Compare commits

...
7 changed files with 29 additions and 29 deletions
+5 -5
View File
@@ -195,7 +195,7 @@ apt29_intel = context.retrieve(
```python ```python
from semantica.llms import LiteLLM from semantica.llms import LiteLLM
llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") llm = LiteLLM(model="anthropic/claude-sonnet-5")
result = context.query_with_reasoning( result = context.query_with_reasoning(
"What are APT29's known TTPs against healthcare infrastructure, " "What are APT29's known TTPs against healthcare infrastructure, "
@@ -281,7 +281,7 @@ context.store(
link_entities=True, link_entities=True,
) )
llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") llm = LiteLLM(model="anthropic/claude-sonnet-5")
result = context.query_with_reasoning( result = context.query_with_reasoning(
"Trace the C2 infrastructure chain for APT29 operations targeting " "Trace the C2 infrastructure chain for APT29 operations targeting "
"ITAR-controlled contractors in 2025. Include IP ranges, ASNs, and TTPs.", "ITAR-controlled contractors in 2025. Include IP ranges, ASNs, and TTPs.",
@@ -351,7 +351,7 @@ Parent: wmiprvse.exe
Sigma match: T1053.005 Scheduled Task/Job Sigma match: T1053.005 Scheduled Task/Job
""" """
llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") llm = LiteLLM(model="anthropic/claude-sonnet-5")
triage = soc_context.query_with_reasoning( triage = soc_context.query_with_reasoning(
"Triage this SIEM alert and identify the correct response runbook:\n{}".format(alert_text), "Triage this SIEM alert and identify the correct response runbook:\n{}".format(alert_text),
llm_provider=llm, llm_provider=llm,
@@ -425,7 +425,7 @@ Patient: 68F, AF, CKD stage 3b (eGFR 32). On warfarin (INR target 2.03.0).
Presenting for elective hip replacement. Concurrent: amiodarone 200mg, atorvastatin 40mg. Presenting for elective hip replacement. Concurrent: amiodarone 200mg, atorvastatin 40mg.
""" """
llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") llm = LiteLLM(model="anthropic/claude-sonnet-5")
answer = clinical_context.query_with_reasoning( answer = clinical_context.query_with_reasoning(
"What is the evidence-based warfarin bridging protocol for this patient " "What is the evidence-based warfarin bridging protocol for this patient "
"given CKD and amiodarone interaction risk?\n\n{}".format(patient_context), "given CKD and amiodarone interaction risk?\n\n{}".format(patient_context),
@@ -495,7 +495,7 @@ compliance_context.store(
extract_relationships=True, extract_relationships=True,
) )
llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") llm = LiteLLM(model="anthropic/claude-sonnet-5")
answer = compliance_context.query_with_reasoning( answer = compliance_context.query_with_reasoning(
"Under Basel III CRE20, what are the RWA calculation requirements for " "Under Basel III CRE20, what are the RWA calculation requirements for "
"commercial real estate exposures with LTV > 80%? " "commercial real estate exposures with LTV > 80%? "
+8 -8
View File
@@ -275,20 +275,20 @@ print(data)
**LiteLLM** is a universal adapter that provides a single interface to over 100 different LLM providers, including Anthropic Claude, Azure OpenAI, AWS Bedrock, Google Vertex AI, and local Ollama instances. It acts as a translation layer, converting your unified API calls into provider-specific requests, enabling easy switching between providers without code changes. **LiteLLM** is a universal adapter that provides a single interface to over 100 different LLM providers, including Anthropic Claude, Azure OpenAI, AWS Bedrock, Google Vertex AI, and local Ollama instances. It acts as a translation layer, converting your unified API calls into provider-specific requests, enabling easy switching between providers without code changes.
`LiteLLM` is the Swiss Army knife. It wraps the `litellm` library, which speaks to every major provider using a unified completion API. The model string encodes both provider and model name: `"anthropic/claude-sonnet-4-20250514"`, `"azure/gpt-4o"`, `"bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0"`, `"ollama/llama3.2"`. Change the string, change the provider — no other code changes needed. `LiteLLM` is the Swiss Army knife. It wraps the `litellm` library, which speaks to every major provider using a unified completion API. The model string encodes both provider and model name: `"anthropic/claude-sonnet-5"`, `"azure/gpt-4o"`, `"bedrock/anthropic.claude-sonnet-4-5-20250929-v1:0"`, `"ollama/llama3.2"`. Change the string, change the provider — no other code changes needed.
```python ```python
from semantica.llms import LiteLLM from semantica.llms import LiteLLM
# Anthropic Claude — highest accuracy for complex reasoning # Anthropic Claude — highest accuracy for complex reasoning
llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") llm = LiteLLM(model="anthropic/claude-sonnet-5")
# Reads ANTHROPIC_API_KEY from environment # Reads ANTHROPIC_API_KEY from environment
# Azure OpenAI — compliance and data-residency requirements # Azure OpenAI — compliance and data-residency requirements
llm = LiteLLM(model="azure/gpt-4o", api_key="YOUR_AZURE_KEY") llm = LiteLLM(model="azure/gpt-4o", api_key="YOUR_AZURE_KEY")
# AWS Bedrock — existing cloud agreement, no new vendor # AWS Bedrock — existing cloud agreement, no new vendor
llm = LiteLLM(model="bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0") llm = LiteLLM(model="bedrock/anthropic.claude-sonnet-4-5-20250929-v1:0")
# Google Vertex AI # Google Vertex AI
llm = LiteLLM(model="vertex_ai/gemini-1.5-pro") llm = LiteLLM(model="vertex_ai/gemini-1.5-pro")
@@ -306,7 +306,7 @@ The environment-variable convention for each provider: `ANTHROPIC_API_KEY`, `AZU
import os import os
PROVIDER_MAP = { PROVIDER_MAP = {
"prod": "anthropic/claude-sonnet-4-20250514", "prod": "anthropic/claude-sonnet-5",
"staging": "openai/gpt-4o-mini", "staging": "openai/gpt-4o-mini",
"local": "ollama/llama3.2", "local": "ollama/llama3.2",
"azure": "azure/gpt-4o", "azure": "azure/gpt-4o",
@@ -378,7 +378,7 @@ print("FAST: {} (conf={:.0%})".format(fast_result["response"], fast_result["con
# Tier 2: deep answer with Claude if confidence is below threshold # Tier 2: deep answer with Claude if confidence is below threshold
if fast_result["confidence"] < 0.85: if fast_result["confidence"] < 0.85:
deep_llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") deep_llm = LiteLLM(model="anthropic/claude-sonnet-5")
deep_result = context.query_with_reasoning( deep_result = context.query_with_reasoning(
query, llm_provider=deep_llm, max_results=15, max_hops=3 query, llm_provider=deep_llm, max_results=15, max_hops=3
) )
@@ -574,7 +574,7 @@ print("TRIAGE: {} (conf={:.0%})".format(triage["response"], triage["confidence"]
# Tier 2: escalate to Claude for deep analysis if Tier 1 is uncertain # Tier 2: escalate to Claude for deep analysis if Tier 1 is uncertain
if triage["confidence"] < 0.88: if triage["confidence"] < 0.88:
deep_llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") deep_llm = LiteLLM(model="anthropic/claude-sonnet-5")
deep = context.query_with_reasoning( deep = context.query_with_reasoning(
"Full MITRE ATT&CK analysis of this alert: identify the attack chain, " "Full MITRE ATT&CK analysis of this alert: identify the attack chain, "
"blast radius, affected systems, and recommended containment steps.", "blast radius, affected systems, and recommended containment steps.",
@@ -630,7 +630,7 @@ for d in drugs:
# trastuzumab (conf=0.98), pertuzumab (conf=0.97), docetaxel (conf=0.96) # trastuzumab (conf=0.98), pertuzumab (conf=0.97), docetaxel (conf=0.96)
# Report synthesis with Claude — switch to azure/gpt-4o for HIPAA by changing one string # Report synthesis with Claude — switch to azure/gpt-4o for HIPAA by changing one string
report_llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") report_llm = LiteLLM(model="anthropic/claude-sonnet-5")
# For HIPAA-constrained Azure deployment: # For HIPAA-constrained Azure deployment:
# report_llm = LiteLLM(model="azure/gpt-4o", api_key="YOUR_AZURE_KEY") # report_llm = LiteLLM(model="azure/gpt-4o", api_key="YOUR_AZURE_KEY")
@@ -682,7 +682,7 @@ question = (
# Two-provider consensus — same query, same graph, different LLMs # Two-provider consensus — same query, same graph, different LLMs
gpt4o = OpenAI(model="gpt-4o", api_key="YOUR_OAI_KEY") gpt4o = OpenAI(model="gpt-4o", api_key="YOUR_OAI_KEY")
claude = LiteLLM(model="anthropic/claude-sonnet-4-20250514") claude = LiteLLM(model="anthropic/claude-sonnet-5")
answer_a = context.query_with_reasoning(question, llm_provider=gpt4o, max_results=10) answer_a = context.query_with_reasoning(question, llm_provider=gpt4o, max_results=10)
answer_b = context.query_with_reasoning(question, llm_provider=claude, max_results=10) answer_b = context.query_with_reasoning(question, llm_provider=claude, max_results=10)
+4 -4
View File
@@ -197,7 +197,7 @@ reasoning_agent.load("./pipeline/enriched_intel/")
# All memories, graph nodes, and vector embeddings from both ingestion agents are now available. # All memories, graph nodes, and vector embeddings from both ingestion agents are now available.
# Use a high-capability model for the synthesis step # Use a high-capability model for the synthesis step
llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") llm = LiteLLM(model="anthropic/claude-sonnet-5")
synthesis = reasoning_agent.query_with_reasoning( synthesis = reasoning_agent.query_with_reasoning(
"Summarize the APT29 exploitation of CVE-2024-3400: affected products, " "Summarize the APT29 exploitation of CVE-2024-3400: affected products, "
@@ -428,7 +428,7 @@ tier1.store(
# --- Tier 2: deep investigation when Tier 1 confidence is low --- # --- Tier 2: deep investigation when Tier 1 confidence is low ---
if triage["confidence"] < 0.90: if triage["confidence"] < 0.90:
deep_llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") deep_llm = LiteLLM(model="anthropic/claude-sonnet-5")
investigation = tier2.query_with_reasoning( investigation = tier2.query_with_reasoning(
"Full MITRE ATT&CK analysis of incident {}. " "Full MITRE ATT&CK analysis of incident {}. "
@@ -533,7 +533,7 @@ t1.start(); t2.start()
t1.join(); t2.join() t1.join(); t2.join()
# Chief agent synthesizes across literature and experimental data # Chief agent synthesizes across literature and experimental data
llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") llm = LiteLLM(model="anthropic/claude-sonnet-5")
synthesis = chief.query_with_reasoning( synthesis = chief.query_with_reasoning(
"Identify the top two candidate compounds for KRAS G12C NSCLC that show " "Identify the top two candidate compounds for KRAS G12C NSCLC that show "
@@ -576,7 +576,7 @@ credit_officer = make_desk_agent()
committee_chair = make_desk_agent() committee_chair = make_desk_agent()
app_id = "LOAN-2025-88421" app_id = "LOAN-2025-88421"
llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") llm = LiteLLM(model="anthropic/claude-sonnet-5")
# --- Risk Desk: PD/LGD/EL analysis --- # --- Risk Desk: PD/LGD/EL analysis ---
risk_desk.store( risk_desk.store(
+1 -1
View File
@@ -477,7 +477,7 @@ regs = [
] ]
# Use an LLM to extract the conceptual model from regulatory prose # Use an LLM to extract the conceptual model from regulatory prose
llm_gen = LLMOntologyGenerator(provider="anthropic", model="claude-sonnet-4-20250514") llm_gen = LLMOntologyGenerator(provider="anthropic", model="claude-sonnet-5")
ontology = llm_gen.generate_ontology_from_text( ontology = llm_gen.generate_ontology_from_text(
"\n\n".join(r.text[:8000] for r in regs) # token-safe excerpt per document "\n\n".join(r.text[:8000] for r in regs) # token-safe excerpt per document
) )
+7 -7
View File
@@ -129,7 +129,7 @@ from semantica.llms import Groq, OpenAI, LiteLLM, HuggingFaceLLM
from semantica.llms import LiteLLM from semantica.llms import LiteLLM
llm = LiteLLM( llm = LiteLLM(
model="anthropic/claude-sonnet-4-20250514", model="anthropic/claude-sonnet-5",
api_key=os.getenv("ANTHROPIC_API_KEY"), api_key=os.getenv("ANTHROPIC_API_KEY"),
temperature=0.0, temperature=0.0,
) )
@@ -198,7 +198,7 @@ llm = Groq(api_key=os.getenv("GROQ_API_KEY"), model="llama-3.1-8b-instant")
# Method 3: Multiple providers via LiteLLM # Method 3: Multiple providers via LiteLLM
providers = { providers = {
"fast": LiteLLM(model="groq/llama-3.1-8b-instant", api_key=os.getenv("GROQ_API_KEY")), "fast": LiteLLM(model="groq/llama-3.1-8b-instant", api_key=os.getenv("GROQ_API_KEY")),
"smart": LiteLLM(model="anthropic/claude-sonnet-4-20250514", api_key=os.getenv("ANTHROPIC_API_KEY")) "smart": LiteLLM(model="anthropic/claude-sonnet-5", api_key=os.getenv("ANTHROPIC_API_KEY"))
} }
``` ```
@@ -252,7 +252,7 @@ from semantica.llms import LiteLLM
# pip install "semantica[llm-litellm]" # pip install "semantica[llm-litellm]"
# Anthropic Claude # Anthropic Claude
llm = LiteLLM(model="anthropic/claude-opus-4-5", api_key=os.getenv("ANTHROPIC_API_KEY")) llm = LiteLLM(model="anthropic/claude-opus-4-7", api_key=os.getenv("ANTHROPIC_API_KEY"))
# Google Gemini # Google Gemini
llm = LiteLLM(model="gemini/gemini-1.5-pro", api_key=os.getenv("GOOGLE_API_KEY")) llm = LiteLLM(model="gemini/gemini-1.5-pro", api_key=os.getenv("GOOGLE_API_KEY"))
@@ -267,7 +267,7 @@ llm = LiteLLM(model="deepseek/deepseek-chat", api_key=os.getenv("DEEP
llm = LiteLLM(model="azure/gpt-4o", api_key=os.getenv("AZURE_API_KEY")) llm = LiteLLM(model="azure/gpt-4o", api_key=os.getenv("AZURE_API_KEY"))
# AWS Bedrock # AWS Bedrock
llm = LiteLLM(model="bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0") llm = LiteLLM(model="bedrock/anthropic.claude-sonnet-4-5-20250929-v1:0")
# Novita AI # Novita AI
llm = LiteLLM(model="novita/deepseek/deepseek-v3.2", api_key=os.getenv("NOVITA_API_KEY")) llm = LiteLLM(model="novita/deepseek/deepseek-v3.2", api_key=os.getenv("NOVITA_API_KEY"))
@@ -297,12 +297,12 @@ from semantica.llms import LiteLLM
# Pattern: LiteLLM(model="<provider>/<model-name>") # Pattern: LiteLLM(model="<provider>/<model-name>")
providers = { providers = {
"Anthropic": LiteLLM(model="anthropic/claude-opus-4-5", api_key=os.getenv("ANTHROPIC_API_KEY")), "Anthropic": LiteLLM(model="anthropic/claude-opus-4-7", api_key=os.getenv("ANTHROPIC_API_KEY")),
"Gemini": LiteLLM(model="gemini/gemini-1.5-pro", api_key=os.getenv("GOOGLE_API_KEY")), "Gemini": LiteLLM(model="gemini/gemini-1.5-pro", api_key=os.getenv("GOOGLE_API_KEY")),
"Ollama": LiteLLM(model="ollama/llama3.2:3b", api_base="http://localhost:11434"), "Ollama": LiteLLM(model="ollama/llama3.2:3b", api_base="http://localhost:11434"),
"DeepSeek": LiteLLM(model="deepseek/deepseek-chat", api_key=os.getenv("DEEPSEEK_API_KEY")), "DeepSeek": LiteLLM(model="deepseek/deepseek-chat", api_key=os.getenv("DEEPSEEK_API_KEY")),
"Azure": LiteLLM(model="azure/gpt-4o", api_key=os.getenv("AZURE_API_KEY")), "Azure": LiteLLM(model="azure/gpt-4o", api_key=os.getenv("AZURE_API_KEY")),
"Bedrock": LiteLLM(model="bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0"), "Bedrock": LiteLLM(model="bedrock/anthropic.claude-sonnet-4-5-20250929-v1:0"),
"Cohere": LiteLLM(model="cohere/command-r-plus", api_key=os.getenv("COHERE_API_KEY")), "Cohere": LiteLLM(model="cohere/command-r-plus", api_key=os.getenv("COHERE_API_KEY")),
"Novita AI": LiteLLM(model="novita/deepseek/deepseek-v3.2", api_key=os.getenv("NOVITA_API_KEY")), "Novita AI": LiteLLM(model="novita/deepseek/deepseek-v3.2", api_key=os.getenv("NOVITA_API_KEY")),
} }
@@ -416,7 +416,7 @@ for text in texts:
| :---------- | :--------------------------- | :----------- | | :---------- | :--------------------------- | :----------- |
| **Entity Extraction** | `Groq("llama-3.3-70b-versatile")` | Fast, good accuracy for structured tasks | | **Entity Extraction** | `Groq("llama-3.3-70b-versatile")` | Fast, good accuracy for structured tasks |
| **Relation Extraction** | `OpenAI("gpt-4o")` | Best at complex relationship reasoning | | **Relation Extraction** | `OpenAI("gpt-4o")` | Best at complex relationship reasoning |
| **Complex Analysis** | `LiteLLM("anthropic/claude-sonnet-4-20250514")` | Highest reasoning capability | | **Complex Analysis** | `LiteLLM("anthropic/claude-sonnet-5")` | Highest reasoning capability |
| **High Volume/Cost** | `LiteLLM("deepseek/deepseek-chat")` | Lowest cost per token | | **High Volume/Cost** | `LiteLLM("deepseek/deepseek-chat")` | Lowest cost per token |
### Error Handling ### Error Handling
+1 -1
View File
@@ -35,7 +35,7 @@ Example Usage:
>>> llm = LiteLLM(model="openai/gpt-4o", api_key="your-key") >>> llm = LiteLLM(model="openai/gpt-4o", api_key="your-key")
>>> response = llm.generate("Hello, world!") >>> response = llm.generate("Hello, world!")
>>> # Or use other providers via LiteLLM >>> # Or use other providers via LiteLLM
>>> llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") >>> llm = LiteLLM(model="anthropic/claude-sonnet-5")
>>> response = llm.generate("Hello, world!") >>> response = llm.generate("Hello, world!")
>>> >>>
>>> # Anthropic provider >>> # Anthropic provider
+3 -3
View File
@@ -31,7 +31,7 @@ class LiteLLM:
Provides unified interface to 100+ LLM providers through LiteLLM library. Provides unified interface to 100+ LLM providers through LiteLLM library.
Supports providers like OpenAI, Anthropic, Groq, Azure, Bedrock, Vertex AI, etc. Supports providers like OpenAI, Anthropic, Groq, Azure, Bedrock, Vertex AI, etc.
Model format: "provider/model-name" (e.g., "openai/gpt-4o", "anthropic/claude-sonnet-4-20250514", "groq/llama-3.1-8b-instant") Model format: "provider/model-name" (e.g., "openai/gpt-4o", "anthropic/claude-sonnet-5", "groq/llama-3.1-8b-instant")
Example: Example:
>>> from semantica.llms import LiteLLM >>> from semantica.llms import LiteLLM
@@ -39,7 +39,7 @@ class LiteLLM:
>>> response = llm.generate("What is AI?") >>> response = llm.generate("What is AI?")
>>> >>>
>>> # Use with different providers >>> # Use with different providers
>>> llm = LiteLLM(model="anthropic/claude-sonnet-4-20250514") >>> llm = LiteLLM(model="anthropic/claude-sonnet-5")
>>> response = llm.generate("Hello!") >>> response = llm.generate("Hello!")
""" """
@@ -54,7 +54,7 @@ class LiteLLM:
Args: Args:
model: Model identifier in format "provider/model-name" model: Model identifier in format "provider/model-name"
Examples: "openai/gpt-4o", "anthropic/claude-sonnet-4-20250514", Examples: "openai/gpt-4o", "anthropic/claude-sonnet-5",
"groq/llama-3.1-8b-instant", "azure/gpt-4", etc. "groq/llama-3.1-8b-instant", "azure/gpt-4", etc.
api_key: API key (optional, can use environment variables) api_key: API key (optional, can use environment variables)
**kwargs: Additional LiteLLM options (temperature, max_tokens, etc.) **kwargs: Additional LiteLLM options (temperature, max_tokens, etc.)