Logprobs does not work with Python
Description of the bug:
Unable to get response_logprobs in response body - unrecognized parameter
Actual vs expected behavior:
According to this cookbook, the following should work -
import google.generativeai as genai
model = genai.GenerativeModel(model_name)
test_prompt="Why don't people have tails?"
response = model.generate_content(
test_prompt,
generation_config=dict(response_logprobs=True, logprobs=5)
)
But I receive the following error -
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[79], line 1
----> 1 model = genai.GenerativeModel(model_name)
2 test_prompt="Why don't people have tails?"
4 response = model.generate_content(
5 test_prompt,
6 generation_config=dict(response_logprobs=True, logprobs=5)
7 )
AttributeError: module 'google.generativeai' has no attribute 'GenerativeModel'
Which tells me that the API has changed.
Additionally, my company's internal offering receives the following error if I replicate the generation_config line -
vertexai.init(project="dev-poc-xxxyyy", location="x-y")
model = GenerativeModel(
"gemini-1.5-flash-001",
)
responses = model.generate_content(
[prompt],
generation_config=dict(response_logprobs=True, logprobs=5),
safety_settings=safety_settings,
stream=False
)
I get the following error -
ValueError: Unknown field for GenerationConfig: response_logprobs
Although it works if I replace generation_config with other parameters such as -
generation_config = {
"candidate_count": 1,
"max_output_tokens": 1024,
"temperature": 0.2,
"top_p": 0.8
}
Any other information you'd like to share?
No response
AttributeError: module 'google.generativeai' has no attribute 'GenerativeModel'
This usually indicates you're using a very old version of the SDK. pip freeze |grep google should show us what you have installed and pip -U 'google-generativeai>=0.8.3' should update it.
vertexai.init(project="dev-poc-xxxyyy", location="x-y")
This repository does not cover Vertex examples. Maybe head over to https://github.com/GoogleCloudPlatform/vertex-ai-samples
Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.
This issue was closed because it has been inactive for 27 days. Please post a new issue if you need further assistance. Thanks!