如果没有提供工具,Google Gemini Pro 也能正常工作 例如:
import google.generativeai as genai
def multiply(a:float, b:float):
"""returns a * b."""
return a*b
model = genai.GenerativeModel(model_name='gemini-1.0-pro')
chat = model.start_chat()
response = chat.send_message('who is the president of usa')
response.text
输出: “乔·拜登”
但是当我在其中集成工具并查询工具以外的其他内容时,该模型无法正常工作。
import google.generativeai as genai
def multiply(a:float, b:float):
"""returns a * b."""
return a*b
model = genai.GenerativeModel(model_name='gemini-1.0-pro',
tools=[multiply])
chat = model.start_chat(enable_automatic_function_calling=True)
response = chat.send_message('who is the president of usa')
response.text
输出: '我无法满足此请求。可用的工具缺乏所需的功能。' 或 “无法从给定来源回答此问题。”
有人可以帮我解决这个问题吗
您需要在聊天环境中使用函数调用功能,允许以下参数为 true
enable_automatic_function_calling=True
喜欢
model = genai.GenerativeModel( model_name='gemini-pro', tools = [function] )
chat = model.start_chat(enable_automatic_function_calling=True)
response = chat.send_message(content)
这将 100% 工作