增加加了博物馆展品清单数据库及对前端获取展品清单、展品详细的接口,增加了QWenOmni多模态大模型的支 持(主要为了测试),增加了本地部署大模型支持(主要为了测试,在autoDL上),修正了TTS生成和返回前端的逻辑与参数,增加了判断用户问题有没有在知识库中检索到相关片段、如果没有则直接返回并提示未包含
This commit is contained in:
@@ -127,6 +127,98 @@ class DeepSeekChat(Base):
|
||||
super().__init__(key, model_name, base_url)
|
||||
|
||||
|
||||
class LocalLLMChat(Base):
|
||||
def __init__(self, key, model_name="Qwen2.5-7B", base_url="http://106.52.71.204:9483/v1"):
|
||||
if not base_url: base_url = "http://106.52.71.204:9483/v1"
|
||||
super().__init__(key, model_name, base_url)
|
||||
|
||||
class QWenOmniChat(Base):
|
||||
def __init__(self, key, model_name="qwen-omni-turbo", base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"):
|
||||
if not base_url: base_url = "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||||
super().__init__(key, model_name, base_url)
|
||||
def chat(self, system, history, gen_conf):
|
||||
if system:
|
||||
history.insert(0, {"role": "system", "content": system})
|
||||
ans = ""
|
||||
total_tokens = 0
|
||||
try:
|
||||
response = self.client.chat.completions.create(
|
||||
model = self.model_name,
|
||||
messages=history,
|
||||
stream=True,
|
||||
# 设置输出数据的模态,当前支持两种:["text","audio"]、["text"]
|
||||
# modalities=["text", "audio"],
|
||||
# audio={"voice": "Cherry", "format": "wav"},
|
||||
# stream 必须设置为 True,否则会报错
|
||||
# stream_options={"include_usage": True},
|
||||
**gen_conf
|
||||
)
|
||||
for resp in response:
|
||||
if not resp.choices: continue
|
||||
if not resp.choices[0].delta.content:
|
||||
resp.choices[0].delta.content = ""
|
||||
ans += resp.choices[0].delta.content
|
||||
|
||||
if not hasattr(resp, "usage") or not resp.usage:
|
||||
total_tokens = (
|
||||
total_tokens
|
||||
+ num_tokens_from_string(resp.choices[0].delta.content)
|
||||
)
|
||||
elif isinstance(resp.usage, dict):
|
||||
total_tokens = resp.usage.get("total_tokens", total_tokens)
|
||||
else: total_tokens = resp.usage.total_tokens
|
||||
|
||||
if resp.choices[0].finish_reason == "length":
|
||||
ans += "...\nFor the content length reason, it stopped, continue?" if is_english(
|
||||
[ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?"
|
||||
break # 如果达到长度限制,可以跳出循环
|
||||
except openai.APIError as e:
|
||||
ans= ans + "\n**ERROR**: " + str(e)
|
||||
|
||||
return ans, total_tokens
|
||||
|
||||
|
||||
def chat_streamly(self, system, history, gen_conf):
|
||||
# logging.info(f"chat_streamly :{gen_conf}")
|
||||
if system :
|
||||
history.insert(0, {"role": "system", "content":
|
||||
[{"type":"text","text": system}]})
|
||||
ans = ""
|
||||
total_tokens = 0
|
||||
try:
|
||||
response = self.client.chat.completions.create(
|
||||
model=self.model_name,
|
||||
messages=history,
|
||||
stream=True,
|
||||
#**gen_conf
|
||||
)
|
||||
for resp in response:
|
||||
if not resp.choices: continue
|
||||
if not resp.choices[0].delta.content:
|
||||
resp.choices[0].delta.content = ""
|
||||
ans += resp.choices[0].delta.content
|
||||
|
||||
if not hasattr(resp, "usage") or not resp.usage:
|
||||
total_tokens = (
|
||||
total_tokens
|
||||
+ num_tokens_from_string(resp.choices[0].delta.content)
|
||||
)
|
||||
elif isinstance(resp.usage, dict):
|
||||
total_tokens = resp.usage.get("total_tokens", total_tokens)
|
||||
else: total_tokens = resp.usage.total_tokens
|
||||
|
||||
if resp.choices[0].finish_reason == "length":
|
||||
ans += "...\nFor the content length reason, it stopped, continue?" if is_english(
|
||||
[ans]) else "······\n由于长度的原因,回答被截断了,要继续吗?"
|
||||
yield ans
|
||||
|
||||
except openai.APIError as e:
|
||||
yield ans + "\n**ERROR**: " + str(e)
|
||||
|
||||
yield total_tokens
|
||||
|
||||
|
||||
|
||||
class AzureChat(Base):
|
||||
def __init__(self, key, model_name, **kwargs):
|
||||
api_key = json.loads(key).get('api_key', '')
|
||||
|
||||
Reference in New Issue
Block a user