2023/8/25 update
This commit is contained in:
47
chat_command.py
Normal file
47
chat_command.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import openai
|
||||||
|
import os
|
||||||
|
from time import sleep
|
||||||
|
import sys
|
||||||
|
|
||||||
|
ml = os.getcwd()
|
||||||
|
file_path = os.path.join(ml, "api_key.txt")
|
||||||
|
|
||||||
|
# 设置openai库的API认证密钥
|
||||||
|
def api_key():
|
||||||
|
input1 = input("请输入API_key:")
|
||||||
|
if input1 == None:
|
||||||
|
print('error: Not input')
|
||||||
|
sleep(4)
|
||||||
|
sys.exit()
|
||||||
|
else:
|
||||||
|
openai.api_key = input1
|
||||||
|
|
||||||
|
# 设置GPT-3.5模型的引擎ID
|
||||||
|
model_engine = 'text-davinci-003'
|
||||||
|
|
||||||
|
# 循环读入用户输入并输出聊天结果
|
||||||
|
def input_print():
|
||||||
|
while True:
|
||||||
|
# 获取用户输入
|
||||||
|
prompt = input("你好,请问有什么需要帮助的吗?\n")
|
||||||
|
|
||||||
|
# 调用openai.ChatCompletion.create()方法来获取聊天结果
|
||||||
|
response = openai.Completion.create(
|
||||||
|
engine='text-davinci-003',
|
||||||
|
prompt=prompt,
|
||||||
|
temperature=0.7,
|
||||||
|
max_tokens=210,
|
||||||
|
top_p=1,
|
||||||
|
frequency_penalty=0,
|
||||||
|
presence_penalty=0
|
||||||
|
)
|
||||||
|
result = response['choices'][0]['text'].strip()
|
||||||
|
print(f"chatGPT:{result}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print('注意,本程序是测试程序,如有问题,非常正常')
|
||||||
|
sleep(2)
|
||||||
|
api_key()
|
||||||
|
# 设置GPT-3.5模型的引擎ID
|
||||||
|
model_engine = 'text-davinci-003'
|
||||||
|
input_print()
|
||||||
@@ -10,7 +10,8 @@ CURRENT_DIR = os.getcwd()
|
|||||||
FILE_ERROR = '文件丢失,请检查文件内容并重新安装'
|
FILE_ERROR = '文件丢失,请检查文件内容并重新安装'
|
||||||
task = f'taskkill -f -t -im '
|
task = f'taskkill -f -t -im '
|
||||||
|
|
||||||
# Define functions
|
''' Define functions
|
||||||
|
程序文件检测'''
|
||||||
def open_exe(exe_name):
|
def open_exe(exe_name):
|
||||||
if os.path.exists(os.path.join(CURRENT_DIR, f"{exe_name}.exe")):
|
if os.path.exists(os.path.join(CURRENT_DIR, f"{exe_name}.exe")):
|
||||||
os.system(f"start {exe_name}.exe")
|
os.system(f"start {exe_name}.exe")
|
||||||
@@ -41,9 +42,11 @@ def quit_exe():
|
|||||||
os.system('taskkill -f -t -im update.exe')
|
os.system('taskkill -f -t -im update.exe')
|
||||||
os.system('taskkill -f -t -im xz_chat.exe')
|
os.system('taskkill -f -t -im xz_chat.exe')
|
||||||
os.system('taskkill -f -t -im xz_main.exe')
|
os.system('taskkill -f -t -im xz_main.exe')
|
||||||
|
os.system('taskkill -f -t -im ol_web.exe')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def ol_web():
|
def ol_web():
|
||||||
|
messagebox.showwarning("Warning","这个程序为测试版,如有问题,请马上反馈!")
|
||||||
open_exe('ol_web')
|
open_exe('ol_web')
|
||||||
|
|
||||||
# Create GUI
|
# Create GUI
|
||||||
@@ -53,7 +56,7 @@ root.geometry('200x200+400+400')
|
|||||||
Label(root, text='chatGPT').pack()
|
Label(root, text='chatGPT').pack()
|
||||||
|
|
||||||
bt_web_xz = Button(root, text='网站选择', command=web_xz)
|
bt_web_xz = Button(root, text='网站选择', command=web_xz)
|
||||||
ol_web_b = Button(root ,text='官网', command=ol_web)
|
ol_web_b = Button(root ,text='官方网站', command=ol_web)
|
||||||
quit_bt = Button(root, text='退出', command=quit_exe)
|
quit_bt = Button(root, text='退出', command=quit_exe)
|
||||||
|
|
||||||
Label(root, text='chatWEB')
|
Label(root, text='chatWEB')
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ update_now_bt = Button(root ,text='在线更新', command=update_now).pack(side=
|
|||||||
quit_bt = Button(root, text='返回', command=quit_exe).pack(side=RIGHT)
|
quit_bt = Button(root, text='返回', command=quit_exe).pack(side=RIGHT)
|
||||||
Label(root, text='更新日志').pack()
|
Label(root, text='更新日志').pack()
|
||||||
text = '''
|
text = '''
|
||||||
当前版本:1.3 (Not beta or demo)
|
当前版本:1.4 (Not beta or demo)
|
||||||
|
|
||||||
0.1.0 DEMO制作完成
|
0.1.0 DEMO制作完成
|
||||||
0.1.1 demo版本增加lbbAI网站
|
0.1.1 demo版本增加lbbAI网站
|
||||||
|
|||||||
@@ -20,9 +20,12 @@ def chat():
|
|||||||
def quit_exe():
|
def quit_exe():
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
# Button
|
||||||
chat_b = Button(root ,text='聊天网站', command=chat)
|
chat_b = Button(root ,text='聊天网站', command=chat)
|
||||||
q_b = Button(root ,text='返回', command= quit_exe)
|
q_b = Button(root ,text='返回', command= quit_exe)
|
||||||
|
|
||||||
|
# pack Button and label
|
||||||
Label(root, text='选择模式').pack()
|
Label(root, text='选择模式').pack()
|
||||||
chat_b.pack()
|
chat_b.pack()
|
||||||
q_b.pack()
|
q_b.pack()
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
import openai
|
|
||||||
import os
|
|
||||||
from time import sleep
|
|
||||||
import sys
|
|
||||||
|
|
||||||
ml = os.getcwd()
|
|
||||||
file_path = os.path.join(ml, "api_key.txt")
|
|
||||||
|
|
||||||
# 设置openai库的API认证密钥
|
|
||||||
def api_key():
|
|
||||||
if os.path.exists(os.path.join(ml, f"api_key.txt")):
|
|
||||||
with open(file_path, 'r') as f:
|
|
||||||
openai.api_key = f.read().strip()
|
|
||||||
else:
|
|
||||||
print('文件丢失,请重新输入api_key')
|
|
||||||
sleep(1)
|
|
||||||
if os.path.exists(os.path.join(ml, "chat_command_GUI.exe")):
|
|
||||||
os.startfile("chat_command_GUI.exe")
|
|
||||||
else:
|
|
||||||
print('错误,文件不存在!?')
|
|
||||||
sleep(1)
|
|
||||||
sys.exit()
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# 设置GPT-3.5模型要使用的API_key
|
|
||||||
api_key()
|
|
||||||
|
|
||||||
# 设置GPT-3.5模型的引擎ID
|
|
||||||
model_engine = 'text-davinci-003'
|
|
||||||
|
|
||||||
# 循环读入用户输入并输出聊天结果
|
|
||||||
while True:
|
|
||||||
# 获取用户输入
|
|
||||||
prompt = input("你好,请问有什么需要帮助的吗?\n")
|
|
||||||
|
|
||||||
# 调用openai.ChatCompletion.create()方法来获取聊天结果
|
|
||||||
response = openai.Completion.create(
|
|
||||||
engine='text-davinci-003',
|
|
||||||
prompt=prompt,
|
|
||||||
temperature=0.7,
|
|
||||||
max_tokens=210,
|
|
||||||
top_p=1,
|
|
||||||
frequency_penalty=0,
|
|
||||||
presence_penalty=0
|
|
||||||
)
|
|
||||||
result = response['choices'][0]['text'].strip()
|
|
||||||
print(f"chatGPT:{result}")
|
|
||||||
Reference in New Issue
Block a user