feat: improve DEFAULT_WEBSEARCH_PROMPT for IoD and 3W citations
This commit is contained in:
@@ -9,6 +9,7 @@ import { searxngSearch } from "./search-engines/searxng"
|
||||
import { braveAPISearch } from "./search-engines/brave-api"
|
||||
import { webBaiduSearch } from "./search-engines/baidu"
|
||||
import { searchIod } from "./iod"
|
||||
import type { WebSearchResult } from "~/types/web"
|
||||
import type { IodRegistryEntry } from "~/types/iod"
|
||||
|
||||
const getHostName = (url: string) => {
|
||||
@@ -20,23 +21,35 @@ const getHostName = (url: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const searchWeb = (provider: string, query: string) => {
|
||||
async function searchWeb(
|
||||
provider: string,
|
||||
query: string
|
||||
): Promise<WebSearchResult[]> {
|
||||
let results = []
|
||||
switch (provider) {
|
||||
case "duckduckgo":
|
||||
return webDuckDuckGoSearch(query)
|
||||
results = await webDuckDuckGoSearch(query)
|
||||
break
|
||||
case "sogou":
|
||||
return webSogouSearch(query)
|
||||
results = await webSogouSearch(query)
|
||||
break
|
||||
case "brave":
|
||||
return webBraveSearch(query)
|
||||
results = await webBraveSearch(query)
|
||||
break
|
||||
case "searxng":
|
||||
return searxngSearch(query)
|
||||
results = await searxngSearch(query)
|
||||
break
|
||||
case "brave-api":
|
||||
return braveAPISearch(query)
|
||||
results = await braveAPISearch(query)
|
||||
break
|
||||
case "baidu":
|
||||
return webBaiduSearch(query)
|
||||
results = await webBaiduSearch(query)
|
||||
break
|
||||
default:
|
||||
return webGoogleSearch(query)
|
||||
results = await webGoogleSearch(query)
|
||||
break
|
||||
}
|
||||
return results.map((r) => ({ ...r, name: getHostName(r.url) }))
|
||||
}
|
||||
|
||||
export const getSystemPromptForWeb = async (
|
||||
@@ -47,10 +60,7 @@ export const getSystemPromptForWeb = async (
|
||||
) => {
|
||||
try {
|
||||
const websiteVisit = getWebsiteFromQuery(query)
|
||||
let webSearchResults: {
|
||||
url: any
|
||||
content: string
|
||||
}[] = []
|
||||
let webSearchResults: WebSearchResult[] = []
|
||||
// let search_results_web = ""
|
||||
|
||||
if (webSearch) {
|
||||
@@ -87,28 +97,25 @@ export const getSystemPromptForWeb = async (
|
||||
}
|
||||
const iod_search_results = iodSearchResults
|
||||
.map((res) => ({
|
||||
url: `${res.url}`,
|
||||
doId: res.doId,
|
||||
name: res.name,
|
||||
url: res.url,
|
||||
content: res.content || res.description
|
||||
}))
|
||||
.map(
|
||||
(result, idx) =>
|
||||
`<result source="${result.url}" id="${idx}">${result.content}</result>`
|
||||
`<result doId="${result.doId}" name="${result.name}" source="${result.url}" id="${idx + 1}">${result.content}</result>`
|
||||
)
|
||||
.join("\n")
|
||||
console.log("iod_search_result:" + iod_search_results)
|
||||
console.log("iod_search_result: " + iod_search_results)
|
||||
|
||||
const web_search_results = webSearchResults
|
||||
.map(
|
||||
(result, idx) =>
|
||||
`<result source="${result.url}" id="${idx}">${result.content}</result>`
|
||||
`<result source="${result.url}" name="${result.name}" id="${idx + 1}">${result.content}</result>`
|
||||
)
|
||||
.join("\n")
|
||||
const search_results =
|
||||
(iodSearch
|
||||
? "<数联网搜索结果>" + iod_search_results + "</数联网搜索结果>"
|
||||
: "") +
|
||||
(webSearch
|
||||
? "<万维网搜索结果>" + web_search_results + "</万维网搜索结果>"
|
||||
: "")
|
||||
console.log("web_search_result: " + web_search_results)
|
||||
|
||||
const current_date_time = new Date().toLocaleString()
|
||||
|
||||
@@ -116,14 +123,15 @@ export const getSystemPromptForWeb = async (
|
||||
|
||||
const prompt = system
|
||||
.replace("{current_date_time}", current_date_time)
|
||||
.replace("{search_results}", search_results)
|
||||
.replace("{iod_search_results}", iod_search_results)
|
||||
.replace("{web_search_results}", web_search_results)
|
||||
|
||||
return {
|
||||
prompt,
|
||||
webSources: webSearchResults.map((result) => {
|
||||
return {
|
||||
url: result.url,
|
||||
name: getHostName(result.url),
|
||||
name: result.name,
|
||||
type: "url"
|
||||
}
|
||||
}),
|
||||
@@ -133,7 +141,8 @@ export const getSystemPromptForWeb = async (
|
||||
console.error(e)
|
||||
return {
|
||||
prompt: "",
|
||||
source: []
|
||||
webSources: [],
|
||||
iodSources: []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user