Skip to content

Commit ee7306d

Browse files
committed
fix: response parsing bug for gemini
1 parent 1f2b36a commit ee7306d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

app/services/llm.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _generate_response(prompt: str) -> str:
8686

8787
if llm_provider == "gemini":
8888
import google.generativeai as genai
89-
genai.configure(api_key=api_key)
89+
genai.configure(api_key=api_key, transport='rest')
9090

9191
generation_config = {
9292
"temperature": 0.5,
@@ -118,11 +118,15 @@ def _generate_response(prompt: str) -> str:
118118
generation_config=generation_config,
119119
safety_settings=safety_settings)
120120

121-
convo = model.start_chat(history=[])
121+
try:
122+
response = model.generate_content(prompt)
123+
candidates = response.candidates
124+
generated_text = candidates[0].content.parts[0].text
125+
except (AttributeError, IndexError) as e:
126+
print("Gemini Error:", e)
127+
128+
return generated_text
122129

123-
convo.send_message(prompt)
124-
return convo.last.text
125-
126130
if llm_provider == "cloudflare":
127131
import requests
128132
response = requests.post(
@@ -180,9 +184,9 @@ def generate_script(video_subject: str, language: str = "", paragraph_number: in
180184
1. the script is to be returned as a string with the specified number of paragraphs.
181185
2. do not under any circumstance reference this prompt in your response.
182186
3. get straight to the point, don't start with unnecessary things like, "welcome to this video".
183-
4. you must not include any type of markdown or formatting in the script, never use a title.
184-
5. only return the raw content of the script.
185-
6. do not include "voiceover", "narrator" or similar indicators of what should be spoken at the beginning of each paragraph or line.
187+
4. you must not include any type of markdown or formatting in the script, never use a title.
188+
5. only return the raw content of the script.
189+
6. do not include "voiceover", "narrator" or similar indicators of what should be spoken at the beginning of each paragraph or line.
186190
7. you must not mention the prompt, or anything about the script itself. also, never talk about the amount of paragraphs or lines. just write the script.
187191
8. respond in the same language as the video subject.
188192

0 commit comments

Comments
 (0)