Hello everybody!
I'm working with Gemini Pro. It's great but I've found that for the same prompt, sometimes it returns a response, sometimes it doesn't. Why is that?
This is the function I'm using:
def get_response_from_llm(user_email, name, company, role, storage_client, db, current_date):
try:
doc_ref = db.collection(FIRESTORE_COLLECTION).document(user_email).collection(current_date).document("overview")
#doc_ref = db.collection('boozeco').document(user_email).collection(current_date).document('script')
doc = doc_ref.get()
if doc.exists:
summary = doc.to_dict().get("content")
prompt = PROMPTS["script"].format(summary=summary, name=name, company=company, role=role)
genai.configure(api_key=GENERATIVE_AI_API_KEY)
generation_config = {
"temperature": 0.8,
"top_p": 0.9,
"top_k": 2,
"max_output_tokens": 512,
}
safety_settings = [
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"},
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_MEDIUM_AND_ABOVE"}
]
model = genai.GenerativeModel('gemini-pro', generation_config=generation_config, safety_settings=safety_settings)
# Add a 10 second delay between LLM calls to avoid exceeding quota limits
#time.sleep(10)
responses = model.generate_content(prompt)
for response in responses:
print(f"Analysing response: {response}")
if response.parts:
print(f"response.parts: {response.parts}")
flag = ""
la_respuesta = ""
if response.candidates:
la_respuesta = response.parts[0].text
flag = "response.parts[0].text"
else:
la_respuesta = response.candidates[0].content.parts
flag = "response.candidates[0].content.parts"
print(f"flag: {flag}")
if la_respuesta:
print(f"OK: Response Characters == {len(la_respuesta)}")
#return la_respuesta
else:
print(f"ERROR: There is no la_respuesta")
print(f"ERROR: la_respuesta =={la_respuesta}")
else:
print(f"ERROR: Empty response parts for user ")
print(f"ERROR: response.parts =={response.parts}")
else:
print(f"No overview document found for user and date {current_date}.")
except Exception as e:
print(f"Exception: An error occurred while generating podcast prompt: {e}")
name = "David"
company = "The Booze Co"
role = "VP of Engineering"
user_email = "david.regalado@somedomain.com"
current_date = "20240125"
PROMPTS['script'] = """Produce a brief and enticing podcast script for informing and motivating {name} in his role {role} at {company}.
You are Cloudia, the digital data analyst for {company}.
Write only the narration, without adding any additional instructions, roles or metadata. Don't include any narration that instructs
Cloudia on how to deliver the report or interact with the user.
"""
--
Best regards
David Regalado
Web | Linkedin | Cloudskillsboost