forked from huggingface/chat-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into front/setting_page_theme
- Loading branch information
Showing
17 changed files
with
118 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { SEARXNG_QUERY_URL } from "$env/static/private"; | ||
|
||
export async function searchSearxng(query: string) { | ||
const abortController = new AbortController(); | ||
setTimeout(() => abortController.abort(), 10000); | ||
|
||
// Insert the query into the URL template | ||
let url = SEARXNG_QUERY_URL.replace("<query>", query); | ||
|
||
// Check if "&format=json" already exists in the URL | ||
if (!url.includes("&format=json")) { | ||
url += "&format=json"; | ||
} | ||
|
||
// Call the URL to return JSON data | ||
const jsonResponse = await fetch(url, { | ||
signal: abortController.signal, | ||
}) | ||
.then((response) => response.json() as Promise<{ results: { url: string }[] }>) | ||
.catch((error) => { | ||
console.error("Failed to fetch or parse JSON", error); | ||
throw new Error("Failed to fetch or parse JSON"); | ||
}); | ||
|
||
// Extract 'url' elements from the JSON response and trim to the top 5 URLs | ||
const urls = jsonResponse.results.slice(0, 5).map((item) => item.url); | ||
|
||
if (!urls.length) { | ||
throw new Error(`Response doesn't contain any "url" elements`); | ||
} | ||
|
||
// Map URLs to the correct object shape | ||
return { organic_results: urls.map((link) => ({ link })) }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export function formatUserCount(userCount: number): string { | ||
const userCountRanges: { min: number; max: number; label: string }[] = [ | ||
{ min: 0, max: 1, label: "1" }, | ||
{ min: 2, max: 9, label: "1-10" }, | ||
{ min: 10, max: 49, label: "10+" }, | ||
{ min: 50, max: 99, label: "50+" }, | ||
{ min: 100, max: 299, label: "100+" }, | ||
{ min: 300, max: 499, label: "300+" }, | ||
{ min: 500, max: 999, label: "500+" }, | ||
{ min: 1_000, max: 2_999, label: "1k+" }, | ||
{ min: 3_000, max: 4_999, label: "3k+" }, | ||
{ min: 5_000, max: 9_999, label: "5k+" }, | ||
{ min: 10_000, max: Infinity, label: "10k+" }, | ||
]; | ||
|
||
const range = userCountRanges.find(({ min, max }) => userCount >= min && userCount <= max); | ||
return range?.label ?? ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters