feat: add metering data
This commit is contained in:
parent
f617a05483
commit
6d79d42925
@ -55,6 +55,8 @@ export const useMessageOption = () => {
|
|||||||
const {
|
const {
|
||||||
history,
|
history,
|
||||||
setHistory,
|
setHistory,
|
||||||
|
chatMessages,
|
||||||
|
setChatMessages,
|
||||||
setStreaming,
|
setStreaming,
|
||||||
streaming,
|
streaming,
|
||||||
setIsFirstMessage,
|
setIsFirstMessage,
|
||||||
@ -166,7 +168,6 @@ export const useMessageOption = () => {
|
|||||||
useMlock:
|
useMlock:
|
||||||
currentChatModelSettings?.useMlock ?? userDefaultModelSettings?.useMlock
|
currentChatModelSettings?.useMlock ?? userDefaultModelSettings?.useMlock
|
||||||
})
|
})
|
||||||
|
|
||||||
let newMessage: Message[] = []
|
let newMessage: Message[] = []
|
||||||
let generateMessageId = generateID()
|
let generateMessageId = generateID()
|
||||||
|
|
||||||
@ -285,16 +286,19 @@ export const useMessageOption = () => {
|
|||||||
const response = await ollama.invoke(promptForQuestion)
|
const response = await ollama.invoke(promptForQuestion)
|
||||||
let res = response.content.toString()
|
let res = response.content.toString()
|
||||||
res = removeReasoning(res)
|
res = removeReasoning(res)
|
||||||
keywords = res.replace(/^Keywords:/i, '').split(', ').map(k => k.trim())
|
keywords = res
|
||||||
|
.replace(/^Keywords:/i, "")
|
||||||
|
.split(", ")
|
||||||
|
.map((k) => k.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
const { prompt, webSources, iodSources } = await getSystemPromptForWeb(
|
const { prompt, webSources, iodSources } = await getSystemPromptForWeb(
|
||||||
query,
|
query,
|
||||||
keywords,
|
keywords,
|
||||||
webSearch,
|
webSearch,
|
||||||
iodSearch,
|
iodSearch
|
||||||
)
|
)
|
||||||
console.log("prompt:\n"+prompt);
|
console.log("prompt:\n" + prompt)
|
||||||
setIsSearchingInternet(false)
|
setIsSearchingInternet(false)
|
||||||
|
|
||||||
// message = message.trim().replaceAll("\n", " ")
|
// message = message.trim().replaceAll("\n", " ")
|
||||||
@ -455,6 +459,24 @@ export const useMessageOption = () => {
|
|||||||
|
|
||||||
setIsProcessing(false)
|
setIsProcessing(false)
|
||||||
setStreaming(false)
|
setStreaming(false)
|
||||||
|
|
||||||
|
setChatMessages([
|
||||||
|
...chatMessages,
|
||||||
|
{
|
||||||
|
id: generateMessageId,
|
||||||
|
query: message,
|
||||||
|
prompt: prompt,
|
||||||
|
thinkingChain: "",
|
||||||
|
answer: fullText,
|
||||||
|
relatedDataCount: count,
|
||||||
|
iodInputToken: "",
|
||||||
|
iodOutputToken: "",
|
||||||
|
modelInputToken: "",
|
||||||
|
modelOutputToken: "",
|
||||||
|
date: reasoningStartTime,
|
||||||
|
timeTaken: timetaken
|
||||||
|
}
|
||||||
|
])
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const errorSave = await saveMessageOnError({
|
const errorSave = await saveMessageOnError({
|
||||||
e,
|
e,
|
||||||
|
@ -26,15 +26,43 @@ export type Message = {
|
|||||||
export type ChatHistory = {
|
export type ChatHistory = {
|
||||||
role: "user" | "assistant" | "system"
|
role: "user" | "assistant" | "system"
|
||||||
content: string
|
content: string
|
||||||
image?: string,
|
image?: string
|
||||||
messageType?: string
|
messageType?: string
|
||||||
}[]
|
}[]
|
||||||
|
|
||||||
|
export type ChatMessage = {
|
||||||
|
id: string
|
||||||
|
// 问题
|
||||||
|
query: string
|
||||||
|
// 提示词全文
|
||||||
|
prompt: string
|
||||||
|
// 思维链(只有深度思考时有)
|
||||||
|
thinkingChain?: string
|
||||||
|
// 回答
|
||||||
|
answer: string
|
||||||
|
// 关联数据个数
|
||||||
|
relatedDataCount: number
|
||||||
|
// 数联网输入token
|
||||||
|
iodInputToken: string
|
||||||
|
// 数联网输出token
|
||||||
|
iodOutputToken: string
|
||||||
|
// 大模型输入token
|
||||||
|
modelInputToken: string
|
||||||
|
// 大模型输出token
|
||||||
|
modelOutputToken: string
|
||||||
|
// 日期
|
||||||
|
date: Date
|
||||||
|
// 耗时
|
||||||
|
timeTaken: number
|
||||||
|
}[]
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
messages: Message[]
|
messages: Message[]
|
||||||
setMessages: (messages: Message[]) => void
|
setMessages: (messages: Message[]) => void
|
||||||
history: ChatHistory
|
history: ChatHistory
|
||||||
setHistory: (history: ChatHistory) => void
|
setHistory: (history: ChatHistory) => void
|
||||||
|
chatMessages: ChatMessage
|
||||||
|
setChatMessages: (chatMessages: ChatMessage) => void
|
||||||
streaming: boolean
|
streaming: boolean
|
||||||
setStreaming: (streaming: boolean) => void
|
setStreaming: (streaming: boolean) => void
|
||||||
isFirstMessage: boolean
|
isFirstMessage: boolean
|
||||||
@ -82,6 +110,8 @@ export const useStoreMessageOption = create<State>((set) => ({
|
|||||||
setMessages: (messages) => set({ messages }),
|
setMessages: (messages) => set({ messages }),
|
||||||
history: [],
|
history: [],
|
||||||
setHistory: (history) => set({ history }),
|
setHistory: (history) => set({ history }),
|
||||||
|
chatMessages: [],
|
||||||
|
setChatMessages: (chatMessages) => set({ chatMessages }),
|
||||||
streaming: false,
|
streaming: false,
|
||||||
setStreaming: (streaming) => set({ streaming }),
|
setStreaming: (streaming) => set({ streaming }),
|
||||||
isFirstMessage: true,
|
isFirstMessage: true,
|
||||||
@ -120,5 +150,5 @@ export const useStoreMessageOption = create<State>((set) => ({
|
|||||||
setTemporaryChat: (temporaryChat) => set({ temporaryChat }),
|
setTemporaryChat: (temporaryChat) => set({ temporaryChat }),
|
||||||
|
|
||||||
useOCR: false,
|
useOCR: false,
|
||||||
setUseOCR: (useOCR) => set({ useOCR }),
|
setUseOCR: (useOCR) => set({ useOCR })
|
||||||
}))
|
}))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user