Add search mode settings and textarea focus on form submission

This commit is contained in:
n4ze3m
2024-03-04 00:32:01 +05:30
parent a87c56061c
commit 1b689c91c0
8 changed files with 88 additions and 26 deletions

View File

@@ -5,7 +5,7 @@ import { MemoryVectorStore } from "langchain/vectorstores/memory"
import { cleanUrl } from "~libs/clean-url"
import { chromeRunTime } from "~libs/runtime"
import { PageAssistHtmlLoader } from "~loader/html"
import { defaultEmbeddingChunkOverlap, defaultEmbeddingChunkSize, defaultEmbeddingModelForRag, getOllamaURL } from "~services/ollama"
import { defaultEmbeddingChunkOverlap, defaultEmbeddingChunkSize, defaultEmbeddingModelForRag, getIsSimpleInternetSearch, getOllamaURL } from "~services/ollama"
const BLOCKED_HOSTS = [
"google.com",
@@ -40,13 +40,7 @@ export const localGoogleSearch = async (query: string) => {
(result) => {
const title = result.querySelector("h3")?.textContent
const link = result.querySelector("a")?.getAttribute("href")
let content = result.querySelector("div[data-sncf='2']")?.textContent
if(content === "") {
content = result.querySelector("div[data-sncf='1']")?.textContent
if(content === "") {
content = result.querySelector("div[data-sncf='3']")?.textContent
}
}
const content = Array.from(result.querySelectorAll("span")).map((span) => span.textContent).join(" ")
return { title, link, content }
}
)
@@ -65,6 +59,18 @@ export const webSearch = async (query: string) => {
const results = await localGoogleSearch(query)
const searchResults = results.slice(0, TOTAL_SEARCH_RESULTS)
const isSimpleMode = await getIsSimpleInternetSearch()
if (isSimpleMode) {
await getOllamaURL()
return searchResults.map((result) => {
return {
url: result.link,
content: result.content
}
})
}
const docs: Document<Record<string, any>>[] = [];
for (const result of searchResults) {
const loader = new PageAssistHtmlLoader({