使用Microsoft Autogen遇Completions.create()参数错误,如何解决?
问题解决方案
1. 解决Completions.create() got an unexpected keyword argument 'request_timeout'错误
错误原因是request_timeout参数被放在了llm_config顶层,而Autogen要求该参数属于单个模型的配置项,需将其移至config_list的字典中。
修改后的核心代码片段:
config_list = [ { 'model': 'gpt-4', 'api_key': '你的真实API密钥', 'request_timeout': 600 # 将request_timeout移至此处 } ] llm_config={ "seed": 42, "config_list": config_list, "temperature": 0 # 移除顶层的request_timeout参数 }
2. 解决API密钥格式不符合OpenAI规范的警告
警告源于代码中使用了占位符'API_KEY',需替换为真实有效的OpenAI API密钥:
- 密钥必须以
sk-开头,格式为sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - 确保密钥未过期、权限正常,可在OpenAI平台的API密钥管理页面获取
完整修改后的代码:
import autogen from autogen import AssistantAgent, UserProxyAgent config_list = [ { 'model': 'gpt-4', 'api_key': 'sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', # 替换为你的真实API密钥 'request_timeout': 600 } ] llm_config={ "seed": 42, "config_list": config_list, "temperature": 0 } assistant = autogen.AssistantAgent( name="assistant", llm_config=llm_config, system_message="Chief technical officer of a tech company" ) user_proxy = autogen.UserProxyAgent( name="user_proxy", human_input_mode="ALWAYS", max_consecutive_auto_reply=10, is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), code_execution_config={"work_dir": "web"}, llm_config=llm_config, system_message="""Reply TERMINATE if the task has been solved at full satisfaction. Otherwise, reply CONTINUE, or the reason why the task is not solved yet.""" ) task = """ Write python code to output numbers 1 to 100 """ user_proxy.initiate_chat( assistant, message=task )
内容的提问来源于stack exchange,提问作者esllmllama
相关产品推荐
相关产品推荐

