A flexible Python interface for locally hosted LLMs, focusing on Ollama integration with RAG capabilities.
- Connect to locally hosted LLMs (Ollama)
- Support for both single-shot queries and persistent chat sessions
- Built-in RAG (Retrieval Augmented Generation) for web research
- Tool-based research system with ReAct pattern
- Lightweight with minimal dependencies and cross-platform compatibility
- Extensible architecture for future capabilities
pip install git+https://github.com/Munger/llm_interface.git
git clone https://github.com/Munger/llm_interface.git cd llm_interface pip install -e .
from llm_interface import LLMClient
client = LLMClient()
response = client.query("Explain quantum computing in simple terms") print(response)
session = client.create_session() response = session.chat("Tell me about Python's asyncio library") print(response)
response = session.chat("How does it compare to threading?") print(response)
response = session.research("What are the latest developments in fusion energy?") print(response)
Single query:
llm-cli ask "What is the capital of France?"
Start interactive chat session:
llm-cli chat
Research with web search:
llm-cli research "Recent advances in quantum computing"
-m, --model MODEL Specify Ollama model to use (default: from config) -h, --host HOST Specify Ollama host (default: localhost) -p, --port PORT Specify Ollama port (default: 11434) -c, --config PATH Path to custom config file -d, --debug Enable debug mode for verbose output
ask PROMPT Send a single query to the LLM
chat Start an interactive chat session -s, --session ID Session ID (creates new if not provided)
research QUERY Perform intelligent research with ReAct -s, --session ID Session ID (creates temporary if not provided)
list-sessions List all available sessions
delete-session ID Delete a chat session -f, --force Force deletion without confirmation
show-config Show current configuration -s, --save Save config to user config file
list-tools List available research tools
You can initiate research during a chat session using the /research command:
$ llm-cli chat Created new session 123e4567-e89b-12d3-a456-426614174000 Enter your messages (Ctrl+D or type 'exit' to quit): Use /research to perform research on a topic
You> Tell me about quantum computing LLM> Quantum computing is a type of computing that uses quantum-mechanical phenomena...
You> /research latest breakthroughs in quantum computing LLM> Researching: latest breakthroughs in quantum computing... [Research results will appear here]
The /research command triggers the ReAct pattern which:
- Breaks down the research query
- Uses appropriate tools to gather information
- Synthesises the findings into a coherent response
You can also use the research command programmatically:
response = session.chat("/research latest developments in quantum computing")
LLM Interface uses API keys for various services when performing research. Keys are stored securely in ~/.llm_interface/api_keys.json.
Supported APIs:
- youtube, google, google_custom_search
- vimeo, dailymotion
- github, twitter, bing
Keys can be set programmatically:
from llm_interface.config.api_keys import api_key_manager
api_key_manager.set_key("youtube", "your-api-key-here")
if api_key_manager.has_key("youtube"): # Use the key youtube_key = api_key_manager.get_key("youtube")
Default configuration is stored in ~/.llm_interface/config.json. You can override settings when initialising:
from llm_interface import LLMClient from llm_interface.config import Config
config_override = { "ollama_host": "localhost", "ollama_port": 11434, "default_model": "llama2:13b" }
client = LLMClient(config_override=config_override)
LLM Interface is built with a modular architecture:
- Core Client: Interfaces with local LLMs (currently focused on Ollama)
- Session Management: Handles persistent chat sessions with history
- Research Capabilities: Implements RAG for enhanced responses
- Tools: Pluggable research tools for web search, video content, and list processing
- Configuration: Flexible configuration with sensible defaults
The ReAct (Reasoning + Acting) system combines these tools with LLM reasoning for powerful research capabilities.
Licence: MIT
Contributing: Contributions are welcome! Please feel free to submit a Pull Request.