Skip to content

Commit e537221

Browse files
authored
Merge pull request #328 from n4ze3m/next
v1.4.5
2 parents 2d1e465 + 7264f30 commit e537221

File tree

7 files changed

+122
-14
lines changed

7 files changed

+122
-14
lines changed

src/components/Common/Playground/Message.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { useTTS } from "@/hooks/useTTS"
1818
import { tagColors } from "@/utils/color"
1919
import { removeModelSuffix } from "@/db/models"
2020
import { GenerationInfo } from "./GenerationInfo"
21-
import { parseReasoning } from "@/libs/reasoning"
21+
import { parseReasoning, removeReasoning } from "@/libs/reasoning"
2222
import { humanizeMilliseconds } from "@/utils/humanize-miliseconds"
2323
type Props = {
2424
message: string
@@ -54,7 +54,7 @@ export const PlaygroundMessage = (props: Props) => {
5454
return (
5555
<div className="group w-full text-gray-800 dark:text-gray-100">
5656
<div className="text-base md:max-w-2xl lg:max-w-xl xl:max-w-3xl flex lg:px-0 m-auto w-full">
57-
<div className="flex flex-row gap-4 md:gap-6 p-4 md:py-6 lg:px-0 m-auto w-full">
57+
<div className="flex flex-row gap-4 md:gap-6 p-4 m-auto w-full">
5858
<div className="w-8 flex flex-col relative items-end">
5959
<div className="relative h-7 w-7 p-1 rounded-sm text-white flex items-center justify-center text-opacity-100r">
6060
{props.isBot ? (
@@ -150,7 +150,6 @@ export const PlaygroundMessage = (props: Props) => {
150150
</div>
151151
{/* source if available */}
152152
{props.images &&
153-
props.images &&
154153
props.images.filter((img) => img.length > 0).length > 0 && (
155154
<div className="flex md:max-w-2xl lg:max-w-xl xl:max-w-3xl mt-4 m-auto w-full">
156155
{props.images
@@ -198,8 +197,12 @@ export const PlaygroundMessage = (props: Props) => {
198197
<div
199198
className={`space-x-2 gap-2 mt-3 flex ${
200199
props.currentMessageIndex !== props.totalMessages - 1
201-
? "invisible group-hover:visible"
202-
: ""
200+
// there is few style issue so i am commenting this out for v1.4.5 release
201+
// next release we will fix this
202+
// ? "invisible group-hover:visible"
203+
? "hidden group-hover:flex"
204+
// ""
205+
: "flex"
203206
}`}>
204207
{props.isTTSEnabled && (
205208
<Tooltip title={t("tts")}>
@@ -210,7 +213,7 @@ export const PlaygroundMessage = (props: Props) => {
210213
cancel()
211214
} else {
212215
speak({
213-
utterance: props.message
216+
utterance: removeReasoning(props.message),
214217
})
215218
}
216219
}}

src/utils/search-provider.ts

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export const SUPPORTED_SERACH_PROVIDERS = [
1111
label: "Sogou",
1212
value: "sogou"
1313
},
14+
{
15+
label: "Baidu",
16+
value: "baidu"
17+
},
1418
{
1519
label: "Brave",
1620
value: "brave"

src/web/search-engines/baidu.ts

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { cleanUrl } from "@/libs/clean-url"
2+
import { PageAssistHtmlLoader } from "@/loader/html"
3+
import { pageAssistEmbeddingModel } from "@/models/embedding"
4+
import {
5+
defaultEmbeddingModelForRag,
6+
getOllamaURL
7+
} from "@/services/ollama"
8+
import {
9+
getIsSimpleInternetSearch,
10+
totalSearchResults
11+
} from "@/services/search"
12+
import { getPageAssistTextSplitter } from "@/utils/text-splitter"
13+
import type { Document } from "@langchain/core/documents"
14+
import { MemoryVectorStore } from "langchain/vectorstores/memory"
15+
16+
export const localBaiduSearch = async (query: string) => {
17+
const TOTAL_SEARCH_RESULTS = await totalSearchResults()
18+
19+
const abortController = new AbortController()
20+
setTimeout(() => abortController.abort(), 10000)
21+
22+
const jsonRes = await fetch(
23+
"https://www.baidu.com/s?wd=" + encodeURIComponent(query) + "&tn=json&rn=" + TOTAL_SEARCH_RESULTS,
24+
{
25+
signal: abortController.signal
26+
}
27+
)
28+
.then((response) => response.json())
29+
.catch((e) => {
30+
console.log(e)
31+
return {
32+
feed: {
33+
entry: []
34+
}
35+
}
36+
})
37+
38+
const data = jsonRes?.feed?.entry || []
39+
40+
const searchResults = data.map((result: any) => {
41+
const title = result?.title || ""
42+
const link = result?.url
43+
const content = result?.abs || ""
44+
return { title, link, content }
45+
})
46+
47+
48+
return searchResults.filter((result) => result?.link)
49+
}
50+
51+
export const webBaiduSearch = async (query: string) => {
52+
const searchResults = await localBaiduSearch(query)
53+
54+
const isSimpleMode = await getIsSimpleInternetSearch()
55+
56+
if (isSimpleMode) {
57+
await getOllamaURL()
58+
return searchResults.map((result) => {
59+
return {
60+
url: result.link,
61+
content: result.content
62+
}
63+
})
64+
}
65+
66+
const docs: Document<Record<string, any>>[] = []
67+
for (const result of searchResults) {
68+
const loader = new PageAssistHtmlLoader({
69+
html: "",
70+
url: result.link
71+
})
72+
73+
const documents = await loader.loadByURL()
74+
75+
documents.forEach((doc) => {
76+
docs.push(doc)
77+
})
78+
}
79+
const ollamaUrl = await getOllamaURL()
80+
81+
const embeddingModle = await defaultEmbeddingModelForRag()
82+
const ollamaEmbedding = await pageAssistEmbeddingModel({
83+
model: embeddingModle || "",
84+
baseUrl: cleanUrl(ollamaUrl)
85+
})
86+
87+
const textSplitter = await getPageAssistTextSplitter()
88+
89+
const chunks = await textSplitter.splitDocuments(docs)
90+
91+
const store = new MemoryVectorStore(ollamaEmbedding)
92+
93+
await store.addDocuments(chunks)
94+
95+
const resultsWithEmbeddings = await store.similaritySearch(query, 3)
96+
97+
const searchResult = resultsWithEmbeddings.map((result) => {
98+
return {
99+
url: result.metadata.url,
100+
content: result.pageContent
101+
}
102+
})
103+
104+
return searchResult
105+
}

src/web/search-engines/duckduckgo.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { cleanUrl } from "@/libs/clean-url"
2-
import { urlRewriteRuntime } from "@/libs/runtime"
32
import { PageAssistHtmlLoader } from "@/loader/html"
43
import { pageAssistEmbeddingModel } from "@/models/embedding"
54
import {
@@ -16,7 +15,6 @@ import * as cheerio from "cheerio"
1615
import { MemoryVectorStore } from "langchain/vectorstores/memory"
1716

1817
export const localDuckDuckGoSearch = async (query: string) => {
19-
await urlRewriteRuntime(cleanUrl("https://html.duckduckgo.com/html/?q=" + query), "duckduckgo")
2018

2119
const abortController = new AbortController()
2220
setTimeout(() => abortController.abort(), 10000)

src/web/search-engines/google.ts

-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { getPageAssistTextSplitter } from "@/utils/text-splitter"
88
import type { Document } from "@langchain/core/documents"
99
import { MemoryVectorStore } from "langchain/vectorstores/memory"
1010
import { cleanUrl } from "~/libs/clean-url"
11-
import { urlRewriteRuntime } from "~/libs/runtime"
1211
import { PageAssistHtmlLoader } from "~/loader/html"
1312
import {
1413
defaultEmbeddingModelForRag,
@@ -18,10 +17,6 @@ import {
1817

1918
export const localGoogleSearch = async (query: string) => {
2019
const baseGoogleDomain = await getGoogleDomain()
21-
await urlRewriteRuntime(
22-
cleanUrl(`https://www.${baseGoogleDomain}/search?hl=en&q=` + query),
23-
"google"
24-
)
2520
const abortController = new AbortController()
2621
setTimeout(() => abortController.abort(), 10000)
2722

src/web/web.ts

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { webBraveSearch } from "./search-engines/brave"
77
import { getWebsiteFromQuery, processSingleWebsite } from "./website"
88
import { searxngSearch } from "./search-engines/searxng"
99
import { braveAPISearch } from "./search-engines/brave-api"
10+
import { webBaiduSearch } from "./search-engines/baidu"
1011

1112
const getHostName = (url: string) => {
1213
try {
@@ -29,6 +30,8 @@ const searchWeb = (provider: string, query: string) => {
2930
return searxngSearch(query)
3031
case "brave-api":
3132
return braveAPISearch(query)
33+
case "baidu":
34+
return webBaiduSearch(query)
3235
default:
3336
return webGoogleSearch(query)
3437
}

wxt.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default defineConfig({
5151
outDir: "build",
5252

5353
manifest: {
54-
version: "1.4.4",
54+
version: "1.4.5",
5555
name:
5656
process.env.TARGET === "firefox"
5757
? "Page Assist - A Web UI for Local AI Models"

0 commit comments

Comments
 (0)