提交 053ec8ab 编写于 作者: W weixin_44463441

Mon Jan 15 11:58:00 CST 2024 inscode

上级 bb063a43
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
<textarea class="my-2 w-full bg-gray-100 h-32 max-h-64 border-gray-300 text-slate-600 text-sm" v-model="item.content" maxLength="512"></textarea> <textarea class="my-2 w-full bg-gray-100 h-32 max-h-64 border-gray-300 text-slate-600 text-sm" v-model="item.content" maxLength="512"></textarea>
</td> </td>
<td class="*:py-1 *:px-4 *:rounded-md *:mr-2 *:text-gray-100 w-[160px]"> <td class="*:py-1 *:px-4 *:rounded-md *:mr-2 *:text-gray-100 w-[160px]">
<button @click="deleteItem(item)" class="bg-orange-800 hover:bg-orange-900 sm:inline"> 删除</button> <button @click="deleteItem(item)" class="bg-orange-800 hover:bg-orange-900 sm:inline"> 删除</button>
<button @click="updateItem(item)" class="bg-slate-700 hover:bg-slate-800"> 更新</button> <button @click="updateItem(item)" class="bg-slate-700 hover:bg-slate-800"> 更新</button>
</td> </td>
......
...@@ -9,8 +9,6 @@ const prompt_template = ` ...@@ -9,8 +9,6 @@ const prompt_template = `
以下为用户后续问题相关的内容: 以下为用户后续问题相关的内容:
{context} {context}
请根据以上相关信息,回答用户问题。
` `
// 欢迎语,用户打开时自动发送给用户 // 欢迎语,用户打开时自动发送给用户
...@@ -46,7 +44,7 @@ export default { ...@@ -46,7 +44,7 @@ export default {
"default_prompt": default_prompt, "default_prompt": default_prompt,
"max_request_len": "2048", "max_request_len": "2048",
"prompt_template": prompt_template, "prompt_template": prompt_template,
"api_prompt_prefix":"结合上下文回答问题,如果问题不是技术问题,请直接回答不知道\n问题为:", "api_prompt_prefix":"结合上下文回答问题。\n问题为:",
"show_profile_setting":false, "show_profile_setting":false,
"index_url": index_url, "index_url": index_url,
......
...@@ -31,23 +31,28 @@ class InsCodeAI { ...@@ -31,23 +31,28 @@ class InsCodeAI {
const model = config?.model??'vicuna-13b-all-v1.1' const model = config?.model??'vicuna-13b-all-v1.1'
const temperature = this.temperature??0.1 const temperature = this.temperature??0.1
const top_p = config?.top_p??1.0 const top_p = config?.top_p??1.0
const prefix = config?.prompt_prefix??''
let stop_key = config?.stop_key??null let stop_key = config?.stop_key??null
if (stop_key !== null && stop_key !== '') { if (stop_key !== null && stop_key !== '') {
stop_key = stop_key.split(';;') stop_key = stop_key.split(';;')
} }
const data = { const data = {
model: model, // model: model,
max_tokens: parseInt(max_tokens), max_tokens: parseInt(max_tokens),
temperature: parseFloat(temperature), temperature: parseFloat(temperature),
top_p: parseFloat(top_p), top_p: parseFloat(top_p),
stream: true, stream: true,
stop: stop_key, stop: stop_key,
apikey: apiKey, apikey: apiKey,
// prefix: prefix bizParam: {
support: "ai"
},
prefix: prefix
} }
if (mode === 'chat') { if (mode === 'chat') {
data.messages = Prompt.getPromptByChatMode(config, context, history)
data.messages = JSON.stringify(Prompt.getPromptByChatMode(config, context, history))
} else { } else {
data.prompt = Prompt.getPromptByTemplate(config, context, prompt) data.prompt = Prompt.getPromptByTemplate(config, context, prompt)
} }
...@@ -56,6 +61,7 @@ class InsCodeAI { ...@@ -56,6 +61,7 @@ class InsCodeAI {
method: 'POST', method: 'POST',
signal: signal, signal: signal,
headers: { headers: {
'accept': 'text/event-stream',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify(data), body: JSON.stringify(data),
...@@ -63,7 +69,12 @@ class InsCodeAI { ...@@ -63,7 +69,12 @@ class InsCodeAI {
// if the server emits an error message, throw an exception // if the server emits an error message, throw an exception
// so it gets handled by the onerror callback below: // so it gets handled by the onerror callback below:
if (msg && msg?.data) { if (msg && msg?.data) {
if (msg?.data === stop) { const aiResult = decodeURIComponent(msg?.data??'')
// console.info(aiResult)
if (aiResult === stop) {
if (callback?.onclose) { if (callback?.onclose) {
callback?.onclose() callback?.onclose()
} }
...@@ -72,7 +83,6 @@ class InsCodeAI { ...@@ -72,7 +83,6 @@ class InsCodeAI {
} else { } else {
// console.info(msg.data) // console.info(msg.data)
const jsonData = JSON.parse(msg.data)
// 和上面重复触发,只留一个 // 和上面重复触发,只留一个
// if (jsonData.choices[0].finish_reason === 'stop') { // if (jsonData.choices[0].finish_reason === 'stop') {
...@@ -81,20 +91,20 @@ class InsCodeAI { ...@@ -81,20 +91,20 @@ class InsCodeAI {
// } // }
// return // return
// } // }
let message = null // let message = msg?.data??''
if (mode === 'chat') { // if (mode === 'chat') {
message = jsonData?.choices[0]?.message?.content // message = jsonData?.choices[0]?.message?.content
if (typeof message === 'undefined') { // if (typeof message === 'undefined') {
message = jsonData?.choices[0]?.delta?.content // message = jsonData?.choices[0]?.delta?.content
} // }
if (typeof message === 'undefined') { // if (typeof message === 'undefined') {
message = '' // message = ''
} // }
} else { // } else {
message = jsonData?.choices[0]?.text // message = jsonData?.choices[0]?.text
} // }
callback?.onmessage(message, true) callback?.onmessage(aiResult, false)
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册