update
This commit is contained in:
30
callback.py
30
callback.py
@@ -14,6 +14,7 @@ import torch
|
||||
import json
|
||||
import base64
|
||||
import requests
|
||||
from tentcentSMS import sendSms
|
||||
|
||||
#使用int8的量化模型
|
||||
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm2-6b-int4", trust_remote_code=True)
|
||||
@@ -40,6 +41,21 @@ def save_encoded_image(b64_image: str, output_path: str):
|
||||
with open(output_path, "wb") as image_file:
|
||||
image_file.write(base64.b64decode(b64_image))
|
||||
|
||||
# 正则查找11位手机号
|
||||
def findPhoneNum(text):
|
||||
pattern = re.compile(r"1[356789]\d{9}")
|
||||
# strs = '小明的手机号是13987692110,你明天打给他'
|
||||
result = pattern.findall(text)
|
||||
print(result)
|
||||
# ['13987692110']
|
||||
if len(result) > 0:
|
||||
# 通过腾讯云-短信发送api
|
||||
sendSms(result[0])
|
||||
return result[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
# bot发消息到tg群组
|
||||
def sendTg(message):
|
||||
@@ -195,11 +211,7 @@ async def img(
|
||||
# print("console :,", "appid", appid, "bid", bid, "requestid", requestid, "uid", uid)
|
||||
print('query',query)
|
||||
print('query[query]',query["query"])
|
||||
try:
|
||||
sendTg(query["query"])
|
||||
except:
|
||||
print('发送tg失败')
|
||||
|
||||
# sendTg(query["query"])
|
||||
# 获取请求参数
|
||||
global model, tokenizer
|
||||
# time.sleep(10)
|
||||
@@ -227,6 +239,12 @@ async def img(
|
||||
response=f'#web_img http://aiimg.hackrobot.cn/{now}.png'
|
||||
print('response',response)
|
||||
# return responseimg
|
||||
elif ('手机号' in query) is True:
|
||||
phonenumber=findPhoneNum(query)
|
||||
if phonenumber is not None:
|
||||
response="请查收短信,并在微信回复短信中的数字,自动邀请加群"
|
||||
else:
|
||||
response="手机号格式不正确,或其他错误"
|
||||
|
||||
else:
|
||||
prompt = query #问题
|
||||
@@ -267,4 +285,4 @@ async def img(
|
||||
# model = load_model_on_gpus(model_path, num_gpus=2)
|
||||
|
||||
# model.eval()
|
||||
# uvicorn.run(app, host='0.0.0.0', port=8000, workers=1
|
||||
# uvicorn.run(app, host='0.0.0.0', port=8000, workers=1)
|
||||
Reference in New Issue
Block a user