Merge branch 'feat/metering' of gitea.internetapi.cn:iod/page-assist into feat/page
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
||||
promptForRag,
|
||||
systemPromptForNonRagOption
|
||||
} from "~/services/ollama"
|
||||
import { type ChatHistory, type Message } from "~/store/option"
|
||||
import { type ChatHistory, ChatMessage, type Message } from "~/store/option"
|
||||
import { SystemMessage } from "@langchain/core/messages"
|
||||
import { useStoreMessageOption } from "~/store/option"
|
||||
import {
|
||||
@@ -114,6 +114,26 @@ export const useMessageOption = () => {
|
||||
setWebSearch(true)
|
||||
}
|
||||
}
|
||||
// 从最后的结果中解析出 思维链 和 结果
|
||||
const responseResolver = (msg: string) => {
|
||||
const thinkStart = msg.indexOf("<think>")
|
||||
const thinkEnd = msg.indexOf("</think>")
|
||||
let think = ""
|
||||
let content = ""
|
||||
if (thinkStart > -1 && thinkEnd > -1) {
|
||||
think = msg.substring(thinkStart + 7, thinkEnd)
|
||||
content = msg.substring(thinkEnd + 8)
|
||||
} else {
|
||||
content = msg
|
||||
}
|
||||
// 去掉换行符
|
||||
think = think.replace(/\n/g, "")
|
||||
content = content.replace(/\n/g, "")
|
||||
return {
|
||||
think,
|
||||
content
|
||||
}
|
||||
}
|
||||
|
||||
const searchChatMode = async (
|
||||
webSearch: boolean,
|
||||
@@ -170,6 +190,10 @@ export const useMessageOption = () => {
|
||||
})
|
||||
let newMessage: Message[] = []
|
||||
let generateMessageId = generateID()
|
||||
const chatMessage: ChatMessage = {
|
||||
id: generateMessageId,
|
||||
queryContent: message
|
||||
} as ChatMessage
|
||||
|
||||
if (!isRegenerate) {
|
||||
newMessage = [
|
||||
@@ -300,6 +324,7 @@ export const useMessageOption = () => {
|
||||
)
|
||||
console.log("prompt:\n" + prompt)
|
||||
setIsSearchingInternet(false)
|
||||
chatMessage.prompt = prompt
|
||||
|
||||
// message = message.trim().replaceAll("\n", " ")
|
||||
|
||||
@@ -460,23 +485,13 @@ export const useMessageOption = () => {
|
||||
setIsProcessing(false)
|
||||
setStreaming(false)
|
||||
|
||||
setChatMessages([
|
||||
...chatMessages,
|
||||
{
|
||||
id: generateMessageId,
|
||||
query: message,
|
||||
prompt: prompt,
|
||||
thinkingChain: "",
|
||||
answer: fullText,
|
||||
relatedDataCount: count,
|
||||
iodInputToken: "",
|
||||
iodOutputToken: "",
|
||||
modelInputToken: "",
|
||||
modelOutputToken: "",
|
||||
date: reasoningStartTime,
|
||||
timeTaken: timetaken
|
||||
}
|
||||
])
|
||||
chatMessage.relatedDataCount = keywords.length
|
||||
chatMessage.timeTaken = timetaken
|
||||
chatMessage.date = reasoningStartTime
|
||||
const { think, content } = responseResolver(fullText)
|
||||
chatMessage.thinkingChain = think
|
||||
chatMessage.responseContent = content
|
||||
setChatMessages([...chatMessages, chatMessage])
|
||||
} catch (e) {
|
||||
const errorSave = await saveMessageOnError({
|
||||
e,
|
||||
|
||||
Reference in New Issue
Block a user