langchain-serpex-js
v0.1.4
Published
LangChain integration for SERPEX search API (JavaScript/TypeScript)
Maintainers
Readme
langchain-serpex-js
LangChain integration for SERPEX search API (JavaScript/TypeScript).
Installation
npm install langchain-serpex-jsWhat is SERPEX?
SERPEX is a powerful multi-engine search API that provides access to search results from Google, Bing, DuckDuckGo, Baidu, Yandex, and other search engines in JSON format. It's designed for developers building AI applications, SEO tools, market research platforms, and data aggregation services.
Features
- Multi-Engine Support: Search across Google, Bing, DuckDuckGo, Baidu, and Yandex
- Rich Results: Get organic results, answer boxes, knowledge graphs, news, images, videos, and shopping results
- Localization: Support for location-based and language-specific searches
- Real-time Data: Access to current search results
- Easy Integration: Simple API with comprehensive documentation
Quick Start
Get Your API Key
Sign up at SERPEX to get your API key.
Basic Usage
import { Serpex } from 'langchain-serpex-js';
// Initialize the tool
const tool = new Serpex('your-serpex-api-key', {
engine: 'google'
});
// Perform a search
const results = await tool.invoke('latest AI developments');
console.log(results);With LangChain Agent
import { Serpex } from 'langchain-serpex-js';
import { ChatOpenAI } from '@langchain/openai';
import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents';
import { ChatPromptTemplate } from '@langchain/core/prompts';
// Initialize the search tool
const searchTool = new Serpex('your-serpex-api-key', {
engine: 'google'
});
// Initialize the LLM
const llm = new ChatOpenAI({ model: 'gpt-4', temperature: 0 });
// Create an agent with the search tool
const prompt = ChatPromptTemplate.fromMessages([
['system', 'You are a helpful assistant.'],
['human', '{input}'],
['human', '{agent_scratchpad}']
]);
const agent = await createOpenAIFunctionsAgent({
llm,
tools: [searchTool],
prompt
});
const executor = new AgentExecutor({
agent,
tools: [searchTool]
});
// Run the agent
const result = await executor.invoke({
input: 'What are the latest developments in quantum computing?'
});
console.log(result);Configuration
Environment Variables
You can set your SERPEX API key as an environment variable:
export SERPEX_API_KEY="your-serpex-api-key"Then use the tool without passing the API key:
import { Serpex } from 'langchain-serpex-js';
const tool = new Serpex(); // Will use SERPEX_API_KEY from environmentParameters
apiKey(string): Your SERPEX API key (required)engine(string): Search engine to use - "google", "bing", "duckduckgo", "baidu", "yandex" (default: "google")category(string): Search category - currently only "web" is supportedtime_range(string): Time filter - "all", "day", "week", "month", "year"
Documentation
For more detailed documentation, visit:
Support
For issues and questions:
- GitHub Issues: langchain-serpex-js issues
- SERPEX Support: [email protected]
License
This package is licensed under the MIT License.
CI / Publishing
A GitHub Actions workflow is provided to publish the package to npm when a tag like v* is pushed or when a release is published.
Required repository secret:
NPM_TOKEN— an npm automation token with permission to publish the package. Set this in the repository's Settings → Secrets → Actions.
To publish a new release, create a tag vMAJOR.MINOR.PATCH and push it or create a release in GitHub; the workflow will build the package and upload it to npm.
