Mac运行Multi-GPT报错:AttributeError: module 'lmql' has no attribute 'query'
解决Multi-GPT启动时
AttributeError: module 'lmql' has no attribute 'query'错误 问题说明
在Mac系统中安装Multi-GPT后,执行python -m multigpt命令启动时触发AttributeError: module 'lmql' has no attribute 'query'错误,Python3.9和Python3.11虚拟环境下均出现该问题。
完整报错栈
Traceback (most recent call last): File "/Users/capelle/opt/anaconda3/lib/python3.9/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/Users/capelle/opt/anaconda3/lib/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/Users/capelle/Multi-GPT/multigpt/__main__.py", line 8, in <module> from multigpt.multi_agent_manager import MultiAgentManager File "/Users/capelle/Multi-GPT/multigpt/multi_agent_manager.py", line 21, in <module> from multigpt import lmql_utils File "/Users/capelle/Multi-GPT/multigpt/lmql_utils/__init__.py", line 1, in <module> from multigpt.lmql_utils._queries import generate_experts, generate_trait_profile File "/Users/capelle/Multi-GPT/multigpt/lmql_utils/_queries.py", line 4, in <module> @lmql.query AttributeError: module 'lmql' has no attribute 'query'
涉及的_queries.py代码
import lmql @lmql.query async def generate_trait_profile(name): ''' argmax(max_len=2000) """ Rate {name} on a scale from 0 (extremly low degree of) to 10 (extremly high degree of) on the following five traits: Openness, Agreeableness, Conscientiousness, Emotional Stability and Assertiveness. Follow the format precisely: Openness: [OPENNESS] Agreeableness: [AGREEABLENESS] Conscientiousness: [CONSCIENTIOUSNESS] Emotional Stability: [EMOTIONAL_STABILITY] Assertiveness: [ASSERTIVENESS] Short description of personality traits of {name}: [DESCRIPTION] """ from 'openai/text-davinci-003' where INT(OPENNESS) and INT(AGREEABLENESS) and INT(CONSCIENTIOUSNESS) and INT(EMOTIONAL_STABILITY) and INT(ASSERTIVENESS) ''' @lmql.query async def generate_experts(task, min_experts, max_experts, llm_model): ''' argmax(max_len=2000) """ The task is: {task}. Please determine which historical or renowned experts would be best suited to complete the given task. Include all experts explicitly mentioned in the task. Name between {min_experts} and {max_experts} experts. List three goals for them to help the overall task. Follow the following format precisely: 1. <Name of the person>: <Description of how they are useful> 1a) <Goal a> 1b) <Goal b> 1c) <Goal c> [RESULT] """ from llm_model ''' @lmql.query async def smart_select_agent(message_history, list_of_participants): ''' argmax """Consider the following excerpt of a panel discussion :\n\n{message_history}\n Now consider this list of participants (ID - NAME):\n{list_of_participants}\n Who should talk next? Explain your reasoning. First and foremost, ensure that if the last speaker addresses one of the participants directly, it should be their turn next. Secondly, make sure each participant contributes roughly equal parts to the discussion.\n Reasoning: [REASONING]\n Therefore, the next speaker should be: [INTVALUE] - [NAME] """ from 'openai/text-davinci-003' where INT(INTVALUE) ''' @lmql.query async def classify_emotion(message): ''' argmax """Message:{message}\n Q: In what emotional state is the author of this message and why?\n A:[ANALYSIS]\n Based on this, the overall emotional sentiment of the message can be considered to be[CLASSIFICATION]""" from "openai/text-davinci-003" distribution CLASSIFICATION in [" agreement", " critique", " surprise", " annoyance", " neutral", " amusement", " idea", " sad"] ''' @lmql.query async def create_chat_completion(messages, llm_model): ''' argmax for message in messages: if message['role'] == 'system': "{:system} {message['content']}" elif message['role'] == 'user': "{:user} {message['content']}" elif message['role'] == 'assistant': "{:assistant} {message['content']}" else: assert False, "not a supported role " + str(role) schema = { "thoughts": { "text": str, "reasoning": str, "plan": str, "criticism": str, "speak": str }, "command": { "name": str, "args": { "[STRING_VALUE]" : str } } } stack = [("", schema)] indent = "" dq = '"' while len(stack) > 0: t = stack.pop(0) if type(t) is tuple: k, key_type = t if k != "": "{indent}{dq}{k}{dq}: " if key_type is str: if stack[0] == "DEDENT": '"[STRING_VALUE]\n' else: '"[STRING_VALUE],\n' elif key_type is int: if stack[0] == "DEDENT": "[INT_VALUE]\n" else: "[INT_VALUE],\n" elif type(key_type) is dict: "{{\n" indent += " " if len(stack) == 0 or stack[0] == "DEDENT": stack = [(k, key_type[k]) for k in key_type.keys()] + ["DEDENT", "}\n"] + stack else: stack = [(k, key_type[k]) for k in key_type.keys()] + ["DEDENT", "},\n"] + stack else: assert False, "not a supported type " + str(k) elif t == "DEDENT": indent = indent[:-4] elif type(t) is str: "{indent}{t}" else: assert False, "not a supported type" + str(t) from llm_model where STOPS_AT(STRING_VALUE, '\\"') and STOPS_AT(INT_VALUE, ",") and INT(INT_VALUE) '''
解决方法
1. 安装指定版本的LMQL
查看Multi-GPT项目根目录下的requirements.txt文件,找到LMQL的版本要求,执行对应安装命令:
pip install lmql==<指定版本号>
若没有requirements.txt,可尝试安装旧版LMQL(如0.1.0版本),因新版LMQL已调整API接口,不再支持@lmql.query装饰器。
2. 修改代码适配新版LMQL
若无法安装旧版LMQL,可修改_queries.py中的装饰器用法:
- 将所有
@lmql.query替换为@lmql.query()(带括号形式) - 或根据新版LMQL文档,调整为
@lmql.query(model="模型名称")的显式声明形式,需确保与原代码逻辑一致。
3. 验证启动
修改完成后,重新执行python -m multigpt命令,检查是否仍有报错。
内容的提问来源于stack exchange,提问作者techfan
相关产品推荐
相关产品推荐

