mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-07-11 00:33:40 +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
77 lines
2.4 KiB
JavaScript
77 lines
2.4 KiB
JavaScript
const { z } = require('zod');
|
|
const { ProxyAgent, fetch } = require('undici');
|
|
const { tool } = require('@librechat/agents/langchain/tools');
|
|
const { getApiKey } = require('./credentials');
|
|
|
|
function createTavilySearchTool(fields = {}) {
|
|
const envVar = 'TAVILY_API_KEY';
|
|
const override = fields.override ?? false;
|
|
const apiKey = fields.apiKey ?? getApiKey(envVar, override);
|
|
const kwargs = fields?.kwargs ?? {};
|
|
|
|
return tool(
|
|
async (input) => {
|
|
const { query, ...rest } = input;
|
|
|
|
const requestBody = {
|
|
api_key: apiKey,
|
|
query,
|
|
...rest,
|
|
...kwargs,
|
|
};
|
|
|
|
const fetchOptions = {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(requestBody),
|
|
};
|
|
|
|
if (process.env.PROXY) {
|
|
fetchOptions.dispatcher = new ProxyAgent(process.env.PROXY);
|
|
}
|
|
|
|
const response = await fetch('https://api.tavily.com/search', fetchOptions);
|
|
|
|
const json = await response.json();
|
|
if (!response.ok) {
|
|
throw new Error(`Request failed with status ${response.status}: ${json.error}`);
|
|
}
|
|
|
|
return JSON.stringify(json);
|
|
},
|
|
{
|
|
name: 'tavily_search_results_json',
|
|
description:
|
|
'A search engine optimized for comprehensive, accurate, and trusted results. Useful for when you need to answer questions about current events.',
|
|
schema: z.object({
|
|
query: z.string().min(1).describe('The search query string.'),
|
|
max_results: z
|
|
.number()
|
|
.min(1)
|
|
.max(10)
|
|
.optional()
|
|
.describe('The maximum number of search results to return. Defaults to 5.'),
|
|
search_depth: z
|
|
.enum(['basic', 'advanced'])
|
|
.optional()
|
|
.describe(
|
|
'The depth of the search, affecting result quality and response time (`basic` or `advanced`). Default is basic for quick results and advanced for indepth high quality results but longer response time. Advanced calls equals 2 requests.',
|
|
),
|
|
include_images: z
|
|
.boolean()
|
|
.optional()
|
|
.describe(
|
|
'Whether to include a list of query-related images in the response. Default is False.',
|
|
),
|
|
include_answer: z
|
|
.boolean()
|
|
.optional()
|
|
.describe('Whether to include answers in the search results. Default is False.'),
|
|
}),
|
|
},
|
|
);
|
|
}
|
|
|
|
module.exports = createTavilySearchTool;
|