This commit is contained in:
timothycarambat 2024-06-10 15:22:32 -07:00
parent 7693240e21
commit 394b5aafb6
4 changed files with 36 additions and 25 deletions

View File

@ -3,14 +3,14 @@ import AnythingLLMIcon from "@/media/logo/anything-llm-icon.png";
import GoogleSearchIcon from "./icons/google.png";
import SerperDotDevIcon from "./icons/serper.png";
import BingSearchIcon from "./icons/bing.png";
import SerplySearchIcon from "./icons/serply.png"
import SerplySearchIcon from "./icons/serply.png";
import { CaretUpDown, MagnifyingGlass, X } from "@phosphor-icons/react";
import SearchProviderItem from "./SearchProviderItem";
import {
SerperDotDevOptions,
GoogleSearchOptions,
BingSearchOptions,
SerplySearchOptions
SerplySearchOptions,
} from "./SearchProviderOptions";
const SEARCH_PROVIDERS = [

View File

@ -71,9 +71,12 @@ const SystemSettings = {
try {
if (update === "none") return null;
if (
!["google-search-engine", "serper-dot-dev", "bing-search", "serply-engine"].includes(
update
)
![
"google-search-engine",
"serper-dot-dev",
"bing-search",
"serply-engine",
].includes(update)
)
throw new Error("Invalid SERP provider.");
return String(update);

View File

@ -221,7 +221,14 @@ const webBrowsing = {
return `No information was found online for the search query.`;
return JSON.stringify(searchResponse);
},
_serplyEngine: async function (query, language = "en", hl = "us", limit = 100, device_type = "desktop", proxy_location = "US") {
_serplyEngine: async function (
query,
language = "en",
hl = "us",
limit = 100,
device_type = "desktop",
proxy_location = "US"
) {
// query (str): The query to search for
// hl (str): Host Language code to display results in (reference https://developers.google.com/custom-search/docs/xml_results?hl=en#wsInterfaceLanguages)
// limit (int): The maximum number of results to return [10-100, defaults to 100]
@ -244,28 +251,29 @@ const webBrowsing = {
q: query,
language: language,
hl,
gl: proxy_location.toUpperCase()
gl: proxy_location.toUpperCase(),
});
const url = `https://api.serply.io/v1/search/${params.toString()}`;
const { response, error } = await fetch(url, {
method: "GET",
headers: {
"X-API-KEY": process.env.AGENT_SERPLY_API_KEY,
"Content-Type": "application/json",
"User-Agent": "anything-llm",
"X-Proxy-Location": proxy_location,
"X-User-Agent": device_type,
},
})
const url = `https://api.serply.io/v1/search/${params.toString()}`
const { response, error } = await fetch(
url,
{
method: "GET",
headers: {
"X-API-KEY": process.env.AGENT_SERPLY_API_KEY,
"Content-Type": "application/json",
"User-Agent": "anything-llm",
"X-Proxy-Location": proxy_location,
"X-User-Agent": device_type
}
}
)
.then((res) => res.json())
.then((data) => {
if (data?.message === "Unauthorized"){
return { response: null, error: "Unauthorized. Please double check your AGENT_SERPLY_API_KEY" };
if (data?.message === "Unauthorized") {
return {
response: null,
error:
"Unauthorized. Please double check your AGENT_SERPLY_API_KEY",
};
}
return { response: data, error: null}
return { response: data, error: null };
})
.catch((e) => {
return { response: null, error: e.message };

View File

@ -773,7 +773,7 @@ async function dumpENV() {
"AGENT_GSE_KEY",
"AGENT_SERPER_DEV_KEY",
"AGENT_BING_SEARCH_API_KEY",
"AGENT_SERPLY_API_KEY"
"AGENT_SERPLY_API_KEY",
];
// Simple sanitization of each value to prevent ENV injection via newline or quote escaping.