API is valid but got invalid response, I am not sure where I got it wrong.
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Start with src/lagent_utils/lagent_internlm.py around lines 124-125 and run.sh to reproduce the invalid API: run response. Review the GPTAPI configuration, including api_base, model_type, and the agent's PluginParser setup, then compare the request and response handling with the reported execution result. Done means identifying and documenting the source of the invalid API response and confirming a corrected request path.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Python
- Stars
- 2.3k
- Forks
- 249
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from InternLM/lagent
-
OpenAI shuts down gpt-3.5-turbo and gpt-4o-2024-05-13 on 2026-10-23: default model_type values need updatingPossibly taken @qiyuhuating claimed this 53 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
`trust_remote_code=True` is hard-coded in the Hugging Face and vLLM wrappers and cannot be turned offPossibly taken @ningyixi claimed this 4 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 50/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Techiebutler/freeframe#687 ·
Maintainers usually reply within 1 day
-
Parse truncated verbose GC logs up to the first XML errorPossibly taken A pull request linked to this issue is open or already merged. Openbug verbose GC
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
IBM/javacore-analyser#677 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 2 days
-
area/config comp/plugins P1 platform/qqbot tool/file type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
NousResearch/hermes-agent#163932 · 1 comment ·
Maintainers usually reply within 1 day
-
plugins/dsh: todayStr() computes UTC but is documented as local — journal entries written 00:00–08:00 local land in the previous day's filePossibly taken @Beehtrix claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zilliztech/memsearch#907 · 1 comment ·
Maintainers usually reply within 1 day