Commit 7375d90a authored by Rayyyyy's avatar Rayyyyy
Browse files

Add replace codes

parent b9c34648
......@@ -10,6 +10,26 @@ from loguru import logger
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoModel
COMMON = {
"<光合组织登记网址>": "https://www.hieco.com.cn/partner?from=timeline",
"<官网>": "https://www.sugon.com/after_sale/policy?sh=1",
"<平台联系方式>": "1、访问官网,根据您所在地地址联系平台人员,网址地址:https://www.sugon.com/about/contact;\n2、点击人工客服进行咨询;\n3、请您拨打中科曙光服务热线400-810-0466联系人工进行咨询。",
"<购买与维修的咨询方法>": "1、确定付费处理,可以微信搜索'sugon中科曙光服务'小程序,选择'在线报修'业务\n2、先了解价格,可以微信搜索'sugon中科曙光服务'小程序,选择'其他咨询'业务\n3、请您拨打中科曙光服务热线400-810-0466",
"<服务器续保流程>": "1、微信搜索'sugon中科曙光服务'小程序,选择'延保与登记'业务\n2、点击人工客服进行登记\n3、请您拨打中科曙光服务热线400-810-0466根据语音提示选择维保与购买",
"<XC内外网OS网盘链接>": "【腾讯文档】XC内外网OS网盘链接:https://docs.qq.com/sheet/DTWtXbU1BZHJvWkJm",
"<W360-G30机器,安装Win7使用的镜像链接>": "W360-G30机器,安装Win7使用的镜像链接:https://pan.baidu.com/s/1SjHqCP6kJ9KzdJEBZDEynw;提取码:x6m4",
"<麒麟系统搜狗输入法下载链接>": "软件下载链接(百度云盘):链接:https://pan.baidu.com/s/18Iluvs4BOAfFET0yFMBeLQ,提取码:bhkf",
"<X660 G45 GPU服务器拆解视频网盘链接>": "链接: https://pan.baidu.com/s/1RkRGh4XY1T2oYftGnjLp4w;提取码: v2qi",
"<DS800,SANTRICITY存储IBM版本模拟器网盘链接>": "链接:https://pan.baidu.com/s/1euG9HGbPfrVbThEB8BX76g;提取码:o2ya",
"<E80-D312(X680-G55)风冷整机组装说明下载链接>": "链接:https://pan.baidu.com/s/17KDpm-Z9lp01WGp9sQaQ4w;提取码:0802",
"<X680 G55 风冷相关资料下载链接>": "链接:https://pan.baidu.com/s/1KQ-hxUIbTWNkc0xzrEQLjg;提取码:0802",
"<R620 G51刷写EEPROM下载>": "下载链接如下:http://10.2.68.104/tools/bytedance/eeprom/",
"<X7450A0服务器售后培训文件网盘链接>": "网盘下载:https://pan.baidu.com/s/1tZJIf_IeQLOWsvuOawhslQ?pwd=kgf1;提取码:kgf1",
"<福昕阅读器补丁链接>": "补丁链接: https://pan.baidu.com/s/1QJQ1kHRplhhFly-vxJquFQ,提取码: aupx1",
"<W330-H35A_22DB4/W3335HA安装win7网盘链接>": "硬盘链接: https://pan.baidu.com/s/1fDdGPH15mXiw0J-fMmLt6Q提取码: k97i",
"<X680 G55服务器售后培训资料网盘链接>": "云盘连接下载:链接:https://pan.baidu.com/s/1gaok13DvNddtkmk6Q-qLYg?pwd=xyhb提取码:xyhb",
}
def build_history_messages(prompt, history, system: str = None):
history_messages = []
if system is not None and len(system) > 0:
......@@ -58,6 +78,7 @@ class InferenceWrapper:
def chat(self, prompt: str, history=[]):
'''单轮问答'''
import re
output_text = ''
try:
if self.use_vllm:
......@@ -68,6 +89,14 @@ class InferenceWrapper:
prompt,
history,
do_sample=False)
matchObj = re.match('.*(<.*>).*', output_text)
if matchObj:
obj = matchObj.group(1)
replace_str = COMMON.get(obj)
output_text = output_text.replace(obj, replace_str)
logger.info(f"{obj} be replaced {replace_str}, after {output_text}")
except Exception as e:
logger.error(f"chat inference failed, {e}")
return output_text
......@@ -75,19 +104,34 @@ class InferenceWrapper:
def chat_stream(self, prompt: str, history=[]):
'''流式服务'''
import re
if self.use_vllm:
from fastllm_pytools import llm
# Fastllm
for response in self.model.stream_response(prompt, history=[]):
matchObj = re.match('.*(<.*>).*', response)
if matchObj:
obj = matchObj.group(1)
replace_str = COMMON.get(obj)
response = response.replace(obj, replace_str)
logger.info(f"{obj} be replaced {replace_str}, after {response}")
yield response
else:
# HuggingFace
current_length = 0
past_key_values = None
for response, _, past_key_values in self.model.stream_chat(self.tokenizer, prompt, history=history,
past_key_values=past_key_values,
past_key_values=None,
return_past_key_values=True):
output_text = response[current_length:]
matchObj = re.match('.*(<.*>).*', output_text)
if matchObj:
obj = matchObj.group(1)
replace_str = COMMON.get(obj)
output_text = output_text.replace(obj, replace_str)
logger.info(f"{obj} be replaced {replace_str}, after {output_text}")
yield output_text
current_length = len(response)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment