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

Mon Jan 15 11:58:00 CST 2024 inscode

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