vLLM 推理模型 Responses 接口的多轮推理消息回传
该示例展示如何启动兼容 OpenAI 接口的 vLLM 服务,并通过 Responses API 调用推理模型。首轮响应中的 reasoning 输出可追加回输入消息,再发起第二轮请求,从而在对话中保留推理内容。
## OpenAI 响应客户端[¶](<https://docs.vllm.ai/en/latest/examples/reasoning/openai_responses_client/#openai-responses-client>) 来源 [https://github.com/vllm-project/vllm/blob/main/examples/reasoning/openai_responses_client.py](<https://github.com/vllm-project/vllm/blob/main/examples/reasoning/openai_responses_client.py>). ``` # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """Set up this example by starting a vLLM OpenAI-compatible server. Reasoning models can be used through the Responses API as seen here https://platform.openai.com/docs/api-reference/responses For example: vllm serve Qwen/Qwen3-8B --reasoning-parser qwen3 """ from openai import OpenAI input_messages = [{"role": "user", "content": "What model are you?"}] def main(): base_url = "http://localhost:8000/v1" client = OpenAI(base_url=base_url, api_key="empty") model = "Qwen/Qwen3-8B" # get_first_model(client) response = client.responses.create( model=model, input=input_messages, ) for message in response.output: if message.type == "reasoning": # append reasoning message input_messages.append(message) response_2 = client.responses.create( model=model, input=input_messages, ) print(response_2.output_text) # I am Qwen, a large language model developed by Alibaba Cloud. # I am designed to assist with a wide range of tasks, including # answering questions, creating content, coding, and engaging in # conversations. I can help with various topics and provide # information or support in multiple languages. How can I assist you today? if __name__ == "__main__": main() ``` 11月 30, 2026 (英语).
查看原始来源