[Bug]: when i give agent function,there is the errorline 898, in _request raise self._make_status_error_from_response(err.response) from None openai.NotFoundError: Error code: 404 - {'error': {'message': 'Unrecognized request argument supplied: functions (request id: 20231218185632700815098gdho4iSo)', 'type': 'invalid_request_error', 'param': '', 'code': None}}
Describe the bug
No response
Steps to reproduce
` function_llm_config = { "cache_seed": 42, # change the cache_seed for different trials "temperature": 0, "config_list": config_list, "timeout": 120, "functions": [ { "name": "get_account_id", "description": "retrieves the account id for a user given their name", "parameters": { "type": "object", "properties": { "name": { "type": "string", "description": "The name of the customer that will be used to lookup the account id" } }, "required": ["name"] } }, { "name": "get_last_bill_amount", "description": "Retrieves the last bill amount for a user for a given account id.", "parameters": { "type": "object", "properties": { "account_id": { "type": "string", "description": "The account id fetched from get_account_id that will be used to lookup the last bill for the customer" } }, "required": ["account_id"] } } ] }
nofunction_llm_config = { "cache_seed": 42, # change the cache_seed for different trials "temperature": 0, "config_list": config_list, "timeout": 120,
}
name_to_account_id = { "Alice": "A123", "Bob": "B456", "Charlie": "C789" }
account_id_to_bill = { "A123": 120.50, "B456": 200.75, "C789": 99.99 }
def get_account_id(name): return name_to_account_id.get(name, "Name not found")
def get_last_bill_amount(account_id): return account_id_to_bill.get(account_id, "Account ID not found")
import autogen from autogen import config_list_from_json from autogen.code_utils import execute_code import json
config_list = autogen.config_list_from_json( env_or_file='config.json', filter_dict={ "model": ["gpt-4"] }, )
function_llm_config = { "cache_seed": 42, # change the cache_seed for different trials "temperature": 0, "config_list": config_list, "timeout": 120, "functions": [ { "name": "get_account_id", "description": "retrieves the account id for a user given their name", "parameters": { "type": "object", "properties": { "name": { "type": "string", "description": "The name of the customer that will be used to lookup the account id" } }, "required": ["name"] } }, { "name": "get_last_bill_amount", "description": "Retrieves the last bill amount for a user for a given account id.", "parameters": { "type": "object", "properties": { "account_id": { "type": "string", "description": "The account id fetched from get_account_id that will be used to lookup the last bill for the customer" } }, "required": ["account_id"] } } ] }
nofunction_llm_config = { "cache_seed": 42, # change the cache_seed for different trials "temperature": 0, "config_list": config_list, "timeout": 120,
}
name_to_account_id = { "Alice": "A123", "Bob": "B456", "Charlie": "C789" }
account_id_to_bill = { "A123": 120.50, "B456": 200.75, "C789": 99.99 }
def get_account_id(name): print("--------------------") print(name_to_account_id.get(name, "Name not found")), return name_to_account_id.get(name, "Name not found")
def get_last_bill_amount(account_id): return account_id_to_bill.get(account_id, "Account ID not found")
为我们的代理创建提示
billing_assistant_agent_prompt = ''' 该代理是一个有用的助手,可以检索客户的账户 ID 和上次账单金额。 任何其他客户服务请求都不属于该代理的工作范围。 完成对用户的帮助后,输出 TERMINATE'''
创建代理,并为其配置已定义的函数定义
billing_assistant_agent = autogen.AssistantAgent( name="billing_assistant_agent", system_message=billing_assistant_agent_prompt, llm_config=function_llm_config, )
首先定义我们的用户代理,记住将 human_input_mode 设置为 NEVER,这样它才能
正确执行功能
user_proxy = autogen.UserProxyAgent( name="user_proxy", human_input_mode="NEVER", max_consecutive_auto_reply=10, is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"), )
接下来我们注册我们的函数,这非常简单
我们只需提供一个字典,将我们希望 llm 调用的名称映射为实际函数的引用
好的做法是让 llm 试图调用的名称与实际的预定义函数相同
但我们也可以随心所欲地调用它们、
user_proxy.register_function( function_map={ "get_account_id": get_account_id, "get_last_bill_amount": get_last_bill_amount, } )
user_proxy.initiate_chat(billing_assistant_agent, message="My name is Bob, can you tell me what my last bill was?")`
Expected Behavior
No response
Screenshots and logs
No response
Additional Information
No response
Hi @safa1018 , is your issue resolved with latest version of AutoGen? If not, could you update the issue since it's difficult to read in the current format. Thanks.
appears resolved.