mirror of
https://github.com/Kakune55/PyGetGPT.git
synced 2025-06-28 07:48:03 +08:00
Compare commits
4 Commits
2b8f18157d
...
50445d8af3
Author | SHA1 | Date | |
---|---|---|---|
50445d8af3 | |||
9837a91e65 | |||
6654ea0953 | |||
90403d78bb |
14
README.md
14
README.md
@ -1,3 +1,17 @@
|
|||||||
# PyGetGPT
|
# PyGetGPT
|
||||||
使用python构建的简易语言模型api调用系统
|
使用python构建的简易语言模型api调用系统
|
||||||
使用web页面作为GUI易于部署
|
使用web页面作为GUI易于部署
|
||||||
|
---
|
||||||
|
## 使用的外部库
|
||||||
|
- flask
|
||||||
|
- flask_cors
|
||||||
|
- zhipuai
|
||||||
|
- pymysql
|
||||||
|
- requests
|
||||||
|
- openai
|
||||||
|
|
||||||
|
## 使用pip安装依赖
|
||||||
|
~~~ bash
|
||||||
|
pip install pymysql requests flask zhipuai openai
|
||||||
|
pip install pymysql requests flask zhipuai openai -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
|
~~~
|
||||||
|
@ -22,6 +22,6 @@ def service(prompt,history = ""):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
if response["code"] == 200:
|
if response["code"] == 200:
|
||||||
return 200, response["data"]["choices"][0]["content"], response["data"]["usage"]['total_tokens']
|
return 200, str(response["data"]["choices"][0]["content"]).split('"')[1], response["data"]["usage"]['total_tokens']
|
||||||
else:
|
else:
|
||||||
return 50 , str(response["code"])+response["msg"], 0
|
return 50 , str(response["code"])+response["msg"], 0
|
||||||
|
28
src/Server/gpt35Turbo.py
Normal file
28
src/Server/gpt35Turbo.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import openai , config
|
||||||
|
|
||||||
|
openai.api_key = config.readConf()["gpt3.5turbo"]["Authorization"]
|
||||||
|
openai.base_url = config.readConf()["gpt3.5turbo"]["url"]
|
||||||
|
|
||||||
|
def service(prompt,history = ""):
|
||||||
|
if history == "":
|
||||||
|
response = openai.chat.completions.create(
|
||||||
|
model="gpt-3.5-turbo",
|
||||||
|
messages=[
|
||||||
|
{"role": "user", "content": prompt},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
response = openai.chat.completions.create(
|
||||||
|
model="gpt-3.5-turbo",
|
||||||
|
messages=[
|
||||||
|
{"role": "user", "content": history[1]["user"]},
|
||||||
|
{"role": "assistant", "content": history[1]["bot"]},
|
||||||
|
{"role": "user", "content": history[0]["user"]},
|
||||||
|
{"role": "assistant", "content": history[0]["bot"]},
|
||||||
|
{"role": "user", "content": prompt},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
if response.choices[0].finish_reason == "stop":
|
||||||
|
return 200, response.choices[0].message.content, int(response.usage.total_tokens*3) #三倍tokens消耗
|
||||||
|
else:
|
||||||
|
return 50 , "API Error!", 0
|
@ -1,6 +1,6 @@
|
|||||||
import flask , requests , json
|
import flask , requests , json
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
import db , qwenTurbo ,chatglmTurbo
|
import db , qwenTurbo , chatglmTurbo , gpt35Turbo
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -36,6 +36,12 @@ def post_data():
|
|||||||
elif userRequest["context"] == 0:
|
elif userRequest["context"] == 0:
|
||||||
code , output , tokenUsed = chatglmTurbo.service(userRequest['prompt'])
|
code , output , tokenUsed = chatglmTurbo.service(userRequest['prompt'])
|
||||||
|
|
||||||
|
if userRequest["model"] == "gpt3.5-turbo": # 调用gpt3.5-turbo
|
||||||
|
if userRequest["context"] == 1: # 是否使用上文关联
|
||||||
|
code , output , tokenUsed = gpt35Turbo.service(userRequest['prompt'],userRequest['history'])
|
||||||
|
elif userRequest["context"] == 0:
|
||||||
|
code , output , tokenUsed = gpt35Turbo.service(userRequest['prompt'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,6 +93,7 @@
|
|||||||
<input type="text" id="user-input" placeholder="输入消息..."> <!-- 用户输入消息的输入框 -->
|
<input type="text" id="user-input" placeholder="输入消息..."> <!-- 用户输入消息的输入框 -->
|
||||||
<button id="user-input-button" disabled>发送</button> <!-- 发送消息按钮初始状态禁用 -->
|
<button id="user-input-button" disabled>发送</button> <!-- 发送消息按钮初始状态禁用 -->
|
||||||
<!-- 新增复选框、文本和附加功能按钮 -->
|
<!-- 新增复选框、文本和附加功能按钮 -->
|
||||||
|
<img id="loadingico" alt="Loading..." src="https://www.intogif.com/resource/image/loading/radio.gif" style="height: 50px;transform: translate(10px, 20px);display: none;"/>
|
||||||
<div id="additional-controls">
|
<div id="additional-controls">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" id="additional-checkbox"> 联系上文 <a id="showtoken"><br>剩余Token将会被显示在这里</a>
|
<input type="checkbox" id="additional-checkbox"> 联系上文 <a id="showtoken"><br>剩余Token将会被显示在这里</a>
|
||||||
@ -106,9 +107,10 @@
|
|||||||
<button id="close-popup">关闭</button>
|
<button id="close-popup">关闭</button>
|
||||||
<h1>设置</h1>
|
<h1>设置</h1>
|
||||||
<p>使用的AI模型</p>
|
<p>使用的AI模型</p>
|
||||||
<select id="setUpDropdown" defaultValue="qwen-turbo">
|
<select id="setUpDropdown" defaultValue="qwen-turbo" onchange="setCookie('modelSet', document.getElementById('setUpDropdown').value, 265)">
|
||||||
<option value="qwen-turbo">qwen-turbo</option>
|
<option value="qwen-turbo">qwen-turbo</option>
|
||||||
<option value="chatglm-turbo">chatglmTurbo</option>
|
<option value="chatglm-turbo">chatglmTurbo</option>
|
||||||
|
<option value="gpt3.5-turbo">gpt3.5-turbo(X3 Token)</option>
|
||||||
</select>
|
</select>
|
||||||
<hr>
|
<hr>
|
||||||
<h3>当前UserKey</h3>
|
<h3>当前UserKey</h3>
|
||||||
@ -153,6 +155,7 @@
|
|||||||
|
|
||||||
// 发送消息函数
|
// 发送消息函数
|
||||||
function sendMessage() {
|
function sendMessage() {
|
||||||
|
document.getElementById("loadingico").style.display = "";
|
||||||
const userMessage = userInput.value; // 获取用户输入的消息
|
const userMessage = userInput.value; // 获取用户输入的消息
|
||||||
appendMessage('你', userMessage); // 在聊天界面中添加用户消息
|
appendMessage('你', userMessage); // 在聊天界面中添加用户消息
|
||||||
userInput.value = ''; // 清空输入框
|
userInput.value = ''; // 清空输入框
|
||||||
@ -213,11 +216,13 @@
|
|||||||
if (user != "") {
|
if (user != "") {
|
||||||
alert("欢迎回来 UserKey:" + user);
|
alert("欢迎回来 UserKey:" + user);
|
||||||
document.getElementById("showUserKey").innerHTML = user;
|
document.getElementById("showUserKey").innerHTML = user;
|
||||||
|
document.getElementById('setUpDropdown').value = getCookie("modelSet");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
user = prompt("请输入你的Userkey:", "");
|
user = prompt("请输入你的Userkey:", "");
|
||||||
if (user != "" && user != null) {
|
if (user != "" && user != null) {
|
||||||
setCookie("userkey", user, 265);
|
setCookie("userkey", user, 265);
|
||||||
|
setCookie('modelSet', document.getElementById('setUpDropdown').value, 265);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,10 +278,12 @@
|
|||||||
userhs0 = message;
|
userhs0 = message;
|
||||||
boths0 = data["output"];
|
boths0 = data["output"];
|
||||||
loading = false;
|
loading = false;
|
||||||
|
document.getElementById("loadingico").style.display = "none";
|
||||||
// 可以根据返回的数据执行相应的操作
|
// 可以根据返回的数据执行相应的操作
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('请求出错:', error);
|
console.error('请求出错:', error);
|
||||||
|
alert('请求出错:', error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user