Update app.py
Browse files
app.py
CHANGED
@@ -51,20 +51,18 @@ async def chat(request: ChatRequest):
|
|
51 |
return {"response": response.choices[0].message.content}
|
52 |
|
53 |
if request.model_choice == "google":
|
54 |
-
genai.
|
55 |
-
model = genai.GenerativeModel("gemini-2.0-flash")
|
56 |
|
57 |
messages = [
|
58 |
{"role": "system", "parts": [request.system_message]},
|
59 |
{"role": "user", "parts": [request.message]},
|
60 |
]
|
61 |
|
62 |
-
|
63 |
-
|
|
|
64 |
if response and hasattr(response, 'text'):
|
65 |
-
return response.text
|
66 |
-
else:
|
67 |
-
return "No response text received from the model."
|
68 |
|
69 |
except Exception as e:
|
70 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
51 |
return {"response": response.choices[0].message.content}
|
52 |
|
53 |
if request.model_choice == "google":
|
54 |
+
client = genai.Client(api_key=google_api_key)
|
|
|
55 |
|
56 |
messages = [
|
57 |
{"role": "system", "parts": [request.system_message]},
|
58 |
{"role": "user", "parts": [request.message]},
|
59 |
]
|
60 |
|
61 |
+
response = client.models.generate_content(
|
62 |
+
model="gemini-2.0-flash", contents=request.message
|
63 |
+
)
|
64 |
if response and hasattr(response, 'text'):
|
65 |
+
return response.text # Return text if it's present
|
|
|
|
|
66 |
|
67 |
except Exception as e:
|
68 |
raise HTTPException(status_code=500, detail=str(e))
|