LiteLLM中supports_parallel_function_calling返回值与文档不符问题
问题描述
我在Python项目中使用LiteLLM测试不同模型对*并行函数调用(parallel function calling)*的支持情况,编写了最小复现代码:
from litellm import completion from litellm.utils import supports_function_calling, supports_parallel_function_calling models = [ "gpt-5", "gpt-5-mini", "gpt-4-turbo-preview", "gpt-4o", "gpt-3.5-turbo-1106" ] for model in models: print(f"Model: {model}") print(" Supports function calling:", supports_function_calling(model)) print(" Supports parallel function calling:", supports_parallel_function_calling(model)) print()
运行后输出:
Model: gpt-5 Supports function calling: True Supports parallel function calling: False Model: gpt-5-mini Supports function calling: True Supports parallel function calling: False Model: gpt-4-turbo-preview Supports function calling: True Supports parallel function calling: False Model: gpt-4o Supports function calling: True Supports parallel function calling: False Model: gpt-3.5-turbo-1106 Supports function calling: True Supports parallel function calling: False
根据LiteLLM官方文档,以下断言应当成立:
assert litellm.supports_parallel_function_calling(model="gpt-4-turbo-preview") == True
但实际测试中,supports_parallel_function_calling("gpt-4-turbo-preview")始终返回False,与预期不符。当前使用的LiteLLM版本为1.76.0,即使在模型名称中指定提供商(如openai/gpt-4-turbo-preview),问题仍未解决,官方文档提及的gpt-3.5-turbo-1106模型也存在同样问题。
可能的解决方向
升级LiteLLM版本
LiteLLM的模型支持列表可能在后续版本中更新,尝试升级到最新稳定版:pip install --upgrade litellm升级后重新运行测试代码,确认函数返回值是否符合预期。
手动验证模型实际能力
绕过supports_parallel_function_calling工具函数,直接调用模型发起并行函数调用请求,验证模型本身是否支持该功能。示例代码:from litellm import completion tools = [ { "type": "function", "function": { "name": "get_current_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" }, "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]} }, "required": ["location"] } } }, { "type": "function", "function": { "name": "get_news", "description": "Get the latest news for a given topic", "parameters": { "type": "object", "properties": { "topic": { "type": "string", "description": "The news topic, e.g. technology" } }, "required": ["topic"] } } } ] response = completion( model="gpt-4-turbo-preview", messages=[{"role": "user", "content": "告诉我北京的天气和最新的科技新闻"}], tools=tools, tool_choice="auto" ) # 检查是否返回多个工具调用 if response.choices[0].message.tool_calls and len(response.choices[0].message.tool_calls) > 1: print("模型支持并行函数调用") else: print("模型不支持并行函数调用")如果实际调用成功返回多个工具调用,说明是
supports_parallel_function_calling函数的判断逻辑存在问题。检查LiteLLM源码配置
查看LiteLLM源码中的模型支持配置,确认目标模型是否被标记为支持并行函数调用。可以在LiteLLM的model_info或类似配置文件中查找对应模型的属性,若未正确配置,可提交Issue反馈。
内容的提问来源于stack exchange,提问作者EnzoDeg40
相关产品推荐
相关产品推荐

