@jackhua/mini-langchain
Version:
A lightweight TypeScript implementation of LangChain with cost optimization features
41 lines • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SearchTool = void 0;
const base_1 = require("./base");
/**
* Mock search tool for demonstration
*/
class SearchTool extends base_1.BaseTool {
constructor() {
super(...arguments);
this.name = 'search';
this.description = 'Search for information on the internet. Input should be a search query.';
// Mock search data
this.mockData = {
'capital of france': 'Paris is the capital and largest city of France.',
'python programming': 'Python is a high-level, interpreted programming language known for its simplicity.',
'machine learning': 'Machine learning is a subset of artificial intelligence that enables systems to learn from data.',
'typescript benefits': 'TypeScript adds static typing to JavaScript, improving code quality and developer productivity.',
'langchain': 'LangChain is a framework for developing applications powered by language models.',
'weather today': 'I cannot provide real-time weather data. This is a mock response.',
'latest news': 'I cannot provide real-time news. This is a mock response.'
};
}
async execute(input) {
const query = input.toLowerCase().trim();
// Check for exact matches first
if (this.mockData[query]) {
return this.mockData[query];
}
// Check for partial matches
for (const [key, value] of Object.entries(this.mockData)) {
if (query.includes(key) || key.includes(query)) {
return value;
}
}
// Default response
return `No specific information found for "${input}". This is a mock search tool for demonstration purposes.`;
}
}
exports.SearchTool = SearchTool;
//# sourceMappingURL=search.js.map