mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-09-10 04:00:35 +00:00
- Migrate from mint.json to docs.json (Mintlify v4) - Theme: maple, emerald green + near-black dark / cream light palette (#059669 primary, #0A0A0A dark bg, #FAF7F0 light bg) - Typography: Lexend headings, Inter body - 5-tab navigation: Documentation, Quick Start, API Reference, Cookbook, FAQ - Homepage: removed badge stickers, redundant h2, added blockquote tagline, full 27-module reference table with semantica.mcp_server added - quickstart.md: CodeGroup per pipeline step, pattern vs LLM options, AccordionGroup for patterns and troubleshooting - faq.md: full AccordionGroup structure across 5 sections - reference/explorer.md: NEW — FastAPI explorer, Ontology Hub, Distance Intelligence, CLI reference, REST API endpoints - reference/mcp_server.md: NEW — MCP stdio server, 12 tools with I/O examples, 3 resources, Claude Desktop/VS Code/Windsurf/Cline config - docs.json: explorer added to Output group, mcp_server to Utilities group - Chat, feedback (thumbs/suggest/raise), OG/Twitter metadata, search topbar - All reference pages reformatted with Mintlify JSX components Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
202 lines
5.3 KiB
Markdown
202 lines
5.3 KiB
Markdown
---
|
|
title: "LLMs Module"
|
|
description: "Unified interface for Groq, OpenAI, Anthropic, Gemini, Ollama, DeepSeek, Novita AI, LiteLLM, and HuggingFace."
|
|
icon: "microchip"
|
|
---
|
|
|
|
The `semantica.llms` module provides a single consistent API across 8+ LLM providers. All providers are drop-in replacements for `llm_provider=` in extractors, reasoning engines, and agents.
|
|
|
|
---
|
|
|
|
## Providers
|
|
|
|
<CodeGroup>
|
|
|
|
```python Groq
|
|
from semantica.llms import Groq
|
|
import os
|
|
|
|
llm = Groq(
|
|
model="llama-3.3-70b-versatile", # default
|
|
api_key=os.getenv("GROQ_API_KEY"),
|
|
max_tokens=64000,
|
|
temperature=0.0,
|
|
)
|
|
# Best for: high-throughput extraction, fast inference
|
|
```
|
|
|
|
```python OpenAI
|
|
from semantica.llms import OpenAI
|
|
import os
|
|
|
|
# pip install "semantica[llm-openai]"
|
|
llm = OpenAI(
|
|
model="gpt-4o",
|
|
api_key=os.getenv("OPENAI_API_KEY"),
|
|
temperature=0.0,
|
|
)
|
|
# Best for: general purpose, function calling
|
|
```
|
|
|
|
```python Anthropic
|
|
from semantica.llms import Anthropic
|
|
import os
|
|
|
|
# pip install "semantica[llm-anthropic]"
|
|
llm = Anthropic(
|
|
model="claude-opus-4-7",
|
|
api_key=os.getenv("ANTHROPIC_API_KEY"),
|
|
max_tokens=8192,
|
|
)
|
|
# Best for: complex reasoning, long context, safety
|
|
```
|
|
|
|
```python Gemini
|
|
from semantica.llms import Gemini
|
|
import os
|
|
|
|
# pip install "semantica[llm-gemini]"
|
|
llm = Gemini(
|
|
model="gemini-1.5-pro",
|
|
api_key=os.getenv("GOOGLE_API_KEY"),
|
|
)
|
|
# Best for: long context, multimodal tasks
|
|
```
|
|
|
|
```python Ollama (Local)
|
|
from semantica.llms import Ollama
|
|
|
|
# pip install "semantica[llm-ollama]"
|
|
llm = Ollama(
|
|
model="llama3.2:3b",
|
|
base_url="http://localhost:11434",
|
|
)
|
|
# Best for: local inference, air-gapped environments
|
|
# No API key required
|
|
```
|
|
|
|
```python DeepSeek
|
|
from semantica.llms import DeepSeek
|
|
import os
|
|
|
|
llm = DeepSeek(
|
|
model="deepseek-chat",
|
|
api_key=os.getenv("DEEPSEEK_API_KEY"),
|
|
)
|
|
# Best for: coding tasks, analysis at low cost
|
|
```
|
|
|
|
```python LiteLLM (100+ models)
|
|
from semantica.llms import LiteLLM
|
|
import os
|
|
|
|
# pip install "semantica[llm-litellm]"
|
|
llm = LiteLLM(
|
|
model="gpt-4o", # any LiteLLM-supported model string
|
|
api_key=os.getenv("OPENAI_API_KEY"),
|
|
)
|
|
# Supports: OpenAI, Anthropic, Gemini, Cohere, Azure, Bedrock, and 90+ more
|
|
```
|
|
|
|
```python HuggingFace (BYOM)
|
|
from semantica.llms import HuggingFace
|
|
|
|
llm = HuggingFace(
|
|
model="mistralai/Mistral-7B-Instruct-v0.3",
|
|
device="cuda", # "cpu" | "cuda" | "mps"
|
|
max_new_tokens=512,
|
|
temperature=0.1,
|
|
)
|
|
# Bring your own model — full local control
|
|
```
|
|
|
|
</CodeGroup>
|
|
|
|
---
|
|
|
|
## Provider Factory
|
|
|
|
```python
|
|
from semantica.llms import create_provider
|
|
|
|
llm = create_provider("groq", model="llama-3.3-70b-versatile")
|
|
llm = create_provider("openai", model="gpt-4o")
|
|
llm = create_provider("anthropic", model="claude-opus-4-7")
|
|
llm = create_provider("gemini", model="gemini-1.5-pro")
|
|
llm = create_provider("ollama", model="llama3.2")
|
|
llm = create_provider("deepseek", model="deepseek-chat", api_key=os.getenv("DEEPSEEK_API_KEY"))
|
|
llm = create_provider("novita", model="deepseek/deepseek-v3.2", api_key=os.getenv("NOVITA_API_KEY"))
|
|
llm = create_provider("litellm", model="gpt-4o")
|
|
```
|
|
|
|
---
|
|
|
|
## Custom / Enterprise Gateways
|
|
|
|
Any OpenAI-compatible gateway — internal routing layers, Qwen proxies, LLaMA proxies:
|
|
|
|
```python
|
|
from semantica.llms import OpenAI
|
|
|
|
llm = OpenAI(
|
|
model="qwen2.5-72b",
|
|
api_key=os.getenv("GATEWAY_API_KEY"),
|
|
base_url="https://my-internal-gateway.company.com/v1",
|
|
)
|
|
```
|
|
|
|
<Note>
|
|
`base_url` is validated at construction time. Non-HTTP(S) schemes raise `ValueError` to prevent SSRF attacks (fixed in v0.5.0).
|
|
</Note>
|
|
|
|
---
|
|
|
|
## Using in Extractors
|
|
|
|
```python
|
|
from semantica.semantic_extract import NERExtractor, RelationExtractor, TripletExtractor
|
|
|
|
ner = NERExtractor(method="llm", llm_provider=llm, max_retries=3)
|
|
rel = RelationExtractor(method="llm", llm_provider=llm)
|
|
trip = TripletExtractor(method="llm", llm_provider=llm)
|
|
```
|
|
|
|
---
|
|
|
|
## Provider Comparison
|
|
|
|
| Provider | Speed | Cost | Local | Context | Best for |
|
|
|----------|-------|------|-------|---------|----------|
|
|
| Groq | Very fast | Low | No | 128k | High-throughput extraction |
|
|
| OpenAI | Fast | Medium | No | 128k | General purpose, function calling |
|
|
| Anthropic | Fast | Medium | No | 200k | Complex reasoning, safety |
|
|
| Gemini | Fast | Low | No | 1M | Long context, multimodal |
|
|
| Ollama | Medium | Free | Yes | Varies | Privacy, no API key |
|
|
| DeepSeek | Fast | Very low | No | 64k | Coding, analysis |
|
|
| Novita AI | Fast | Low | No | Varies | DeepSeek-based tasks |
|
|
| LiteLLM | Varies | Varies | Varies | Varies | Multi-provider routing |
|
|
| HuggingFace | Slow | Free | Yes | Varies | Custom models, BYOM |
|
|
|
|
<Tip>
|
|
For production systems, Groq delivers the best throughput-to-cost ratio for extraction pipelines. For complex multi-hop reasoning tasks, Claude Opus or GPT-4o provide the highest accuracy.
|
|
</Tip>
|
|
|
|
---
|
|
|
|
## See Also
|
|
|
|
<CardGroup cols={2}>
|
|
<Card title="Semantic Extract" icon="magnifying-glass" href="semantic_extract">
|
|
Use LLMs for NER and relation extraction.
|
|
</Card>
|
|
<Card title="Agno Integration" icon="robot" href="../integrations/agno">
|
|
LLM providers in Agno multi-agent teams.
|
|
</Card>
|
|
<Card title="Reasoning" icon="brain" href="reasoning">
|
|
LLM-backed deductive and abductive reasoning.
|
|
</Card>
|
|
<Card title="Context" icon="diagram-project" href="context">
|
|
GraphRAG uses LLMs for reasoning over knowledge graphs.
|
|
</Card>
|
|
</CardGroup>
|