This commit is contained in:
Slipstream 2025-04-29 17:37:02 -06:00
parent a4faf8d256
commit acfa2acd71
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -9,6 +9,8 @@ import datetime
from typing import TYPE_CHECKING, Optional, List, Dict, Any, Union, AsyncIterable, Tuple # Import Tuple
import jsonschema # For manual JSON validation
from .tools import get_conversation_summary
import certifi
import httpx
# Google Generative AI Imports (using Vertex AI backend)
# try:
@ -261,13 +263,21 @@ def _get_response_text(response: Optional[types.GenerateContentResponse]) -> Opt
# --- Initialize Google Generative AI Client for Vertex AI ---
# No explicit genai.configure(api_key=...) needed when using Vertex AI backend
try:
# Initialize the client specifically for Vertex AI
# This assumes credentials (like ADC) are set up correctly in the environment
# Step 1: Patch certs into httpx
custom_httpx_client = httpx.AsyncClient(
transport=httpx.AsyncHTTPTransport(verify=certifi.where())
)
# Step 2: Initialize GenAI Client
genai_client = genai.Client(
vertexai=True,
project=PROJECT_ID,
location=LOCATION,
)
# Step 3: Inject the fixed httpx client
genai_client._api_client._httpx_client = custom_httpx_client
print(f"Google GenAI Client initialized for Vertex AI project '{PROJECT_ID}' in location '{LOCATION}'.")
except NameError:
genai_client = None