0.1.102(重新增加chat函数)
This commit is contained in:
parent
3045231303
commit
f70b731903
@ -1,7 +1,7 @@
|
||||
[metadata]
|
||||
# replace with your username:
|
||||
name = guan
|
||||
version = 0.1.101
|
||||
version = 0.1.102
|
||||
author = guanjihuan
|
||||
author_email = guanjihuan@163.com
|
||||
description = An open source python package
|
||||
|
@ -1,6 +1,6 @@
|
||||
Metadata-Version: 2.1
|
||||
Name: guan
|
||||
Version: 0.1.101
|
||||
Version: 0.1.102
|
||||
Summary: An open source python package
|
||||
Home-page: https://py.guanjihuan.com
|
||||
Author: guanjihuan
|
||||
|
@ -1,5 +1,47 @@
|
||||
# Module: others
|
||||
|
||||
# 模型对话
|
||||
def chat(prompt='你好', model=1, stream=0, top_p=0.8, temperature=0.85):
|
||||
'''
|
||||
model=1: 'qwen1.5-0.5b-chat'
|
||||
model=2: 'qwen-1.8b-chat'
|
||||
'''
|
||||
import socket
|
||||
import json
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket:
|
||||
client_socket.settimeout(15)
|
||||
client_socket.connect(('socket.guanjihuan.com', 12345))
|
||||
message = {
|
||||
'server': "chat.guanjihuan.com",
|
||||
'prompt': prompt,
|
||||
'model': model,
|
||||
'top_p': top_p,
|
||||
'temperature': temperature,
|
||||
}
|
||||
send_message = json.dumps(message)
|
||||
client_socket.send(send_message.encode())
|
||||
if stream == 1:
|
||||
print('\n--- Begin Stream Message ---\n')
|
||||
while True:
|
||||
try:
|
||||
data = client_socket.recv(1024)
|
||||
stream_response = data.decode()
|
||||
response_dict = json.loads(stream_response)
|
||||
stream_response = response_dict['response']
|
||||
response = response_dict['all_response']
|
||||
end_message = response_dict['end_message']
|
||||
if end_message == 1:
|
||||
break
|
||||
else:
|
||||
if stream == 1:
|
||||
print(stream_response)
|
||||
except:
|
||||
break
|
||||
client_socket.close()
|
||||
if stream == 1:
|
||||
print('\n--- End Stream Message ---\n')
|
||||
return response
|
||||
|
||||
# 获取当前日期字符串
|
||||
def get_date(bar=True):
|
||||
import datetime
|
||||
|
Loading…
x
Reference in New Issue
Block a user