GPTAPI类型模型,fastapi返回消息报错:缺少必要字段“input”

Open
#266 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
fastapi, javascript, python
Domain
ai, api, backend

Research direction

Start with models.py and the GPTAPI request path used by the FastAPI service, then reproduce the issue with the VLLM_BASE_URL, VLLM_API_KEY, and VLLM_MODEL_NAME settings from the report. Compare the generated request with the FastAPI validation error and the vLLM chat-completions endpoint. Done means a frontend search completes without the reported 400 response.

Written by the indexing model from the issue text.

Description

症状描述

在frontend中正常输入搜索关键词并触发搜索后,卡住不动。fastapi报错:

{"object":"error","message":"[{'type': 'missing', 'loc': ('body', 'messages'), 'msg': 'Field required', 'input': {'model': 'qwen2-vl-7b-instruct', 'input': {'messages': [{'role': 'system', 'content': 'The current date is 2024-12-04.'}, {'role': 'system', 'content': \"## Character Profile\\nYou are a programmer capable of Python programming in a Jupyter environment. You can utilize the provided API to construct a Web Search Graph, ultimately generating and executing code.\\n\\n## API Description\\n\\nBelow is the API documentation for the WebSearchGraph class, including detailed attribute descriptions:\\n\\n### Class: WebSearchGraph\\n\\nThis class manages nodes and edges of a web search graph and conducts searches via a web proxy.\\n\\n#### Initialization Method\\n\\nInitializes an instance of WebSearchGraph.\\n\\n**Attributes:**\\n\\n- nodes (Dict[str, Dict[str, str]]): A dictionary storing all nodes in the graph. Each node is indexed by its name and contains content, type, and other related information.\\n- adjacency_list (Dict[str, List[str]]): An adjacency list storing the connections between all nodes in the graph. Each node is indexed by its name and contains a list of adjacent node names.\\n\\n#### Method: add_root_node\\n\\nAdds the initial question as the root node.\\n**Parameters:**\\n\\n- node_content (str): The user's question.\\n- node_name (str, optional): The node name, default is 'root'.\\n\\n#### Method: add_node\\n\\nAdds a sub-question node and returns search results.\\n**Parameters:**\\n\\n- node_name (str): The node name.\\n- node_content (str): The sub-question content.\\n\\n**Returns:**\\n\\n- str: Returns the search results.\\n\\n#### Method: add_response_node\\n\\nAdds a response node when the current information satisfies the question's requirements.\\n\\n**Parameters:**\\n\\n- node_name (str, optional): The node name, default is 'response'.\\n\\n#### Method: add_edge\\n\\nAdds an edge.\\n\\n**Parameters:**\\n\\n- start_node (str): The starting node name.\\n- end_node (str): The ending node name.\\n\\n#### Method: reset\\n\\nResets nodes and edges.\\n\\n#### Method: node\\n\\nGet node information.\\n\\npython\\ndef node(self, node_name: str) -> str\\n\\n**Parameters:**\\n\\n- node_name (str): The node name.\\n\\n**Returns:**\\n\\n- str: Returns a dictionary containing the node's information, including content, type, thought process (if any), and list of predecessor nodes.\\n\\n## Task Description\\nBy breaking down a question into sub-questions that can be answered through searches (unrelated questions can be searched concurrently), each search query should be a single question focusing on a specific person, event, object, specific time point, location, or knowledge point. It should not be a compound question (e.g., a time period). Step by step, build the search graph to finally answer the question.\\n\\n## Considerations\\n\\n1. Each search node's content must be a single question; do not include multiple questions (e.g., do not ask multiple knowledge points or compare and filter multiple things simultaneously, like asking for differences between A, B, and C, or price ranges -> query each separately).\\n2. Do not fabricate search results; wait for the code to return results.\\n3. Do not repeat the same question; continue asking based on existing questions.\\n4. When adding a response node, add it separately; do not add a response node and other nodes simultaneously.\\n5. In a single output, do not include multiple code blocks; only one code block per output.\\n6. Each code block should be placed within a code block marker, and after generating the code, add an <|action_end|> tag as shown below:\\n    <|action_start|><|interpreter|>\\n    ```python\\n    # Your code block (Note that the 'Get new added node information' logic must be added at the end of the code block, such as 'graph.node('...')')\\n    ```<|action_end|>\\n7. The final response should add a response node with node_name 'response', and no other nodes should be added.\\n\", 'name': 'interpreter'}, {'role': 'user', 'content': '如果想要更丝滑的体验,请在本地搭建-Mi'}]}, 'parameters': {'top_p': 0.9, 'temperature': 0.2, 'stream': True, 'max_tokens': 4096, 'stop': ['<|im_end|>'], 'repetition_penalty': 1.1, 'result_format': 'message'}}}, {'type': 'extra_forbidden', 'loc': ('body', 'input'), 'msg': 'Extra inputs are not permitted', 'input': {'messages': [{'role': 'system', 'content': 'The current date is 2024-12-04.'}, {'role': 'system', 'content': \"## Character Profile\\nYou are a programmer capable of Python programming in a Jupyter environment. You can utilize the provided API to construct a Web Search Graph, ultimately generating and executing code.\\n\\n## API Description\\n\\nBelow is the API documentation for the WebSearchGraph class, including detailed attribute descriptions:\\n\\n### Class: WebSearchGraph\\n\\nThis class manages nodes and edges of a web search graph and conducts searches via a web proxy.\\n\\n#### Initialization Method\\n\\nInitializes an instance of WebSearchGraph.\\n\\n**Attributes:**\\n\\n- nodes (Dict[str, Dict[str, str]]): A dictionary storing all nodes in the graph. Each node is indexed by its name and contains content, type, and other related information.\\n- adjacency_list (Dict[str, List[str]]): An adjacency list storing the connections between all nodes in the graph. Each node is indexed by its name and contains a list of adjacent node names.\\n\\n#### Method: add_root_node\\n\\nAdds the initial question as the root node.\\n**Parameters:**\\n\\n- node_content (str): The user's question.\\n- node_name (str, optional): The node name, default is 'root'.\\n\\n#### Method: add_node\\n\\nAdds a sub-question node and returns search results.\\n**Parameters:**\\n\\n- node_name (str): The node name.\\n- node_content (str): The sub-question content.\\n\\n**Returns:**\\n\\n- str: Returns the search results.\\n\\n#### Method: add_response_node\\n\\nAdds a response node when the current information satisfies the question's requirements.\\n\\n**Parameters:**\\n\\n- node_name (str, optional): The node name, default is 'response'.\\n\\n#### Method: add_edge\\n\\nAdds an edge.\\n\\n**Parameters:**\\n\\n- start_node (str): The starting node name.\\n- end_node (str): The ending node name.\\n\\n#### Method: reset\\n\\nResets nodes and edges.\\n\\n#### Method: node\\n\\nGet node information.\\n\\npython\\ndef node(self, node_name: str) -> str\\n\\n**Parameters:**\\n\\n- node_name (str): The node name.\\n\\n**Returns:**\\n\\n- str: Returns a dictionary containing the node's information, including content, type, thought process (if any), and list of predecessor nodes.\\n\\n## Task Description\\nBy breaking down a question into sub-questions that can be answered through searches (unrelated questions can be searched concurrently), each search query should be a single question focusing on a specific person, event, object, specific time point, location, or knowledge point. It should not be a compound question (e.g., a time period). Step by step, build the search graph to finally answer the question.\\n\\n## Considerations\\n\\n1. Each search node's content must be a single question; do not include multiple questions (e.g., do not ask multiple knowledge points or compare and filter multiple things simultaneously, like asking for differences between A, B, and C, or price ranges -> query each separately).\\n2. Do not fabricate search results; wait for the code to return results.\\n3. Do not repeat the same question; continue asking based on existing questions.\\n4. When adding a response node, add it separately; do not add a response node and other nodes simultaneously.\\n5. In a single output, do not include multiple code blocks; only one code block per output.\\n6. Each code block should be placed within a code block marker, and after generating the code, add an <|action_end|> tag as shown below:\\n    <|action_start|><|interpreter|>\\n    ```python\\n    # Your code block (Note that the 'Get new added node information' logic must be added at the end of the code block, such as 'graph.node('...')')\\n    ```<|action_end|>\\n7. The final response should add a response node with node_name 'response', and no other nodes should be added.\\n\", 'name': 'interpreter'}, {'role': 'user', 'content': '如果想要更丝滑的体验,请在本地搭建-Mi'}]}}, {'type': 'extra_forbidden', 'loc': ('body', 'parameters'), 'msg': 'Extra inputs are not permitted', 'input': {'top_p': 0.9, 'temperature': 0.2, 'stream': True, 'max_tokens': 4096, 'stop': ['<|im_end|>'], 'repetition_penalty': 1.1, 'result_format': 'message'}}]","type":"BadRequestError","param":null,"code":400}

可以从信息中发现request字典多了一层外面的模型名,应该是里面那层input。

vLLM后端报错:

"POST /v1/chat/completions HTTP/1.1" 400 BAD REQUEST

如何复现

(models.py要加一行load_dotenv,否则还加载不出来api和key)
设置以下环境变量:

VLLM_BASE_URL="http://192.168.1.9:8008/v1"
VLLM_API_KEY=[MY_API_KEY]
VLLM_MODEL_NAME="qwen2-vl-7b-instruct"

使用以下模型设置:

vllm = dict(
    type=GPTAPI,
    model_type=os.environ.get("VLLM_MODEL_NAME"),
    key=os.environ.get("VLLM_API_KEY"),
    api_base= f"{os.environ.get("VLLM_BASE_URL")}/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_p=0.9,
    # top_k=1,
    temperature=0.2,
    max_new_tokens=4096,
    repetition_penalty=1.1,
    stop_words=["<|im_end|>"],
)

启动fastapi

python -m mindsearch.app --lang en --model_format vllm --search_engine GoogleSearch --asy

在前端正常输入搜索就会报错。

但是把模型名字改成gpt-smart,就能输出一部分内容了,虽然也是gibberish,但是至少输出了。(vllm显示名,实际模型和之前一样)
image
真是令人费解!

是否影响使用

由于这个问题而无法使用。

Dominant language
JavaScript
Stars
7k
Forks
684
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from InternLM/MindSearch

All issues in InternLM/MindSearch

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.