You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
import concurrent . futures
import requests
import socket
def dialog_line_parse ( url , text ) :
"""
将数据输入模型进行分析并输出结果
: param url : 模型url
: param text : 进入模型的数据
: return : 模型返回结果
"""
response = requests . post (
url ,
json = text ,
timeout = 1000
)
if response . status_code == 200 :
return response . json ( )
else :
# logger.error(
# "【{}】 Failed to get a proper response from remote "
# "server. Status Code: {}. Response: {}"
# "".format(url, response.status_code, response.text)
# )
print ( " 【 {} 】 Failed to get a proper response from remote "
" server. Status Code: {} . Response: {} "
" " . format ( url , response . status_code , response . text ) )
print ( text )
return [ ]
text = " User:生成目录# \n 问:为论文题目《基于跨文化意识培养的中职英语词汇教学模式及策略行动研究》生成目录,要求只有一级标题和二级标题,一级标题使用中文数字 例如一、xxx;二级标题使用阿拉伯数字 例如1.1 xxx;一级标题不少于7个;每个一级标题至少包含3个二级标题 \n 答: \n \n Assistant: " # 获取用户query中的文本 例如"I love you"
nums = 10
nums = int ( nums )
url = " http://192.168.31.74:12000/predict "
input_data = [ ]
for i in range ( nums ) :
input_data . append ( [ url , { " texts " : text } ] )
with concurrent . futures . ThreadPoolExecutor ( ) as executor :
# 使用submit方法将任务提交给线程池,并获取Future对象
futures = [ executor . submit ( dialog_line_parse , i [ 0 ] , i [ 1 ] ) for i in input_data ]
# 使用as_completed获取已完成的任务,并获取返回值
results = [ future . result ( ) for future in concurrent . futures . as_completed ( futures ) ]
print ( results )