Skip to content

Commit

Permalink
add: validate endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Jan 3, 2025
1 parent 59f2ab6 commit b1d1b1f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
8 changes: 6 additions & 2 deletions gemini-vertex-model-provider/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def configure():
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = creds_file

def cleanup():
os.remove(os.getenv("GOOGLE_APPLICATION_CREDENTIALS", ""))
try:
os.remove(os.getenv("GOOGLE_APPLICATION_CREDENTIALS", ""))
except FileNotFoundError:
pass

@asynccontextmanager
async def lifespan(a: FastAPI):
Expand Down Expand Up @@ -112,9 +115,10 @@ async def get_root():

@app.get("/v1/models")
def list_models() -> JSONResponse:
global startup_err
if startup_err:
return JSONResponse(
content={"error": startup_err}, status_code=500
content={"error": str(startup_err)}, status_code=500
)
content = {
"data": [
Expand Down
3 changes: 1 addition & 2 deletions gemini-vertex-model-provider/tool.gpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ Credential: ../model-provider-credential as gemini-vertex-model-provider
/admin/assets/gemini_icon.svg

---
Name: Validate Credentials
Name: validate
Description: Validate the credentials for the Google Gemini Vertex AI Model Provider
Metadata: envVars: OBOT_GEMINI_VERTEX_MODEL_PROVIDER_GOOGLE_CREDENTIALS_JSON
Metadata: optionalEnvVars: OBOT_GEMINI_VERTEX_MODEL_PROVIDER_PROJECT_ID
Credential: ../model-provider-credential as gemini-vertex-model-provider

#!/usr/bin/env python3 ${GPTSCRIPT_TOOL_DIR}/validate.py
6 changes: 3 additions & 3 deletions gemini-vertex-model-provider/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def validate_credentials():
log("Credentials are valid")
except Exception as e:
print(json.dumps({"error": str(e)}))
exit(1)
exit(0)
finally:
cleanup()

Expand All @@ -22,10 +22,10 @@ def test_model():
_ = GenerativeModel("gemini-1.5-pro")
except GoogleAuthError as e:
print(json.dumps({"error": f"Invalid Google Credentials: {str(e)}"}))
exit(1)
exit(0)
except Exception as e:
print(json.dumps({"error": f"Unknown Error: {str(e)}"}))
exit(1)
exit(0)

if __name__ == "__main__":
validate_credentials()

0 comments on commit b1d1b1f

Please sign in to comment.