chatWEB
This commit is contained in:
48
没有使用/chat_command.py
Normal file
48
没有使用/chat_command.py
Normal file
@@ -0,0 +1,48 @@
|
||||
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}")
|
||||
50
没有使用/chat_command_GUI.pyw
Normal file
50
没有使用/chat_command_GUI.pyw
Normal file
@@ -0,0 +1,50 @@
|
||||
import sys
|
||||
from tkinter import *
|
||||
from tkinter import messagebox
|
||||
import os
|
||||
import requests
|
||||
|
||||
root = Tk()
|
||||
ml = os.getcwd()
|
||||
file_path = os.path.join(ml, "api_key.txt")
|
||||
|
||||
|
||||
def open_exe(exe_name):
|
||||
if os.path.exists(os.path.join(ml ,f"{exe_name}.exe")):
|
||||
os.system(f"start {exe_name}.exe")
|
||||
else:
|
||||
messagebox.showerror('chatGPT','错误:命令行文件不存在!')
|
||||
pass
|
||||
def chat_command():
|
||||
API_key = entry_APIkey.get()
|
||||
if API_key != None:
|
||||
with open(file_path,'w') as f:
|
||||
f.write(API_key)
|
||||
pass
|
||||
open_exe('chat_command')
|
||||
pass
|
||||
else:
|
||||
messagebox.showerror('错误','API_key不存在!无法使用!')
|
||||
|
||||
def fh():
|
||||
sys.exit()
|
||||
|
||||
|
||||
# Button
|
||||
run_command = Button(root, text='chatGPT启动', command=chat_command)
|
||||
fh_bt = Button(root, text='返回', command=fh)
|
||||
|
||||
# entry
|
||||
entry_APIkey = Entry(root)
|
||||
|
||||
# grid
|
||||
Label(root, text='api_key:').grid(row=0,column=0)
|
||||
entry_APIkey.grid(row=0, column=1)
|
||||
run_command.grid(row=2,column=0)
|
||||
fh_bt.grid(row=2,column=1)
|
||||
|
||||
|
||||
# mainloop
|
||||
root.title('chatGPT')
|
||||
root.geometry('200x250+100+100')
|
||||
root.mainloop()
|
||||
25
没有使用/xjai.pyw
Normal file
25
没有使用/xjai.pyw
Normal file
@@ -0,0 +1,25 @@
|
||||
import sys
|
||||
from PyQt5.QtCore import QUrl
|
||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QAction
|
||||
from PyQt5.QtWebEngineWidgets import QWebEngineView
|
||||
|
||||
class Browser(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle('浏览器')
|
||||
|
||||
self.browser = QWebEngineView()
|
||||
self.browser.setUrl(QUrl('https://home.xjai.cc'))
|
||||
self.setCentralWidget(self.browser)
|
||||
|
||||
refresh_button = QAction('刷新', self)
|
||||
refresh_button.triggered.connect(self.browser.reload)
|
||||
self.toolbar = self.addToolBar('Refresh')
|
||||
self.toolbar.addAction(refresh_button)
|
||||
|
||||
|
||||
# mainloop
|
||||
app = QApplication(sys.argv)
|
||||
browser = Browser()
|
||||
browser.showMaximized()
|
||||
sys.exit(app.exec_())
|
||||
18
没有使用/xz_login.pyw
Normal file
18
没有使用/xz_login.pyw
Normal file
@@ -0,0 +1,18 @@
|
||||
from tkinter import *
|
||||
from tkinter import messagebox
|
||||
import os
|
||||
|
||||
|
||||
root = Tk()
|
||||
ml = os.getcwd()
|
||||
|
||||
|
||||
def open_exe(exe_name):
|
||||
if exe_name == None:
|
||||
messagebox.showerror('程序错误:没有参数')
|
||||
pass
|
||||
if os.path.exists(os.path.join(ml, f"{exe_name}.exe")):
|
||||
os.system(f"start {exe_name}.exe")
|
||||
else:
|
||||
messagebox.showerror('chatWEB', '重要文件丢失,请重新安装')
|
||||
pass
|
||||
Reference in New Issue
Block a user