LLM Registry
A global, reusable LLM Registry wrapper for LangChain chat models. It enables unified model configuration management, lazy loading, and dynamic resolution of model providers (OpenAI, Groq, Anthropic, and Google Gemini).
Installation & Setup
1. Installation
Install the core package:
pip install lighthouse-llm-registry
To install specific provider SDK dependencies:
# OpenAI support
pip install "lighthouse-llm-registry[openai]"
# Groq support
pip install "lighthouse-llm-registry[groq]"
# Anthropic support
pip install "lighthouse-llm-registry[anthropic]"
# Google Gemini support
pip install "lighthouse-llm-registry[google]"
# Install all supported providers
pip install "lighthouse-llm-registry[all]"
If installing from local source distribution:
pip install ".[all]"
2. API Keys Configuration
Create a .env file in the root of your target project:
OPENAI_API_KEY=your-openai-key
GROQ_API_KEY=your-groq-key
ANTHROPIC_API_KEY=your-anthropic-key
GOOGLE_API_KEY=your-gemini-key
LOCAL_MODEL_LINK=http://192.168.101.88:11434/api/chat
LOCAL_MODEL=llama3.1:8b
Usage Guide
1. Registration (Application Startup)
Register your model configurations once at application startup (e.g., in your app's main entry point):
# main.py
from dotenv import load_dotenv
from llm_registry import global_registry, ModelConfig
# Load environment keys from .env
load_dotenv()
# Register OpenAI config (defaults to standard temperature/max_tokens rules)
global_registry.register_model_config(
"primary-chat",
ModelConfig(
provider="openai",
model_name="gpt-4o-mini",
temperature=0.7
)
)
# Register Groq config
global_registry.register_model_config(
"fast-chat",
ModelConfig(
provider="groq",
model_name="llama-3.1-8b-instant",
temperature=0.2
)
)
# Register Anthropic config (supports models like claude-opus-4-8)
global_registry.register_model_config(
"legacy-chat",
ModelConfig(
provider="anthropic",
model_name="claude-opus-4-8"
)
)
# Register Local Ollama config (falls back to LOCAL_MODEL_LINK and LOCAL_MODEL if parameters are omitted)
global_registry.register_model_config(
"local-chat",
ModelConfig(
provider="local",
model_name=""
)
)
2. Resolution (Anywhere in your code)
Resolve and query the model anywhere inside your application without importing specific provider SDKs:
# agents/agent.py
from llm_registry import global_registry
class SimpleAgent:
def __init__(self):
# Dynamically resolve model from the global registry
self.model = global_registry.get_model("fast-chat")
def respond(self, query: str) -> str:
# Standard LangChain invoke call
response = self.model.invoke(query)
return response.content
# Example for Local Ollama Model:
local_model = global_registry.get_model("local-chat")
local_response = local_model.invoke([
{"role": "user", "content": "How are you today?"}
])
print(local_response) # Returns direct text output
3. Image Generation (OpenAI DALL-E)
Register the DALL-E model and query it using the unified .invoke(prompt) interface. The wrapper handles both public URLs and base64 JSON responses (returning a Base64 data URI):
# Register DALL-E config
global_registry.register_model_config(
"dalle-gen",
ModelConfig(
provider="dalle",
model_name="dall-e-3", # or "dall-e-2" / "gpt-image-2"
extra_params={
"size": "1024x1024" # Optional size configuration
}
)
)
# Resolve and generate image
model = global_registry.get_model("dalle-gen")
image_uri = model.invoke("a beautiful mountain lake at sunrise")
print(image_uri) # Returns public URL or a base64 Data URI
Web Search Capabilities
Depending on the provider, you can enable web search capability natively (Gemini and OpenAI Responses API) or by binding a search tool (Groq, Anthropic, or OpenAI with external tools).
1. Google Gemini (Native Search Grounding)
Google Gemini models support native Google Search grounding directly at the API level (the API handles search internally and returns the final answer with citations):
global_registry.register_model_config(
"gemini-search",
ModelConfig(
provider="google",
model_name="gemini-2.5-flash",
extra_params={
"tools": [{"google_search": {}}]
}
)
)
model = global_registry.get_model("gemini-search")
response = model.invoke("Who won the Formula 1 race yesterday?")
print(response.content)
2. OpenAI Responses API Web Search
OpenAI supports native server-side web search through the Responses API. Enable it on OpenAIProvider with extra_params={"enable_web_search": True}:
from llm_registry import ModelConfig
from llm_registry.providers.openai import OpenAIProvider
provider = OpenAIProvider()
model = provider.create_model(
ModelConfig(
provider="openai",
model_name="gpt-4o-mini",
extra_params={"enable_web_search": True},
)
)
response = model.invoke("What is the current temperature in Nagpur today?")
print(response.content)
If you want to customize the tool list, pass extra_params={"tools": [...]}. If tools contains {"type": "web_search"}, the provider will automatically switch to the Responses API.
3. OpenAI / Anthropic / Groq (Using Free DuckDuckGo Tool)
If you want an external search tool instead of OpenAI's built-in search, you can still bind a free DuckDuckGo tool and run it inside a LangChain agent:
from langchain_community.tools import DuckDuckGoSearchRun
from langgraph.prebuilt import create_react_agent
# 1. Retrieve the standard model
model = global_registry.get_model("fast-chat")
# 2. Create the search tool
search_tool = DuckDuckGoSearchRun()
# 3. Create an agent combining the model and tool
agent = create_react_agent(model, tools=[search_tool])
# 4. Invoke the search agent
response = agent.invoke({"messages": [("user", "What is the stock price of Tesla today?")]})
print(response["messages"][-1].content)
Running Playground tests
An interactive chat test script is included under tests/chat_test.py to check your connections. Run it directly:
python tests/chat_test.py
Metadata
Release files for lighthouse-llm-registry 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lighthouse_llm_registry-0.1.5.tar.gz | 14.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lighthouse_llm_registry-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.7 kB
Release files / lighthouse_llm_registry-0.1.5.tar.gz
| Download URL | lighthouse_llm_registry-0.1.5.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
604d5c372594c7194b9394b1931ef1f0fd7c8215580c7021ad9e7367aedb6e53
|
|
BLAKE2b-256 checksum How to use checksums |
698f72fb233fccc498a9fc6f90736c9c5b8e2255cbacd62cd87dd14349b7681a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Release files / lighthouse_llm_registry-0.1.5-py3-none-any.whl
| Download URL | lighthouse_llm_registry-0.1.5-py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f5a2755c66f2b31904ff9186a2f6b71ba83492038da0d19c31ccb824bb04897c
|
|
BLAKE2b-256 checksum How to use checksums |
d655cfa0b2b068f6f2721361ae9e27fdeebbb15a696e1937002843a5c4bff801
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|