You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用本地Llama 2(LM Studio)运行AutoGen遇api_type参数错误求助

问题:AutoGen对接LM Studio本地Llama 2时出现TypeError错误

我用LM Studio部署了本地Llama 2模型,运行AutoGen代码时出现错误,已确认服务器端口正确。运行代码如下:

from autogen import AssistantAgent, UserProxyAgent

config_list = [
    {
        "api_type": "open_ai",
        "api_base": "http://localhost:1234/v1",
        "api_key": "NULL"
    }
]

llm_config = {'config_list': config_list}

assistant = AssistantAgent(
    name="assistant",
    llm_config = llm_config
)

user_proxy = UserProxyAgent(
    name="user_proxy",
    human_input_mode="NEVER",
    max_consecutive_auto_reply=100,
)

task = """write a python method to output numbers 1 to 100"""

user_proxy.initiate_chat(
    assistant,
    message=task
)

执行python app.py后返回报错:

--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "app.py", line 26, in <module>
    user_proxy.initiate_chat(
  File "C:\Users\Rohun\Development\AutoGen\env\lib\site-packages\autogen\agentchat\conversable_agent.py", line 550, in initiate_chat
    self.send(self.generate_init_message(**context), recipient, silent=silent)
  File "C:\Users\Rohun\Development\AutoGen\env\lib\site-packages\autogen\agentchat\conversable_agent.py", line 348, in send  
    recipient.receive(message, self, request_reply, silent)
  File "C:\Users\Rohun\Development\AutoGen\env\lib\site-packages\autogen\agentchat\conversable_agent.py", line 481, in receive
    reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender)
  File "C:\Users\Rohun\Development\AutoGen\env\lib\site-packages\autogen\agentchat\conversable_agent.py", line 906, in generate_reply
    final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"])
  File "C:\Users\Rohun\Development\AutoGen\env\lib\site-packages\autogen\agentchat\conversable_agent.py", line 625, in generate_oai_reply
    response = client.create(
  File "C:\Users\Rohun\Development\AutoGen\env\lib\site-packages\autogen\oai\client.py", line 247, in create
    response = self._completions_create(client, params)
  File "C:\Users\Rohun\Development\AutoGen\env\lib\site-packages\autogen\oai\client.py", line 327, in _completions_create    
    response = completions.create(**params)
  File "C:\Users\Rohun\Development\AutoGen\env\lib\site-packages\openai\_utils\_utils.py", line 299, in wrapper
    return func(*args, **kwargs)
TypeError: create() got an unexpected keyword argument 'api_type'

查看AutoGen官方GitHub文档多次使用api_type配置项,但不清楚错误原因,求解决方法。


错误原因

错误源于使用的openai-python库版本过高(v1.x及以上),新版openai库的create()方法已移除api_type参数,而AutoGen旧配置格式仍在传递该参数,导致参数不兼容。

解决方法

方案1:调整配置格式(适配新版openai库)

LM Studio完全兼容OpenAI的API格式,无需指定api_type,直接移除该参数即可。修改后的配置代码:

config_list = [
    {
        "api_base": "http://localhost:1234/v1",
        "api_key": "NULL"
    }
]

方案2:降级openai库版本

若需保留原有配置格式,可将openai库降级到支持api_type参数的v0.28.x版本:

pip install openai==0.28.1

验证

修改后重新运行python app.py,若能正常生成输出1到100的Python方法,说明问题已解决。

内容的提问来源于stack exchange,提问作者AI_Demi_God

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 00:53:26