mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-05-13 16:07:30 +00:00
* 🔧 chore: Update dependencies in package-lock.json and package.json - Bump version of @librechat/agents to 3.1.75-dev.0 in multiple package.json files. - Upgrade various AWS SDK and Smithy dependencies to their latest versions in package-lock.json for improved stability and performance. * 🔧 chore: Update AWS SDK and Smithy dependencies in package-lock.json - Bump version of @aws-sdk/client-bedrock-runtime to 3.1041.0 and update related dependencies for improved performance and stability. - Upgrade various AWS SDK and Smithy packages to their latest versions, ensuring compatibility and enhanced functionality. * chore: Align LibreChat with agents LangChain upgrade - Route LangChain imports through @librechat/agents facade exports - Update @librechat/agents to 3.1.75-dev.1 and remove direct LangChain deps - Normalize nullable agent model params and API key override typing - Update Google thinking config typing for newer LangChain packages - Refresh targeted audit-related dependency overrides * chore: Add Jest types for API specs * test: Fix LangChain upgrade CI specs * test: Exercise agents env facade * fix: Clean up TS preview diagnostics * fix: Address Codex review feedback
79 lines
2.2 KiB
JavaScript
79 lines
2.2 KiB
JavaScript
const { Tool } = require('@librechat/agents/langchain/tools');
|
|
const { getEnvironmentVariable } = require('@librechat/agents/langchain/utils/env');
|
|
|
|
const googleSearchJsonSchema = {
|
|
type: 'object',
|
|
properties: {
|
|
query: {
|
|
type: 'string',
|
|
minLength: 1,
|
|
description: 'The search query string.',
|
|
},
|
|
max_results: {
|
|
type: 'integer',
|
|
minimum: 1,
|
|
maximum: 10,
|
|
description: 'The maximum number of search results to return. Defaults to 5.',
|
|
},
|
|
},
|
|
required: ['query'],
|
|
};
|
|
|
|
class GoogleSearchResults extends Tool {
|
|
static lc_name() {
|
|
return 'google';
|
|
}
|
|
|
|
static get jsonSchema() {
|
|
return googleSearchJsonSchema;
|
|
}
|
|
|
|
constructor(fields = {}) {
|
|
super(fields);
|
|
this.name = 'google';
|
|
this.envVarApiKey = 'GOOGLE_SEARCH_API_KEY';
|
|
this.envVarSearchEngineId = 'GOOGLE_CSE_ID';
|
|
this.override = fields.override ?? false;
|
|
this.apiKey = fields[this.envVarApiKey] ?? getEnvironmentVariable(this.envVarApiKey);
|
|
this.searchEngineId =
|
|
fields[this.envVarSearchEngineId] ?? getEnvironmentVariable(this.envVarSearchEngineId);
|
|
|
|
if (!this.override && (!this.apiKey || !this.searchEngineId)) {
|
|
throw new Error(
|
|
`Missing ${this.envVarApiKey} or ${this.envVarSearchEngineId} environment variable.`,
|
|
);
|
|
}
|
|
|
|
this.kwargs = fields?.kwargs ?? {};
|
|
this.name = 'google';
|
|
this.description =
|
|
'A search engine optimized for comprehensive, accurate, and trusted results. Useful for when you need to answer questions about current events.';
|
|
|
|
this.schema = googleSearchJsonSchema;
|
|
}
|
|
|
|
async _call(input) {
|
|
const { query, max_results = 5 } = input;
|
|
|
|
const response = await fetch(
|
|
`https://www.googleapis.com/customsearch/v1?key=${this.apiKey}&cx=${
|
|
this.searchEngineId
|
|
}&q=${encodeURIComponent(query)}&num=${max_results}`,
|
|
{
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
},
|
|
);
|
|
|
|
const json = await response.json();
|
|
if (!response.ok) {
|
|
throw new Error(`Request failed with status ${response.status}: ${json.error.message}`);
|
|
}
|
|
|
|
return JSON.stringify(json);
|
|
}
|
|
}
|
|
|
|
module.exports = GoogleSearchResults;
|