Skip to content

Commit

Permalink
chore: Passes linting and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuajyu committed Nov 28, 2024
1 parent 31d05b9 commit 7884054
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions libs/langchain-community/src/tools/google_finance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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);
}
}
}

0 comments on commit 7884054

Please sign in to comment.