Reputation: 1474
I am using google gemini-api.
Using their Python SDK
I am trying to generate multiple possible responses for a single prompt according to the docs and API-reference
Expected result - multiple response for a single prompt
Actual result - single response
# ... more code above
model = genai.GenerativeModel(model_name="gemini-1.5-pro-latest", system_instruction=system_instruction)
response = model.generate_content("What is the meaning of life?")
resps = response.candidates
resps
is a list
which should contain more than 1 response. But there is only 1 response inside it.If any more information is needed please ask in the comments.
Upvotes: 2
Views: 1833
Reputation: 201553
When I saw the official document GenerationConfig of Method: models.generateContent, it says as follows.
candidateCount: integer Optional. Number of generated responses to return. Currently, this value can only be set to 1. If unset, this will default to 1.
It seems that in the current stage, candidateCount
is only 1. This is the same with "v1". Ref
But, when I saw google.ai.generativelanguage.GenerationConfig of the official document, it says as follows.
candidate_count: int Optional. Number of generated responses to return. This value must be between [1, 8], inclusive. If unset, this will default to 1.
From this, it seems that it is possible to try to change the value of candidate_count
by the script. From this document, when your script is modified, it becomes as follows.
model = genai.GenerativeModel(
model_name="gemini-1.5-pro-latest",
system_instruction=system_instruction,
generation_config=glm.GenerationConfig(candidate_count=2),
)
response = model.generate_content("What is the meaning of life?")
resps = response.candidates
import google.ai.generativelanguage as glm
.candidate_count=2
, an error like Only one candidate can be specified
occurred. I guess that this value might be able to be changed in the future update. When a value of more than 1 got to be able to be used, please test the above-modified script.Upvotes: 1