Spaces:
Sleeping
Sleeping
Update app/genai_client.py
Browse files- app/genai_client.py +12 -5
app/genai_client.py
CHANGED
|
@@ -1,9 +1,16 @@
|
|
| 1 |
-
|
| 2 |
from app.config import GOOGLE_API_KEY, GENAI_MODEL
|
| 3 |
|
| 4 |
-
genai.
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
def generate_answer_from_prompt(prompt):
|
| 8 |
-
response = model.generate_content(prompt)
|
| 9 |
return response.text
|
|
|
|
|
|
| 1 |
+
from google import genai
|
| 2 |
from app.config import GOOGLE_API_KEY, GENAI_MODEL
|
| 3 |
|
| 4 |
+
client = genai.Client(api_key=GOOGLE_API_KEY)
|
| 5 |
+
|
| 6 |
+
def generate_answer_from_prompt(prompt: str) -> str:
|
| 7 |
+
response = client.models.generate_content(
|
| 8 |
+
model=GENAI_MODEL, # เช่น "gemini-1.5-flash"
|
| 9 |
+
contents=prompt
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
if not response or not response.text:
|
| 13 |
+
raise RuntimeError("Empty response from Gemini")
|
| 14 |
|
|
|
|
|
|
|
| 15 |
return response.text
|
| 16 |
+
|