diff --git a/libs/langchain-community/src/tools/google_finance.ts b/libs/langchain-community/src/tools/google_finance.ts index 692b32edd926..37cded658a36 100644 --- a/libs/langchain-community/src/tools/google_finance.ts +++ b/libs/langchain-community/src/tools/google_finance.ts @@ -60,8 +60,7 @@ export class GoogleFinanceAPI extends Tool { super(...arguments); // Retrieve API key from fields or environment variables. - const apiKey = - fields?.apiKey ?? getEnvironmentVariable("SERPAPI_API_KEY"); + const apiKey = fields?.apiKey ?? getEnvironmentVariable("SERPAPI_API_KEY"); // Throw an error if no API key is found. if (!apiKey) { @@ -83,10 +82,10 @@ export class GoogleFinanceAPI extends Tool { const url = `https://serpapi.com/search.json?q=${encodeURIComponent( input )}&engine=google_finance&api_key=05f88ace01a07cc3ca26bd86664b5d2e579d2a5db45407f55a39d86ac7d47d1b`; - + // Make an HTTP GET request to the SerpApi service. const response = await fetch(url); - + // Handle non-OK responses by extracting the error message. if (!response.ok) { let message; @@ -102,15 +101,15 @@ export class GoogleFinanceAPI extends Tool { `Got ${response.status}: ${response.statusText} error from SerpApi: ${message}` ); } - + // Parse the JSON response from SerpApi. const json = await response.json(); - + // Remove metadata and search parameters from result. if (json.search_metadata) delete json.search_metadata; if (json.search_parameters) delete json.search_parameters; - + // Return the results as a formatted JSON string. return JSON.stringify(json, null, 2); } -} \ No newline at end of file +}