Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError: list index out of range #45

Closed
jybaek opened this issue Jun 18, 2023 · 3 comments
Closed

IndexError: list index out of range #45

jybaek opened this issue Jun 18, 2023 · 3 comments

Comments

@jybaek
Copy link
Contributor

jybaek commented Jun 18, 2023

I am encountering an issue while using the google.generativeai.chat library. Whenever I input the phrase "who are you?" as a message, it consistently triggers an error. This behavior seems unexpected and needs to be addressed.

response = palm.chat(messages=["who are you?"])
# error
  ...
  File "/Users/jybaek/work/xxxx/.venv/lib/python3.8/site-packages/google/generativeai/discuss.py", line 413, in reply
    return _generate_response(request=request, client=self._client)
  File "/Users/jybaek/work/xxxx/.venv/lib/python3.8/site-packages/google/generativeai/discuss.py", line 461, in _generate_response
    return _build_chat_response(request, response, client)
  File "/Users/jybaek/work/xxxx/.venv/lib/python3.8/site-packages/google/generativeai/discuss.py", line 443, in _build_chat_response
    request["messages"].append(response["candidates"][0])
IndexError: list index out of range

Is it a known issue? Please check.

@MarkDaoust
Copy link
Collaborator

I think you're using an older version of the client, Instead of "List index out of range" this now returns None.
That itself is not helpful.

The API is not returning any candidates for this request:

curl -H 'Content-Type: application/json'        \
    -H "x-goog-api-key: ${PALM_API_KEY}"      \
    -d '{"prompt": {"messages": [{"content": "who are you", "author":"0"}]}}'     \
    "https://generativelanguage.googleapis.com/v1beta2/models/chat-bison-001:generateMessage"
{
  "messages": [
    {
      "author": "0",
      "content": "who are you"
    }
  ],
  "filters": [
    {
      "reason": "OTHER"
    }
  ]
}

The owners are aware of the problem.

@jybaek
Copy link
Contributor Author

jybaek commented Jun 22, 2023

I found the cause. I was using Python 3.8. When installing google-generativeai with pip install in Python 3.8, it installs rc1.

Thank you for your help :)

@jybaek jybaek closed this as completed Jun 22, 2023
@MarkDaoust
Copy link
Collaborator

Yeah, I think we've yanked those versions, so you shouldn't see them anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants