From ba84585e12171368c09fe5f6d6abd3d34d4df927 Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Sun, 19 Nov 2023 06:26:42 +0800 Subject: [PATCH] 0.1.38 --- PyPI/setup.cfg | 2 +- PyPI/src/guan.egg-info/PKG-INFO | 2 +- PyPI/src/guan/data_processing.py | 119 ++++++++++++++++++++----------- 3 files changed, 81 insertions(+), 42 deletions(-) diff --git a/PyPI/setup.cfg b/PyPI/setup.cfg index a018e5b..e7f9c4f 100644 --- a/PyPI/setup.cfg +++ b/PyPI/setup.cfg @@ -1,7 +1,7 @@ [metadata] # replace with your username: name = guan -version = 0.1.37 +version = 0.1.38 author = guanjihuan author_email = guanjihuan@163.com description = An open source python package diff --git a/PyPI/src/guan.egg-info/PKG-INFO b/PyPI/src/guan.egg-info/PKG-INFO index 0a2bac4..3a5a7de 100644 --- a/PyPI/src/guan.egg-info/PKG-INFO +++ b/PyPI/src/guan.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: guan -Version: 0.1.37 +Version: 0.1.38 Summary: An open source python package Home-page: https://py.guanjihuan.com Author: guanjihuan diff --git a/PyPI/src/guan/data_processing.py b/PyPI/src/guan/data_processing.py index 15efdef..c1d9ed6 100644 --- a/PyPI/src/guan/data_processing.py +++ b/PyPI/src/guan/data_processing.py @@ -1,5 +1,83 @@ # Module: data_processing +# 在服务器上运行大语言模型,通过Python函数调用 +def chat(prompt='你好', stream_show=1, top_p=0.8, temperature=0.8): + import socket + import json + response = '' + 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, + 'top_p': top_p, + 'temperature': temperature, + } + send_message = json.dumps(message) + client_socket.send(send_message.encode()) + while True: + try: + data = client_socket.recv(1024) + stream_response = data.decode() + response_dict = json.loads(stream_response) + stream_response = response_dict['response'] + end_message = response_dict['end_message'] + if end_message == 1: + break + elif stream_response == '': + break + else: + if stream_show == 1: + print(stream_response) + print('\n---\n') + response = stream_response + except: + break + client_socket.close() + import guan + guan.statistics_of_guan_package() + return response + +# 在云端服务器上运行函数 +def run(function_name, args=(), return_show=0, get_print=1): + import socket + import json + import guan + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket: + client_socket.settimeout(15) + client_socket.connect(('socket.guanjihuan.com', 12345)) + function_source = guan.get_function_source(function_name) + message = { + 'server': "python", + 'function_name': function_name.__name__, + 'function_source': function_source, + 'args': args, + 'get_print': get_print, + } + send_message = json.dumps(message) + client_socket.send(send_message.encode()) + return_data = None + while True: + try: + data = client_socket.recv(1024) + return_text = data.decode() + return_dict = json.loads(return_text) + return_data = return_dict['return_data'] + print_data = return_dict['print_data'] + end_message = return_dict['end_message'] + if get_print == 1: + print(print_data) + if return_show == 1: + print(return_data) + if end_message == 1 or return_text == '': + break + except: + break + client_socket.close() + guan.statistics_of_guan_package() + return return_data + # 并行计算前的预处理,把参数分成多份 def preprocess_for_parallel_calculations(parameter_array_all, cpus=1, task_index=0): import numpy as np @@ -382,43 +460,4 @@ def get_PID(name): id_running = ps_ef[1] import guan guan.statistics_of_guan_package() - return id_running - -# 在服务器上运行大语言模型,通过Python函数调用 -def chat(prompt='你好', stream_show=1, top_p=0.8, temperature=0.8): - import socket - import json - response = '' - 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, - 'top_p': top_p, - 'temperature': temperature, - } - send_message = json.dumps(message) - client_socket.send(send_message.encode()) - while True: - try: - data = client_socket.recv(1024) - stream_response = data.decode() - response_dict = json.loads(stream_response) - stream_response = response_dict['response'] - end_message = response_dict['end_message'] - if end_message == 1: - break - elif stream_response == '': - break - else: - if stream_show == 1: - print(stream_response) - print('\n---\n') - response = stream_response - except: - break - client_socket.close() - import guan - guan.statistics_of_guan_package() - return response \ No newline at end of file + return id_running \ No newline at end of file