Skip to content
GitHub

Quickstart

Terminal window
uv add lexigram-ai
# Or with pip
pip install lexigram-ai

lexigram-ai depends on lexigram, lexigram-contracts, lexigram-ai-llm, lexigram-ai-rag, lexigram-ai-feedback, and lexigram-ai-observability.

import asyncio
from lexigram import Application
from lexigram.ai.module import AIModule
from lexigram.ai.llm import ClientConfig
async def main() -> None:
config = AIConfig(
llm=ClientConfig(
provider="openai",
model="gpt-4o",
api_key="sk-...",
),
)
async with Application.boot(
name="ai-demo",
modules=[AIModule.configure(config)],
) as app:
# LLMClientProtocol is now injectable
from lexigram.contracts.ai import LLMClientProtocol
llm = await app.container.resolve(LLMClientProtocol)
result = await llm.complete([{"role": "user", "content": "Say hello!"}])
if result.is_ok():
print(result.unwrap().content)
else:
print(f"Error: {result.unwrap_err()}")
asyncio.run(main())

AIModule.configure(config) registers the AIProvider which wires:

  • LLM — multi-provider client (OpenAI, Anthropic, Ollama, Groq, Mistral, …)
  • Vector — vector store backends (optional, requires lexigram-vector)
  • RAG — retrieval-augmented generation pipelines (optional)
  • Observability — AI tracing, metrics, and health monitoring
  • Governance — audit logging and policy enforcement (optional)
  • Guide — mental model, core concepts, end-to-end workflows
  • Architecture — provider composition and entry-point discovery
  • Configuration — all config keys and env-var overrides
  • Ecosystem — related AI packages