遇到的问题
一直出现这种连接错误,到后面解决了,发现是自己传进去的参数不对劲
api_url #不对,正确应该是这个参数名字
api_base="http://localhost:8000/v1"
用vllm搭建一个仿openai接口
python -m vllm.entrypoints.openai.api_server
--model qwen-0.5fuction-call #本地模型路径
--gpu-memory-utilization 0.8 #使用多少显存
--served-model-name qwen #模型名称,后面调用的时候会用
--trust-remote-code
解决步骤二
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="qwen", #上面定义的模型名称
api_base="http://localhost:8000/v1", #默认是这个端口,vllm可以设置
api_key="EMPTY",
is_chat_model=True,
is_function_calling_model=True, timeout=20)
response = llm.complete("Hello World!")
print(response)
可以看到结果可以正常输出