feat: add IoD search
This commit is contained in:
@@ -59,6 +59,8 @@ export const useMessage = () => {
|
||||
setIsSearchingInternet,
|
||||
webSearch,
|
||||
setWebSearch,
|
||||
iodSearch,
|
||||
setIodSearch,
|
||||
isSearchingInternet
|
||||
} = useStoreMessageOption()
|
||||
const [defaultInternetSearchOn] = useStorage("defaultInternetSearchOn", false)
|
||||
@@ -185,14 +187,16 @@ export const useMessage = () => {
|
||||
isBot: false,
|
||||
name: "You",
|
||||
message,
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
images: []
|
||||
},
|
||||
{
|
||||
isBot: true,
|
||||
name: selectedModel,
|
||||
message: "▋",
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
id: generateMessageId
|
||||
}
|
||||
]
|
||||
@@ -203,7 +207,8 @@ export const useMessage = () => {
|
||||
isBot: true,
|
||||
name: selectedModel,
|
||||
message: "▋",
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
id: generateMessageId
|
||||
}
|
||||
]
|
||||
@@ -334,7 +339,16 @@ export const useMessage = () => {
|
||||
}
|
||||
|
||||
let context: string = ""
|
||||
let source: {
|
||||
let webSources: {
|
||||
name: any
|
||||
type: any
|
||||
mode: string
|
||||
url: string
|
||||
pageContent: string
|
||||
metadata: Record<string, any>
|
||||
}[] = []
|
||||
// TODO: update type
|
||||
let iodSources: {
|
||||
name: any
|
||||
type: any
|
||||
mode: string
|
||||
@@ -346,7 +360,7 @@ export const useMessage = () => {
|
||||
if (chatWithWebsiteEmbedding) {
|
||||
const docs = await vectorstore.similaritySearch(query, 4)
|
||||
context = formatDocs(docs)
|
||||
source = docs.map((doc) => {
|
||||
webSources = docs.map((doc) => {
|
||||
return {
|
||||
...doc,
|
||||
name: doc?.metadata?.source || "untitled",
|
||||
@@ -365,7 +379,7 @@ export const useMessage = () => {
|
||||
.slice(0, maxWebsiteContext)
|
||||
}
|
||||
|
||||
source = [
|
||||
webSources = [
|
||||
{
|
||||
name: embedURL,
|
||||
type: type,
|
||||
@@ -476,7 +490,8 @@ export const useMessage = () => {
|
||||
return {
|
||||
...message,
|
||||
message: fullText,
|
||||
sources: source,
|
||||
webSources,
|
||||
iodSources,
|
||||
generationInfo,
|
||||
reasoning_time_taken: timetaken
|
||||
}
|
||||
@@ -506,7 +521,8 @@ export const useMessage = () => {
|
||||
message,
|
||||
image,
|
||||
fullText,
|
||||
source,
|
||||
webSources,
|
||||
iodSources,
|
||||
message_source: "copilot",
|
||||
generationInfo,
|
||||
reasoning_time_taken: timetaken
|
||||
@@ -606,14 +622,16 @@ export const useMessage = () => {
|
||||
isBot: false,
|
||||
name: "You",
|
||||
message,
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
images: []
|
||||
},
|
||||
{
|
||||
isBot: true,
|
||||
name: selectedModel,
|
||||
message: "▋",
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
id: generateMessageId
|
||||
}
|
||||
]
|
||||
@@ -624,7 +642,8 @@ export const useMessage = () => {
|
||||
isBot: true,
|
||||
name: selectedModel,
|
||||
message: "▋",
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
id: generateMessageId
|
||||
}
|
||||
]
|
||||
@@ -787,7 +806,8 @@ export const useMessage = () => {
|
||||
message,
|
||||
image,
|
||||
fullText,
|
||||
source: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
message_source: "copilot",
|
||||
generationInfo,
|
||||
reasoning_time_taken: timetaken
|
||||
@@ -891,14 +911,16 @@ export const useMessage = () => {
|
||||
isBot: false,
|
||||
name: "You",
|
||||
message,
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
images: [image]
|
||||
},
|
||||
{
|
||||
isBot: true,
|
||||
name: selectedModel,
|
||||
message: "▋",
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
id: generateMessageId
|
||||
}
|
||||
]
|
||||
@@ -909,7 +931,8 @@ export const useMessage = () => {
|
||||
isBot: true,
|
||||
name: selectedModel,
|
||||
message: "▋",
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
id: generateMessageId
|
||||
}
|
||||
]
|
||||
@@ -1077,7 +1100,8 @@ export const useMessage = () => {
|
||||
message,
|
||||
image,
|
||||
fullText,
|
||||
source: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
message_source: "copilot",
|
||||
generationInfo,
|
||||
reasoning_time_taken: timetaken
|
||||
@@ -1114,12 +1138,14 @@ export const useMessage = () => {
|
||||
}
|
||||
|
||||
const searchChatMode = async (
|
||||
webSearch: boolean,
|
||||
iodSearch,
|
||||
message: string,
|
||||
image: string,
|
||||
isRegenerate: boolean,
|
||||
messages: Message[],
|
||||
history: ChatHistory,
|
||||
signal: AbortSignal
|
||||
signal: AbortSignal,
|
||||
) => {
|
||||
const url = await getOllamaURL()
|
||||
setStreaming(true)
|
||||
@@ -1176,14 +1202,16 @@ export const useMessage = () => {
|
||||
isBot: false,
|
||||
name: "You",
|
||||
message,
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
images: [image]
|
||||
},
|
||||
{
|
||||
isBot: true,
|
||||
name: selectedModel,
|
||||
message: "▋",
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
id: generateMessageId
|
||||
}
|
||||
]
|
||||
@@ -1194,7 +1222,8 @@ export const useMessage = () => {
|
||||
isBot: true,
|
||||
name: selectedModel,
|
||||
message: "▋",
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
id: generateMessageId
|
||||
}
|
||||
]
|
||||
@@ -1271,7 +1300,8 @@ export const useMessage = () => {
|
||||
query = removeReasoning(query)
|
||||
}
|
||||
|
||||
const { prompt, source } = await getSystemPromptForWeb(query)
|
||||
const { prompt, webSources, iodSources } =
|
||||
await getSystemPromptForWeb(query, [], webSearch, iodSearch)
|
||||
setIsSearchingInternet(false)
|
||||
|
||||
// message = message.trim().replaceAll("\n", " ")
|
||||
@@ -1394,7 +1424,8 @@ export const useMessage = () => {
|
||||
return {
|
||||
...message,
|
||||
message: fullText,
|
||||
sources: source,
|
||||
webSources,
|
||||
iodSources,
|
||||
generationInfo,
|
||||
reasoning_time_taken: timetaken
|
||||
}
|
||||
@@ -1424,7 +1455,8 @@ export const useMessage = () => {
|
||||
message,
|
||||
image,
|
||||
fullText,
|
||||
source,
|
||||
webSources,
|
||||
iodSources,
|
||||
generationInfo,
|
||||
reasoning_time_taken: timetaken
|
||||
})
|
||||
@@ -1523,7 +1555,8 @@ export const useMessage = () => {
|
||||
isBot: false,
|
||||
name: "You",
|
||||
message,
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
images: [image],
|
||||
messageType: messageType
|
||||
},
|
||||
@@ -1531,7 +1564,8 @@ export const useMessage = () => {
|
||||
isBot: true,
|
||||
name: selectedModel,
|
||||
message: "▋",
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
id: generateMessageId
|
||||
}
|
||||
]
|
||||
@@ -1542,7 +1576,8 @@ export const useMessage = () => {
|
||||
isBot: true,
|
||||
name: selectedModel,
|
||||
message: "▋",
|
||||
sources: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
id: generateMessageId
|
||||
}
|
||||
]
|
||||
@@ -1688,7 +1723,8 @@ export const useMessage = () => {
|
||||
message,
|
||||
image,
|
||||
fullText,
|
||||
source: [],
|
||||
webSources: [],
|
||||
iodSources: [],
|
||||
message_source: "copilot",
|
||||
message_type: messageType,
|
||||
generationInfo,
|
||||
@@ -1766,14 +1802,16 @@ export const useMessage = () => {
|
||||
)
|
||||
} else {
|
||||
if (chatMode === "normal") {
|
||||
if (webSearch) {
|
||||
if (webSearch || iodSearch) {
|
||||
await searchChatMode(
|
||||
webSearch,
|
||||
iodSearch,
|
||||
message,
|
||||
image,
|
||||
isRegenerate || false,
|
||||
messages,
|
||||
memory || history,
|
||||
signal
|
||||
signal,
|
||||
)
|
||||
} else {
|
||||
await normalChatMode(
|
||||
@@ -1906,6 +1944,8 @@ export const useMessage = () => {
|
||||
regenerateLastMessage,
|
||||
webSearch,
|
||||
setWebSearch,
|
||||
iodSearch,
|
||||
setIodSearch,
|
||||
isSearchingInternet,
|
||||
selectedQuickPrompt,
|
||||
setSelectedQuickPrompt,
|
||||
|
||||
Reference in New Issue
Block a user