slorg
v1.0.0
Published
LLM-powered search engine library with knowledge graph generation
Maintainers
Readme
Slorg
An AI-powered search engine with knowledge graph generation.
Installation
npm install -g slorgUsage
As a CLI tool
# Set your OpenAI API key
export OPENAI_API_KEY=your_api_key_here
# Run a search
slorg "What is the capital of France?"
# Or provide the API key directly
slorg -k your_api_key_here "What is the capital of France?"
# Specify a model
slorg -m gpt-4o "What is the capital of France?"
# Limit results
slorg -r 3 "What is the capital of France?"As a server
# Start the server
slorg server
# Start the server on a specific port
slorg server -p 8080
# Start the server with API key
slorg server -k your_api_key_here
# Or set the API key as an environment variable
export OPENAI_API_KEY=your_api_key_here
slorg serverThe server exposes two endpoints:
GET /health- Health check endpointPOST /search- Search endpoint that accepts JSON withquery,model, andmaxResultsfields
Example server usage:
curl -X POST http://localhost:3000/search \
-H "Content-Type: application/json" \
-d '{"query": "What is the capital of France?", "model": "gpt-4o", "maxResults": 3}'As a library
import SlorgSearch from 'slorg';
const searcher = new SlorgSearch('your-openai-api-key');
const results = await searcher.search('What is the capital of France?', {
model: 'gpt-4o-mini',
maxResults: 5
});
console.log(results.answer);
console.log(results.knowledgeGraph);
console.log(results.keywords);
console.log(results.results);Environment Variables
The following environment variables can be used to configure Slorg:
OPENAI_API_KEY- Your OpenAI API key (required)OPENAI_BASE_URL- Custom OpenAI API base URL (optional)SLORG_DEFAULT_MODEL- Default model to use (default: "gpt-4o-mini")SLORG_SEARCH_API_URL- Search API URL (default: "https://search-dev.d736.uk/search")SLORG_SEARCH_ENGINES- Comma-separated list of search engines (default: "google,yahoo,bing,duckduckgo")SLORG_SEARCH_LIMIT- Maximum number of search results (default: "20")PORT- Port for the server (default: 3000)
Features
- AI-powered search with natural language understanding
- Knowledge graph generation for search queries
- Keyword extraction for improved search results
- Web content scraping and analysis
- Token usage tracking
- Configurable OpenAI models
- Both CLI and server modes
- Environment variable configuration
API
new SlorgSearch(apiKey)
Create a new SlorgSearch instance with your OpenAI API key.
search(query, options)
Perform a search with the given query.
Options:
model: The OpenAI model to use (default: 'gpt-4o-mini')maxResults: Maximum number of results to return (default: 5)
Returns a Promise that resolves to an object with:
answer: The LLM-generated answerknowledgeGraph: Structured representation of the querykeywords: Extracted search keywordsresults: Array of search results with scorestokenCount: Total tokens used in the search
License
MIT
