0.1.187
This commit is contained in:
@@ -1,64 +1,5 @@
|
||||
# Module: others
|
||||
|
||||
# AI 对话
|
||||
def chat(prompt='你好', model=1, stream=1, stream_label=0):
|
||||
import requests
|
||||
url = "http://api.guanjihuan.com/chat"
|
||||
data = {
|
||||
"prompt": prompt,
|
||||
"model": model,
|
||||
}
|
||||
if stream == 1:
|
||||
if stream_label == 1:
|
||||
print('\n--- Start Chat Stream Message ---\n')
|
||||
requests_response = requests.post(url, json=data, stream=True)
|
||||
response = ''
|
||||
if requests_response.status_code == 200:
|
||||
for line in requests_response.iter_lines():
|
||||
if line:
|
||||
if stream == 1:
|
||||
print(line.decode('utf-8'), end='', flush=True)
|
||||
response += line.decode('utf-8')
|
||||
print()
|
||||
else:
|
||||
pass
|
||||
if stream == 1:
|
||||
if stream_label == 1:
|
||||
print('\n--- End Chat Stream Message ---\n')
|
||||
return response
|
||||
|
||||
# 加上函数代码的 AI 对话
|
||||
def chat_with_function_code(function_name, prompt='', model=1, stream=1):
|
||||
import guan
|
||||
function_source = guan.get_source(function_name)
|
||||
if prompt == '':
|
||||
response = guan.chat(prompt=function_source, model=model, stream=stream)
|
||||
else:
|
||||
response = guan.chat(prompt=function_source+'\n\n'+prompt, model=model, stream=stream)
|
||||
return response
|
||||
|
||||
# 机器人自动对话
|
||||
def auto_chat(prompt='你好', round=2, model=1, stream=1):
|
||||
import guan
|
||||
response0 = prompt
|
||||
for i0 in range(round):
|
||||
print(f'\n【对话第 {i0+1} 轮】\n')
|
||||
print('机器人 1: ')
|
||||
response1 = guan.chat(prompt=response0, model=model, stream=stream)
|
||||
print('机器人 2: ')
|
||||
response0 = guan.chat(prompt=response1, model=model, stream=stream)
|
||||
|
||||
# 机器人自动对话(引导对话)
|
||||
def auto_chat_with_guide(prompt='你好', guide_message='(回答字数少于30个字,最后反问我一个问题)', round=5, model=1, stream=1):
|
||||
import guan
|
||||
response0 = prompt
|
||||
for i0 in range(round):
|
||||
print(f'\n【对话第 {i0+1} 轮】\n')
|
||||
print('机器人 1: ')
|
||||
response1 = guan.chat(prompt=response0+guide_message, model=model, stream=stream)
|
||||
print('机器人 2: ')
|
||||
response0 = guan.chat(prompt=response1+guide_message, model=model, stream=stream)
|
||||
|
||||
# CPU性能测试(十亿次循环的浮点加法运算的时间,约30秒左右)
|
||||
def cpu_test_with_addition(print_show=1):
|
||||
import time
|
||||
|
||||
Reference in New Issue
Block a user