API is valid but got invalid response, I am not sure where I got it wrong.
还没有人认领这个 Issue。
评估
调研方向
从 src/lagent_utils/lagent_internlm.py 的第 124-125 行附近和 run.sh 开始运行,以复现 invalid API: run 响应。检查 GPTAPI 配置,包括 api_base、model_type 以及 agent 的 PluginParser 设置,然后将请求和响应的处理与报告的执行结果进行比较。完成的标准是确定并记录 invalid API 响应的来源,并确认已修正的请求路径。
由索引模型根据 Issue 内容生成。
描述
API is valid but got invalid response, I am not sure where I got it wrong.
import os
import logging
import warnings as wa
wa.warn_explicit = wa.warn = lambda *_, **__: None
from datetime import datetime
from configparser import ConfigParser
from lagent.agents import AgentForInternLM
from lagent.actions import WebBrowser
from lagent.prompts import PluginParser
from lagent.llms import GPTAPI
from lagent.agents.stream import get_plugin_prompt
from typing import List
from src.utils.debugger.custom_print import enable_custom_print
from src.agent.prompts import (
searcher_context_template_cn,
searcher_input_template_cn,
searcher_system_prompt_cn,
)
enable_custom_print()
config = ConfigParser()
config.read("config/config.ini")
bing_api_key = config.get("BING", "BING_API_KEY")
subscription_key = config.get("SILICON", "SILICON_API_KEY")
date = datetime.now().strftime("The current date is %Y-%m-%d.")
llm = GPTAPI(
model_type="internlm/internlm2_5-7b-chat",
key=subscription_key,
api_base="https://api.siliconflow.cn/v1/chat/completions",
meta_template=[
dict(role="system", api_role="system"),
dict(role="user", api_role="user"),
dict(role="assistant", api_role="assistant"),
dict(role="environment", api_role="system"),
],
top_k=1,
top_p=0.8,
temperature=0,
max_new_tokens=8192,
repetition_penalty=1.02,
stop_words=["<|im_end|>"],
)
plugins = [
WebBrowser(
searcher_type="BingSearch",
topk=6,
api_key=bing_api_key or os.environ.get("BING_API_KEY"),
)
]
# agent = AgentForInternLM(
# llm=llm, # LLM模型配置
# max_turn=4, # 最大对话轮数
# plugins=plugins, # 可用的插件列表
# template=search_template_cn,
# output_format=PluginParser(
# template=(searcher_system_prompt_cn),
# tool_info=get_plugin_prompt(plugins),
# ),
# )
class SearcherAgent(AgentForInternLM):
def __init__(
self,
user_input_template: str = "{question}",
user_context_template: str = None,
**kwargs,
):
self.user_input_template = user_input_template
self.user_context_template = user_context_template
super().__init__(**kwargs)
def forward(
self,
question: str,
topic: str,
history: List[dict] = None,
session_id=0,
**kwargs,
):
message = [self.user_input_template.format(question=question, topic=topic)]
if history and self.user_context_template:
message = [
self.user_context_template.format_map(item) for item in history
] + message
message = "\n".join(message)
return super().forward(message, session_id=session_id, **kwargs)
searcher_config = dict(
llm=llm,
max_turn=4,
plugins=plugins,
template=date,
output_format=PluginParser(
template=(searcher_system_prompt_cn),
tool_info=get_plugin_prompt(plugins),
),
user_input_template=searcher_input_template_cn,
user_context_template=searcher_context_template_cn,
)
# print(f"searcher_config: {searcher_config}")
searcher_agent = SearcherAgent(**searcher_config)
def main():
question = "请介绍一下ChatGPT的发展历程"
topic = "人工智能"
response = searcher_agent.forward(question=question, topic=topic, history=None)
print("搜索结果:")
print(response)
if __name__ == "__main__":
main()
execution result
root@5583da9ef206:~/MAS-APR# bash run.sh
Script started at: 2025-01-07_06-41-42
--------------------------------
/root/MAS-APR/src/lagent_utils/lagent_internlm.py:124 - 搜索结果:
/root/MAS-APR/src/lagent_utils/lagent_internlm.py:125 - content='invalid API: run' sender='ActionExecutor' formatted=None extra_info=None type=None receiver=None stream_state=<AgentStatusCode.END: 0>
--------------------------------
Script ended at: 2025-01-07_06-41-51
Used time: 9 seconds
- 主要语言
- Python
- 星标
- 2.3k
- 派生
- 249
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
InternLM/lagent 的其他 Issue
-
OpenAI shuts down gpt-3.5-turbo and gpt-4o-2024-05-13 on 2026-10-23: default model_type values need updating可能已有人在做 @qiyuhuating 于 53 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
-
`trust_remote_code=True` is hard-coded in the Hugging Face and vLLM wrappers and cannot be turned off可能已有人在做 @ningyixi 于 4 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 50/100
-
难度 5/5 一周以上 新手友好度 30/100
-
难度 5/5 一周以上 新手友好度 30/100
-
难度 5/5 一周以上 新手友好度 25/100
相似的 Issue
-
accepted
难度 2/5 1-3 小时 新手友好度 66/100
future-agi/future-agi#5908 ·
维护者通常 1 天内回复
-
Placeholder export disables HTML image input for picture description可能已有人在做 @cloudiful 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
docling-project/docling-serve#817 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 92/100
Techiebutler/freeframe#687 ·
维护者通常 1 天内回复
-
Parse truncated verbose GC logs up to the first XML error可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug verbose GC
难度 2/5 1-3 小时 新手友好度 74/100
IBM/javacore-analyser#677 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 2 天内回复