This commit is contained in:
guanjihuan 2025-02-22 11:32:09 +08:00
parent 65ae0be518
commit 78898443c3
3 changed files with 8 additions and 5 deletions

View File

@ -1,7 +1,7 @@
[metadata] [metadata]
# replace with your username: # replace with your username:
name = guan name = guan
version = 0.1.145 version = 0.1.147
author = guanjihuan author = guanjihuan
author_email = guanjihuan@163.com author_email = guanjihuan@163.com
description = An open source python package description = An open source python package

View File

@ -1,6 +1,6 @@
Metadata-Version: 2.2 Metadata-Version: 2.2
Name: guan Name: guan
Version: 0.1.145 Version: 0.1.147
Summary: An open source python package Summary: An open source python package
Home-page: https://py.guanjihuan.com Home-page: https://py.guanjihuan.com
Author: guanjihuan Author: guanjihuan

View File

@ -1,7 +1,7 @@
# Module: data_processing # Module: data_processing
# AI 对话 # AI 对话
def chat(prompt='你好', model=1, stream=1): def chat(prompt='你好', model=1, stream=1, stream_label=0):
import requests import requests
url = "http://api.guanjihuan.com/chat" url = "http://api.guanjihuan.com/chat"
data = { data = {
@ -9,6 +9,7 @@ def chat(prompt='你好', model=1, stream=1):
"model": model, "model": model,
} }
if stream == 1: if stream == 1:
if stream_label == 1:
print('\n--- Start Chat Stream Message ---\n') print('\n--- Start Chat Stream Message ---\n')
requests_response = requests.post(url, json=data, stream=True) requests_response = requests.post(url, json=data, stream=True)
response = '' response = ''
@ -18,9 +19,11 @@ def chat(prompt='你好', model=1, stream=1):
if stream == 1: if stream == 1:
print(line.decode('utf-8'), end='', flush=True) print(line.decode('utf-8'), end='', flush=True)
response += line.decode('utf-8') response += line.decode('utf-8')
print()
else: else:
pass pass
if stream == 1: if stream == 1:
if stream_label == 1:
print('\n\n--- End Chat Stream Message ---\n') print('\n\n--- End Chat Stream Message ---\n')
return response return response