google / generative-ai-docs

Documentation for Google's Gen AI site - including the Gemini API and Gemma
https://ai.google.dev
Apache License 2.0
1.71k stars 623 forks source link

Gemini Pro Bug "trustees" #243

Closed mobettadanyu closed 10 months ago

mobettadanyu commented 10 months ago

Description of the bug:

When using the word "trustees" in an api call, the model suddenly throws me "500 An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting". At no other point does this happen. The following is the code I am using

# load Google Gemini API key
from dotenv import load_dotenv
load_dotenv()
import google.generativeai as genai
genai.configure(api_key=os.getenv("API_KEY"))
generation_config = {"temperature": 0}
model = genai.GenerativeModel('gemini-pro',generation_config=generation_config,)

def chat_completion(messages):
  if(type(messages)==list):
    prompts=""
    chat=[{'role':'user','parts':[f'You are a helpful assistant created to help a student attending college. Say "Okay" if you understand.\n\nHere is the context:\n']},
          {'role':'model','parts':['Okay']}]
    for message in messages:
      if(message['role']=='user'):
          prompts+=message['text']+'\n'
          chat.append({'role':'user','parts':[message['text']]})
      else:
          chat.append({'role':'model','parts':[message['text']]})
    chat[0]['parts'][0]+=get_documents(prompts,20)
    chat.pop(-1)
    convo = model.start_chat(history=chat)
    convo.send_message(messages[-1]['text'])
    return(convo.last.text)
  else:
    return "Messages should be a list"

Actual vs expected behavior:

Expected: A response from Gemini Pro detailing a model response

Actual: "500 An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting"

Any other information you'd like to share?

No response

mobettadanyu commented 10 months ago

The issue was not with Google's API, apologies.