两条 API 路径
本地 API 示例依赖 FastAPI、Uvicorn、`openai<1.0`、Pydantic 和 `sse_starlette`,然后运行 `openai_api.py`。
如果你不想维护本地推理服务,README 还单独给出了 DashScope 的托管 API 入口。
类 OpenAI 客户端调用示例
import openai
openai.api_base = "http://localhost:8000/v1"
openai.api_key = "none"
response = openai.ChatCompletion.create(
model="Qwen",
messages=[{"role": "user", "content": "你好"}],
stream=False,
stop=[]
)
print(response.choices[0].message.content)
API 说明
函数调用
上游 README 明确提到本地 API 支持 function calling,但暂时要求 `stream=False`。
DashScope
当你需要托管服务而非本地兼容层时,直接使用 DashScope。
查看链接FastChat OpenAI server
在 vLLM 路径中,FastChat 也能提供类 OpenAI 的 API Server。