Update main.py
Browse files
main.py
CHANGED
|
@@ -46,11 +46,11 @@ try:
|
|
| 46 |
gemini_api_key = os.environ.get("Gemini")
|
| 47 |
if not gemini_api_key: raise ValueError("The 'Gemini' environment variable for the API key is not set.")
|
| 48 |
|
| 49 |
-
# --- CORRECTED SDK PATTERN
|
| 50 |
-
# Instantiate the client object.
|
| 51 |
client = genai.Client(api_key=gemini_api_key)
|
| 52 |
-
# Define the model name
|
| 53 |
-
MODEL_NAME = '
|
| 54 |
# --- END OF CORRECTION ---
|
| 55 |
|
| 56 |
logger.info(f"Google GenAI Client initialized successfully for model {MODEL_NAME}.")
|
|
@@ -115,8 +115,8 @@ def detect_use_case_with_gemini(text):
|
|
| 115 |
Text: "{text[:4000]}"
|
| 116 |
"""
|
| 117 |
try:
|
| 118 |
-
# CORRECTED: Use the client
|
| 119 |
-
response = client.generate_content(model=MODEL_NAME, contents=prompt)
|
| 120 |
category = response.text.strip().replace("'", "").replace('"', '')
|
| 121 |
valid_categories = ['Job Interview', 'Investor Pitch', 'Academic Presentation']
|
| 122 |
if category in valid_categories:
|
|
@@ -169,8 +169,8 @@ def analyze_transcript_with_gemini(uid, project_id, transcript, duration_seconds
|
|
| 169 |
}}
|
| 170 |
Transcript to analyze: "{transcript}"
|
| 171 |
"""
|
| 172 |
-
# CORRECTED: Use the client
|
| 173 |
-
response = client.generate_content(model=MODEL_NAME, contents=prompt)
|
| 174 |
feedback_json_text = response.text.strip().lstrip("```json").rstrip("```")
|
| 175 |
feedback_data = json.loads(feedback_json_text)
|
| 176 |
session_id = str(uuid.uuid4())
|
|
@@ -223,8 +223,8 @@ def generate_agent_briefing(uid, project_id):
|
|
| 223 |
- "The user struggles with concise communication. Ask multi-part questions to test their ability to stay on track."
|
| 224 |
Your directive for the agent:
|
| 225 |
"""
|
| 226 |
-
# CORRECTED: Use the client
|
| 227 |
-
response = client.generate_content(model=MODEL_NAME, contents=summary_prompt)
|
| 228 |
dynamic_directive = response.text.strip()
|
| 229 |
logger.info(f"Generated dynamic directive for agent: {dynamic_directive}")
|
| 230 |
return f"{base_briefing} {dynamic_directive}"
|
|
|
|
| 46 |
gemini_api_key = os.environ.get("Gemini")
|
| 47 |
if not gemini_api_key: raise ValueError("The 'Gemini' environment variable for the API key is not set.")
|
| 48 |
|
| 49 |
+
# --- FINAL CORRECTED SDK PATTERN ---
|
| 50 |
+
# 1. Instantiate the client object.
|
| 51 |
client = genai.Client(api_key=gemini_api_key)
|
| 52 |
+
# 2. Define the model name as a simple string.
|
| 53 |
+
MODEL_NAME = 'gemini-2.0-flash'
|
| 54 |
# --- END OF CORRECTION ---
|
| 55 |
|
| 56 |
logger.info(f"Google GenAI Client initialized successfully for model {MODEL_NAME}.")
|
|
|
|
| 115 |
Text: "{text[:4000]}"
|
| 116 |
"""
|
| 117 |
try:
|
| 118 |
+
# CORRECTED: Use the client.models.generate_content method.
|
| 119 |
+
response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
|
| 120 |
category = response.text.strip().replace("'", "").replace('"', '')
|
| 121 |
valid_categories = ['Job Interview', 'Investor Pitch', 'Academic Presentation']
|
| 122 |
if category in valid_categories:
|
|
|
|
| 169 |
}}
|
| 170 |
Transcript to analyze: "{transcript}"
|
| 171 |
"""
|
| 172 |
+
# CORRECTED: Use the client.models.generate_content method.
|
| 173 |
+
response = client.models.generate_content(model=MODEL_NAME, contents=prompt)
|
| 174 |
feedback_json_text = response.text.strip().lstrip("```json").rstrip("```")
|
| 175 |
feedback_data = json.loads(feedback_json_text)
|
| 176 |
session_id = str(uuid.uuid4())
|
|
|
|
| 223 |
- "The user struggles with concise communication. Ask multi-part questions to test their ability to stay on track."
|
| 224 |
Your directive for the agent:
|
| 225 |
"""
|
| 226 |
+
# CORRECTED: Use the client.models.generate_content method.
|
| 227 |
+
response = client.models.generate_content(model=MODEL_NAME, contents=summary_prompt)
|
| 228 |
dynamic_directive = response.text.strip()
|
| 229 |
logger.info(f"Generated dynamic directive for agent: {dynamic_directive}")
|
| 230 |
return f"{base_briefing} {dynamic_directive}"
|