search-gpt-agent
v1.0.5
Published
SearchGPT is a versatile Node.js library that leverages OpenAI's LLMs and Google Search capabilities, allowing for powerful, context-aware query handling and web search functionality. With this library, you can build custom search agents capable of conduc
Downloads
293
Readme
SearchGPT
SearchGPT is a versatile Node.js library that leverages OpenAI's LLMs and Google Search capabilities, allowing for powerful, context-aware query handling and web search functionality. With this library, you can build custom search agents capable of conducting Google searches and extracting and analyzing content using vector similarities.
Installation
Before using SearchGPT, please ensure you have Node.js and npm installed. Then, create a .env
file in your project root and include your OpenAI and Google API keys:
OPENAI_API_KEY=your_openai_api_key
GOOGLE_SEARCH_API_KEY=your_google_search_api_key
GOOGLE_SEARCH_ENGINE_ID=your_search_engine_id
To install, run:
npm install search-gpt
Usage
Below is a brief example of how to use SearchGPT to create a search agent and perform a context-aware search.
import { config } from 'dotenv';
import { searchGpt, googleSearchWithVectorSimilarityTool } from 'search-gpt';
config();
// Create a search agent
async function example() {
const { createSearchAgent } = searchGpt({
openaiApiKey: process.env.OPENAI_API_KEY,
});
const searchTool = googleSearchWithVectorSimilarityTool({
googleSearchApiKey: process.env.GOOGLE_SEARCH_API_KEY,
googleSearchEngineId: process.env.GOOGLE_SEARCH_ENGINE_ID,
googleSearchApiEntpoint: "https://www.googleapis.com/customsearch/v1",
});
const searchAgent = await createSearchAgent("gpt-4o", [], [searchTool]);
// Perform a context-aware search
const response = await searchAgent.invoke("What is the current price of bitcoin?");
console.log(response.output);
const searchAgentWithContext = await createSearchAgent("gpt-4o", response.outputMessageArray, [searchTool]);
const response2 = await searchAgentWithContext.invoke("How much is that in Australian dollars?");
console.log(response2.output);
}
example();
Features
- Create Custom Agents: Leverage OpenAI's GPT models to create contextually aware search agents.
- Google Search Integration: Perform searches using Google API and retrieve content.
- Vector Similarity Search: Use vector embeddings to compare and analyze content contextually.
- Message History Handling: Maintain conversation state across multiple invocations for interactive applications.
Tools
googleSearchTool
googleSearchWithVectorSimilarityTool
For further customization, explore additional tools provided in src/tools
.
Ensure to replace required API keys and any instance-specific details to utilize SearchGPT effectively. Adjust configurations and refine prompt templates to build agents suited to your domain-specific needs.