4cfad5ae0f
- 全新ui - 全面优化websocket逻辑,提高数字人和ui连接的稳定性及资源开销 - 全面优化唤醒逻辑,提供稳定的普通唤醒模式和前置词唤醒模式 - 优化拾音质量,支持多声道麦克风拾音 - 优化自动播放服务器的对接机制,提供稳定和兼容旧版ue工程的对接模式 - 数字人接口输出机器人表情,以适应新fay ui及单片机的数字人表情输出 - 使用更高级的音频时长计算方式,可以更精准控制音频播放完成后的逻辑 - 修复点击关闭按钮会导致程序退出的bug - 修复没有麦克风的设备开启麦克风会出错的问题 - 为服务器主机地址提供配置项,以方便服务器部署
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
import json
|
|
import requests
|
|
# from core import content_db
|
|
|
|
class VllmGPT:
|
|
|
|
def __init__(self, host="127.0.0.1",
|
|
port="8000",
|
|
model="THUDM/chatglm3-6b",
|
|
max_tokens="1024"):
|
|
self.host = host
|
|
self.port = port
|
|
self.model=model
|
|
self.max_tokens=max_tokens
|
|
self.__URL = "http://{}:{}/v1/completions".format(self.host, self.port)
|
|
self.__URL2 = "http://{}:{}/v1/chat/completions".format(self.host, self.port)
|
|
|
|
def question(self,cont):
|
|
chat_list = []
|
|
url = "http://127.0.0.1:8101/v1/completions"
|
|
req = json.dumps({
|
|
"model": "THUDM/chatglm3-6b",
|
|
"prompt": cont,
|
|
"max_tokens": 768,
|
|
"temperature": 0})
|
|
print(url)
|
|
print(req)
|
|
|
|
headers = {'content-type': 'application/json'}
|
|
r = requests.post(url, headers=headers, data=req)
|
|
res = json.loads(r.text)
|
|
|
|
return res['choices'][0]['text']
|
|
|
|
def question2(self,cont):
|
|
chat_list = []
|
|
current_chat={"role": "user", "content": cont}
|
|
chat_list.append(current_chat)
|
|
content = {
|
|
"model": self.model,
|
|
"messages": chat_list,
|
|
"max_tokens": 768,
|
|
"temperature": 0.3,
|
|
"user":"live-virtual-digital-person"}
|
|
url = self.__URL2
|
|
req = json.dumps(content)
|
|
headers = {'content-type': 'application/json', 'Authorization': 'Bearer '}
|
|
r = requests.post(url, headers=headers, json=content)
|
|
res = json.loads(r.text)
|
|
|
|
return res['choices'][0]['message']['content']
|
|
|
|
if __name__ == "__main__":
|
|
vllm = VllmGPT('127.0.0.1','8101','Qwen-7B-Chat')
|
|
req = vllm.question2("你叫什么名字啊今年多大了")
|
|
print(req)
|