Spaces:
Paused
Paused
bug fix
Browse files- app/main.py +9 -19
app/main.py
CHANGED
|
@@ -717,25 +717,15 @@ async def chat_completions(request: OpenAIRequest, api_key: str = Depends(get_ap
|
|
| 717 |
# Create generation config
|
| 718 |
generation_config = create_generation_config(request)
|
| 719 |
|
| 720 |
-
#
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
# Initialize Vertex AI with the rotated credentials
|
| 730 |
-
try:
|
| 731 |
-
# Re-initialize client for this request - credentials might have rotated
|
| 732 |
-
client = genai.Client(vertexai=True, credentials=credentials, project=project_id, location="us-central1")
|
| 733 |
-
print(f"Using credentials for project: {project_id} for this request")
|
| 734 |
-
except Exception as auth_error:
|
| 735 |
-
error_response = create_openai_error_response(
|
| 736 |
-
500, f"Failed to initialize authentication: {str(auth_error)}", "server_error"
|
| 737 |
-
)
|
| 738 |
-
return JSONResponse(status_code=500, content=error_response)
|
| 739 |
|
| 740 |
# Initialize Gemini model
|
| 741 |
search_tool = types.Tool(google_search=types.GoogleSearch())
|
|
|
|
| 717 |
# Create generation config
|
| 718 |
generation_config = create_generation_config(request)
|
| 719 |
|
| 720 |
+
# Use the globally initialized client (from startup)
|
| 721 |
+
global client
|
| 722 |
+
if client is None:
|
| 723 |
+
# This should ideally not happen if startup was successful
|
| 724 |
+
error_response = create_openai_error_response(
|
| 725 |
+
500, "Vertex AI client not initialized", "server_error"
|
| 726 |
+
)
|
| 727 |
+
return JSONResponse(status_code=500, content=error_response)
|
| 728 |
+
print(f"Using globally initialized client for project: {client.project}") # Assuming client has project attribute
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 729 |
|
| 730 |
# Initialize Gemini model
|
| 731 |
search_tool = types.Tool(google_search=types.GoogleSearch())
|