fix the async mess
This commit is contained in:
17
lib.py
17
lib.py
@@ -12,13 +12,15 @@ from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
# Vertex AI RAG Corpus resource path
|
||||
CORPUS: str = "projects/520464122471/locations/europe-west3/ragCorpora/2305843009213693952"
|
||||
CORPUS: str = (
|
||||
"projects/520464122471/locations/europe-west3/ragCorpora/2305843009213693952"
|
||||
)
|
||||
|
||||
# Gemini model name
|
||||
GEMINI_MODEL: str = "gemini-3-pro-preview"
|
||||
|
||||
|
||||
def generate(prompt: str):
|
||||
async def generate(prompt: str):
|
||||
"""Generate content using Gemini model with RAG retrieval.
|
||||
|
||||
This function creates a streaming response from the Gemini model,
|
||||
@@ -42,8 +44,7 @@ def generate(prompt: str):
|
||||
types.Tool(
|
||||
retrieval=types.Retrieval(
|
||||
vertex_rag_store=types.VertexRagStore(
|
||||
rag_resources=[
|
||||
types.VertexRagStoreRagResource(rag_corpus=CORPUS)],
|
||||
rag_resources=[types.VertexRagStoreRagResource(rag_corpus=CORPUS)],
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -54,16 +55,14 @@ def generate(prompt: str):
|
||||
top_p=0.95,
|
||||
max_output_tokens=65535,
|
||||
safety_settings=[
|
||||
types.SafetySetting(
|
||||
category="HARM_CATEGORY_HATE_SPEECH", threshold="OFF"),
|
||||
types.SafetySetting(category="HARM_CATEGORY_HATE_SPEECH", threshold="OFF"),
|
||||
types.SafetySetting(
|
||||
category="HARM_CATEGORY_DANGEROUS_CONTENT", threshold="OFF"
|
||||
),
|
||||
types.SafetySetting(
|
||||
category="HARM_CATEGORY_SEXUALLY_EXPLICIT", threshold="OFF"
|
||||
),
|
||||
types.SafetySetting(
|
||||
category="HARM_CATEGORY_HARASSMENT", threshold="OFF"),
|
||||
types.SafetySetting(category="HARM_CATEGORY_HARASSMENT", threshold="OFF"),
|
||||
],
|
||||
tools=tools,
|
||||
thinking_config=types.ThinkingConfig(
|
||||
@@ -76,6 +75,8 @@ def generate(prompt: str):
|
||||
contents=contents,
|
||||
config=generate_content_config,
|
||||
):
|
||||
# DEBUG: Log chunk type to confirm generator behavior
|
||||
print(f"[DEBUG] Chunk type: {type(chunk)}")
|
||||
if (
|
||||
not chunk.candidates
|
||||
or not chunk.candidates[0].content
|
||||
|
||||
Reference in New Issue
Block a user