Skip to content

Commit 51b30d6

Browse files
committed
vicuna support history
1 parent 922e7b0 commit 51b30d6

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

Vicuna_7b.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,33 @@ def getAnswerFromVicuna7b(context):
1818
return '算力不足,请稍候再试![stop]'
1919

2020

21-
def getAnswerFromVicuna7b_v2(context):
21+
def getAnswerFromVicuna7b_v2(contextx):
2222
url = 'http://172.16.62.137:8000/v1/chat/completions/stream'
23-
data = json.dumps(
24-
{"model": "vicuna-7b-v1.1",
25-
"messages": [{"role": "user", "content": context}]}
26-
)
23+
messages = []
24+
prompt = contextx["prompt"]
25+
for i in range(len(contextx["history"])):
26+
messages.append({"role": "user", "content": contextx["history"][i][0]})
27+
messages.append(
28+
{"role": "assistant", "content": contextx["history"][i][1]})
29+
messages.append({"role": "user", "content": prompt})
30+
data_json = {"model": "vicuna-7b-v1.1",
31+
"messages": messages}
32+
data = json.dumps(data_json)
2733
headers = {'content-type': 'application/json;charset=utf-8'}
2834
r = requests.post(url, data=data, headers=headers)
2935
res = r.json()
36+
history = []
37+
history_json = res["history"]
38+
his = None
39+
for h in history_json:
40+
if his is None:
41+
his = [h["content"]]
42+
elif len(his) == 1:
43+
his.append(h["content"])
44+
history.append(his)
45+
his = None
3046
now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
3147
if r.status_code == 200:
32-
return {'response': res['response'], 'history': [], 'status': 200, 'time': now}
48+
return {'response': res['response'], 'history': history, 'status': 200, 'time': now}
3349
else:
3450
return {'response': '算力不足,请稍候再试![stop]', 'history': [], 'status': 200, 'time': now}

chat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aiitchat",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"private": true,
55
"dependencies": {
66
"@chatui/core": "^2.4.2",

chat/src/App.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import '@chatui/core/es/styles/index.less';
55
import React, { useEffect, useState } from 'react';
66
import './chatui-theme.css';
77
import { marked } from "marked";
8-
import QRCode from 'react-qr-code'
8+
import QRCode from 'react-qr-code';
9+
import packageJson from '../package.json';
910

1011
var modelname = "ChatGLM-6b";
1112
var lastPrompt = "";
@@ -44,6 +45,7 @@ function App() {
4445
const [percentage, setPercentage] = useState(0);
4546
const msgRef = React.useRef(null);
4647
const [showQRCode, setShowQRCode] = useState(false)
48+
const [version, setVersion] = useState("");
4749

4850
function handleSend(type, val) {
4951
if (percentage > 0) {
@@ -119,7 +121,7 @@ function App() {
119121
}
120122
let xhr = new XMLHttpRequest();
121123
xhr.open('post', 'https://gitclone.com/aiit/codegen_stream/v2');
122-
//xhr.open('post', 'http://localhost:5000/codegen_stream/v2');
124+
//xhr.open('post', 'http://localhost:5001/codegen_stream/v2');
123125
xhr.setRequestHeader('Content-Type', 'application/json');
124126
xhr.onload = function () {
125127
var json = JSON.parse(xhr.response);
@@ -208,17 +210,20 @@ function App() {
208210
}
209211

210212
function openQRCode() {
211-
setShowQRCode(true)
213+
setVersion(packageJson.name + ' ' + packageJson.version);
214+
setShowQRCode(true);
212215
}
213216

214217
useEffect(() => {
215-
if(showQRCode){
216-
return ;
217-
}
218218
var oUl = document.getElementById('root');
219219
var aBox = getByClass(oUl, 'Input Input--outline Composer-input');
220220
if (aBox.length > 0) {
221-
aBox[0].focus();
221+
if (showQRCode) {
222+
aBox[0].blur();
223+
}
224+
else {
225+
aBox[0].focus();
226+
}
222227
}
223228
})
224229

@@ -256,6 +261,8 @@ function App() {
256261
<div className="qr-code-content">
257262
<QRCode value="https://gitclone.com/aiit/chat/" />
258263
<div style={{ textAlign: 'center', marginTop: '10px' }}>
264+
<div>{version}</div>
265+
<p></p>
259266
<button onClick={() => setShowQRCode(false)}>关闭</button>
260267
</div>
261268
</div>

codegen_stream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ async def codegen_stream_v2(request):
102102
time.localtime()), "request : " + prompt)
103103
stop = False
104104
if modelname == 'vicuna-7b':
105-
result = getAnswerFromVicuna7b_v2(prompt)
105+
result = getAnswerFromVicuna7b_v2(context)
106106
else:
107107
result = getAnswerFromChatGLM6b_v2(context)
108108
stop = result["response"] .endswith("[stop]")

0 commit comments

Comments
 (0)