From 394b5aafb6b63ba81ae8f33dbe3b998b95b085b1 Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Mon, 10 Jun 2024 15:22:32 -0700 Subject: [PATCH] linting --- .../AgentConfig/WebSearchSelection/index.jsx | 4 +- server/models/systemSettings.js | 9 ++-- .../agents/aibitat/plugins/web-browsing.js | 46 +++++++++++-------- server/utils/helpers/updateENV.js | 2 +- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/frontend/src/pages/WorkspaceSettings/AgentConfig/WebSearchSelection/index.jsx b/frontend/src/pages/WorkspaceSettings/AgentConfig/WebSearchSelection/index.jsx index 0bbc053a..a71ac770 100644 --- a/frontend/src/pages/WorkspaceSettings/AgentConfig/WebSearchSelection/index.jsx +++ b/frontend/src/pages/WorkspaceSettings/AgentConfig/WebSearchSelection/index.jsx @@ -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 = [ diff --git a/server/models/systemSettings.js b/server/models/systemSettings.js index 3cb0456f..8d548c7b 100644 --- a/server/models/systemSettings.js +++ b/server/models/systemSettings.js @@ -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); diff --git a/server/utils/agents/aibitat/plugins/web-browsing.js b/server/utils/agents/aibitat/plugins/web-browsing.js index 00b004cb..81314f17 100644 --- a/server/utils/agents/aibitat/plugins/web-browsing.js +++ b/server/utils/agents/aibitat/plugins/web-browsing.js @@ -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 }; diff --git a/server/utils/helpers/updateENV.js b/server/utils/helpers/updateENV.js index 3f2baf7e..72d7a8c4 100644 --- a/server/utils/helpers/updateENV.js +++ b/server/utils/helpers/updateENV.js @@ -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.