diff --git a/chat_command.py b/chat_command.py new file mode 100644 index 0000000..60f9820 --- /dev/null +++ b/chat_command.py @@ -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() \ No newline at end of file diff --git a/client.pyw b/client.pyw index de87e82..05a3412 100644 --- a/client.pyw +++ b/client.pyw @@ -10,7 +10,8 @@ CURRENT_DIR = os.getcwd() FILE_ERROR = '文件丢失,请检查文件内容并重新安装' task = f'taskkill -f -t -im ' -# Define functions +''' Define functions +程序文件检测''' def open_exe(exe_name): if os.path.exists(os.path.join(CURRENT_DIR, f"{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 xz_chat.exe') os.system('taskkill -f -t -im xz_main.exe') + os.system('taskkill -f -t -im ol_web.exe') sys.exit() def ol_web(): + messagebox.showwarning("Warning","这个程序为测试版,如有问题,请马上反馈!") open_exe('ol_web') # Create GUI @@ -53,7 +56,7 @@ root.geometry('200x200+400+400') Label(root, text='chatGPT').pack() 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) Label(root, text='chatWEB') diff --git a/update.pyw b/update.pyw index fdf8d5c..a03f9aa 100644 --- a/update.pyw +++ b/update.pyw @@ -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) Label(root, text='更新日志').pack() text = ''' -当前版本:1.3 (Not beta or demo) +当前版本:1.4 (Not beta or demo) 0.1.0 DEMO制作完成 0.1.1 demo版本增加lbbAI网站 diff --git a/xz_main.pyw b/xz_main.pyw index 07145ca..6701ea7 100644 --- a/xz_main.pyw +++ b/xz_main.pyw @@ -20,9 +20,12 @@ def chat(): def quit_exe(): sys.exit() + +# Button chat_b = Button(root ,text='聊天网站', command=chat) q_b = Button(root ,text='返回', command= quit_exe) +# pack Button and label Label(root, text='选择模式').pack() chat_b.pack() q_b.pack() diff --git a/没有使用/chat_command.py b/没有使用/chat_command.py deleted file mode 100644 index c817ca3..0000000 --- a/没有使用/chat_command.py +++ /dev/null @@ -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}") diff --git a/chat_command_client.pyw b/没有使用/chat_command_client.pyw similarity index 100% rename from chat_command_client.pyw rename to 没有使用/chat_command_client.pyw