Skip to content

Commit

Permalink
fix: response parsing bug for gemini
Browse files Browse the repository at this point in the history
  • Loading branch information
elf-mouse committed Apr 12, 2024
1 parent 1f2b36a commit ee7306d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions app/services/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _generate_response(prompt: str) -> str:

if llm_provider == "gemini":
import google.generativeai as genai
genai.configure(api_key=api_key)
genai.configure(api_key=api_key, transport='rest')

generation_config = {
"temperature": 0.5,
Expand Down Expand Up @@ -118,11 +118,15 @@ def _generate_response(prompt: str) -> str:
generation_config=generation_config,
safety_settings=safety_settings)

convo = model.start_chat(history=[])
try:
response = model.generate_content(prompt)
candidates = response.candidates
generated_text = candidates[0].content.parts[0].text
except (AttributeError, IndexError) as e:
print("Gemini Error:", e)

return generated_text

convo.send_message(prompt)
return convo.last.text

if llm_provider == "cloudflare":
import requests
response = requests.post(
Expand Down Expand Up @@ -180,9 +184,9 @@ def generate_script(video_subject: str, language: str = "", paragraph_number: in
1. the script is to be returned as a string with the specified number of paragraphs.
2. do not under any circumstance reference this prompt in your response.
3. get straight to the point, don't start with unnecessary things like, "welcome to this video".
4. you must not include any type of markdown or formatting in the script, never use a title.
5. only return the raw content of the script.
6. do not include "voiceover", "narrator" or similar indicators of what should be spoken at the beginning of each paragraph or line.
4. you must not include any type of markdown or formatting in the script, never use a title.
5. only return the raw content of the script.
6. do not include "voiceover", "narrator" or similar indicators of what should be spoken at the beginning of each paragraph or line.
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.
8. respond in the same language as the video subject.
Expand Down

0 comments on commit ee7306d

Please sign in to comment.