2024-03-23 14:44:05 +05:30
|
|
|
import { getWebSearchPrompt } from "~/services/ollama"
|
2024-04-28 00:36:33 +05:30
|
|
|
import { webGoogleSearch } from "./search-engines/google"
|
|
|
|
|
import { webDuckDuckGoSearch } from "./search-engines/duckduckgo"
|
feat: Add localization support for visitSpecificWebsite label
This commit adds localization support for the "visitSpecificWebsite" label in the settings.json file for multiple languages. Now, the label can be translated into different languages, including Japanese, Chinese, English, Malayalam, Italian, Portuguese, Russian, French, and Spanish.
2024-06-22 16:55:02 +05:30
|
|
|
import { getIsVisitSpecificWebsite, getSearchProvider } from "@/services/search"
|
2024-04-28 00:36:33 +05:30
|
|
|
import { webSogouSearch } from "./search-engines/sogou"
|
2024-05-24 00:22:24 +05:30
|
|
|
import { webBraveSearch } from "./search-engines/brave"
|
2024-06-22 00:25:12 +05:30
|
|
|
import { getWebsiteFromQuery, processSingleWebsite } from "./website"
|
2024-12-01 00:23:17 +05:30
|
|
|
import { searxngSearch } from "./search-engines/searxng"
|
2024-12-13 20:03:52 +05:30
|
|
|
import { braveAPISearch } from "./search-engines/brave-api"
|
2025-02-01 11:22:12 +05:30
|
|
|
import { webBaiduSearch } from "./search-engines/baidu"
|
2024-02-25 18:44:47 +05:30
|
|
|
|
2024-03-16 14:28:32 +05:30
|
|
|
const getHostName = (url: string) => {
|
2024-03-31 15:57:56 +05:30
|
|
|
try {
|
|
|
|
|
const hostname = new URL(url).hostname
|
|
|
|
|
return hostname
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const searchWeb = (provider: string, query: string) => {
|
|
|
|
|
switch (provider) {
|
|
|
|
|
case "duckduckgo":
|
|
|
|
|
return webDuckDuckGoSearch(query)
|
2024-04-28 00:36:33 +05:30
|
|
|
case "sogou":
|
|
|
|
|
return webSogouSearch(query)
|
2024-05-24 00:22:24 +05:30
|
|
|
case "brave":
|
|
|
|
|
return webBraveSearch(query)
|
2024-12-01 00:23:17 +05:30
|
|
|
case "searxng":
|
|
|
|
|
return searxngSearch(query)
|
2024-12-13 20:03:52 +05:30
|
|
|
case "brave-api":
|
|
|
|
|
return braveAPISearch(query)
|
2025-02-01 11:22:12 +05:30
|
|
|
case "baidu":
|
|
|
|
|
return webBaiduSearch(query)
|
2024-03-31 15:57:56 +05:30
|
|
|
default:
|
|
|
|
|
return webGoogleSearch(query)
|
|
|
|
|
}
|
2024-03-16 14:28:32 +05:30
|
|
|
}
|
|
|
|
|
|
2024-02-25 18:44:47 +05:30
|
|
|
export const getSystemPromptForWeb = async (query: string) => {
|
2024-03-31 15:57:56 +05:30
|
|
|
try {
|
2024-06-22 00:25:12 +05:30
|
|
|
|
|
|
|
|
const websiteVisit = getWebsiteFromQuery(query)
|
|
|
|
|
let search: {
|
|
|
|
|
url: any;
|
|
|
|
|
content: string;
|
|
|
|
|
}[] = []
|
|
|
|
|
|
feat: Add localization support for visitSpecificWebsite label
This commit adds localization support for the "visitSpecificWebsite" label in the settings.json file for multiple languages. Now, the label can be translated into different languages, including Japanese, Chinese, English, Malayalam, Italian, Portuguese, Russian, French, and Spanish.
2024-06-22 16:55:02 +05:30
|
|
|
const isVisitSpecificWebsite = await getIsVisitSpecificWebsite()
|
|
|
|
|
|
|
|
|
|
if (isVisitSpecificWebsite && websiteVisit.hasUrl) {
|
2024-06-22 00:25:12 +05:30
|
|
|
|
|
|
|
|
const url = websiteVisit.url
|
|
|
|
|
const queryWithoutUrl = websiteVisit.queryWithouUrls
|
|
|
|
|
search = await processSingleWebsite(url, queryWithoutUrl)
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
const searchProvider = await getSearchProvider()
|
|
|
|
|
search = await searchWeb(searchProvider, query)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-03-31 15:57:56 +05:30
|
|
|
const search_results = search
|
|
|
|
|
.map(
|
|
|
|
|
(result, idx) =>
|
|
|
|
|
`<result source="${result.url}" id="${idx}">${result.content}</result>`
|
|
|
|
|
)
|
|
|
|
|
.join("\n")
|
2024-02-25 18:44:47 +05:30
|
|
|
|
2024-03-31 15:57:56 +05:30
|
|
|
const current_date_time = new Date().toLocaleString()
|
2024-02-25 18:44:47 +05:30
|
|
|
|
2024-03-31 15:57:56 +05:30
|
|
|
const system = await getWebSearchPrompt()
|
2024-02-25 18:44:47 +05:30
|
|
|
|
2024-03-31 15:57:56 +05:30
|
|
|
const prompt = system
|
|
|
|
|
.replace("{current_date_time}", current_date_time)
|
|
|
|
|
.replace("{search_results}", search_results)
|
2024-02-25 18:44:47 +05:30
|
|
|
|
2024-03-31 15:57:56 +05:30
|
|
|
return {
|
|
|
|
|
prompt,
|
|
|
|
|
source: search.map((result) => {
|
2024-02-25 21:17:27 +05:30
|
|
|
return {
|
2024-03-31 15:57:56 +05:30
|
|
|
url: result.url,
|
|
|
|
|
name: getHostName(result.url),
|
|
|
|
|
type: "url"
|
2024-02-25 21:17:27 +05:30
|
|
|
}
|
2024-03-31 15:57:56 +05:30
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
return {
|
|
|
|
|
prompt: "",
|
|
|
|
|
source: []
|
2024-02-25 18:44:47 +05:30
|
|
|
}
|
2024-03-31 15:57:56 +05:30
|
|
|
}
|
|
|
|
|
}
|