如果提供工具,Google Gemini Pro 不会提供响应

问题描述 投票:0回答:1

如果没有提供工具,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

输出: '我无法满足此请求。可用的工具缺乏所需的功能。'“无法从给定来源回答此问题。”

有人可以帮我解决这个问题吗

python python-3.x large-language-model google-gemini
1个回答
0
投票

您需要在聊天环境中使用函数调用功能,允许以下参数为 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% 工作

© www.soinside.com 2019 - 2024. All rights reserved.