我正在使用谷歌gemini-api。
使用他们的 Python SDK
我正在尝试根据 docs 和 API-reference
为单个提示生成多个可能的响应预期结果 - 单个提示的多个响应
实际结果 - 单一响应
# ... 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
是 list
,应包含超过 1 个响应。但里面只有 1 个响应。如果需要更多信息,请在评论中询问。
当我看到Method: models.generateContent的官方文档GenerationConfig时,是这样说的。
candidateCount:整数 选修的。生成的要返回的响应数。 目前,该值只能设置为 1。如果未设置,则默认为 1。
看来在现阶段,
candidateCount
只有1。这和“v1”是一样的。 参考
但是,当我看到官方文档的google.ai.generativelanguage.GenerationConfig时,是这样写的。
candidate_count:int 选修的。生成的要返回的响应数。 该值必须介于 [1, 8] 之间(含)。如果未设置,则默认为 1。
由此看来,可以尝试通过脚本来改变
candidate_count
的值。从这个文档来看,当你的脚本修改后,就变成了如下。
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
测试上面的脚本时,出现了类似Only one candidate can be specified
的错误。我想这个值可能会在未来的更新中改变。当大于1的值可以使用时,请测试上面修改的脚本。