Skip to content

Commit ec05822

Browse files
authored
Merge pull request #101 from IBM/99-openai-lite-llm-connection
LiteLLM AI Gateway support
2 parents 378e4f9 + f88dd83 commit ec05822

File tree

15 files changed

+1139
-149
lines changed

15 files changed

+1139
-149
lines changed

.env_sample

Lines changed: 121 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,135 @@
1-
## Set to any of the following values: gemini, openai, watsonx
2-
## You'll need to set corresponding APIKeys below to use the selected LLM
1+
################################################################################
2+
# AGENTICS LLM CONFIGURATION
3+
################################################################################
4+
# This file contains all the environment variables needed to configure LLM
5+
# providers for use with Agentics. All LLM providers are optional - configure
6+
# only the ones you need. The system will auto-discover which LLMs are available
7+
# based on the environment variables present.
8+
################################################################################
39

4-
SELECTED_LLM = "gemini"
510

6-
## GEMINI
11+
################################################################################
12+
# GEMINI (Optional)
13+
################################################################################
714
GEMINI_API_KEY=
8-
GEMINI_MODEL_ID= "gemini/gemini-2.0-flash"
15+
GEMINI_MODEL_ID="gemini/gemini-2.0-flash"
916

1017

11-
## Set one of the following LLM providers before using agentics
12-
## WatsonX AI credentials (Optional)
18+
################################################################################
19+
# OPENAI (Optional)
20+
################################################################################
21+
OPENAI_API_KEY=
22+
OPENAI_MODEL_ID="openai/gpt-4"
23+
24+
25+
################################################################################
26+
# OPENAI-COMPATIBLE LLMs (Optional)
27+
#
28+
# Configure OpenAI-compatible API providers with custom prefixes.
29+
#
30+
# Supported patterns:
31+
# - Default variant: OPENAI_COMPATIBLE_*
32+
# - Custom variants: OPENAI_COMPATIBLE_<VARIANT>_*
33+
#
34+
# Each variant requires three variables:
35+
# - <PREFIX>_API_KEY: Your API key
36+
# - <PREFIX>_MODEL_ID: The model identifier
37+
# - <PREFIX>_BASE_URL: The base URL of the API
38+
#
39+
# Examples:
40+
################################################################################
41+
42+
# Default OpenAI-compatible variant
43+
OPENAI_COMPATIBLE_API_KEY=
44+
OPENAI_COMPATIBLE_MODEL_ID=
45+
OPENAI_COMPATIBLE_BASE_URL=
46+
47+
48+
################################################################################
49+
# WATSONX (Optional)
50+
################################################################################
1351
MODEL_ID=watsonx/meta-llama/llama-3-3-70b-instruct
14-
WATSONX_URL=https://us-south.ml.cloud.ibm.com
52+
WATSONX_URL=https://us-south.ml.cloud.ibm.com
1553
WATSONX_APIKEY=
1654
WATSONX_PROJECTID=
1755

18-
## OpenAI credentials (Optional)
19-
OPENAI_API_KEY=
20-
OPENAI_MODEL_ID="openai/gpt-4"
2156

22-
## VLLM (Optional)
23-
VLLM_URL=<http://base_url:PORT/v1>
24-
VLLM_MODEL_ID="hosted_vllm/meta-llama/Llama-3.3-70B-Instruct"
57+
################################################################################
58+
# VLLM - vLLM Server (Optional)
59+
#
60+
# vLLM is an open-source LLM serving framework.
61+
# Configure if you have a vLLM server running locally or remotely.
62+
################################################################################
63+
64+
# Required: vLLM server URL
65+
VLLM_URL=http://localhost:8000/v1
66+
67+
# Optional: Specific model ID for vLLM
68+
VLLM_MODEL_ID="meta-llama/Llama-3.3-70B-Instruct"
69+
70+
71+
################################################################################
72+
# OLLAMA (Optional)
73+
#
74+
# Ollama is an open-source LLM runner that can run models locally.
75+
# Configure if you have Ollama installed and running.
76+
################################################################################
77+
78+
# The model to use with Ollama
79+
# OLLAMA_MODEL_ID="deepseek-r1:latest"
80+
# OLLAMA_MODEL_ID="llama2:latest"
81+
# OLLAMA_MODEL_ID="mistral:latest"
82+
83+
84+
################################################################################
85+
# LITELLM (Optional)
86+
#
87+
# LiteLLM provides access to 100+ LLM providers through a unified interface.
88+
# Use model format: "litellm/provider/model-name"
89+
# See: https://docs.litellm.ai/docs/providers
90+
################################################################################
91+
92+
# Model in format: litellm/provider/model-name
93+
# LITELLM_MODEL="litellm/openai/gpt-4"
94+
# LITELLM_MODEL="litellm/anthropic/claude-3-sonnet"
95+
# LITELLM_MODEL="litellm/cohere/command-r"
96+
97+
# Optional temperature and top_p settings
98+
# LITELLM_TEMPERATURE=0.8
99+
# LITELLM_TOP_P=0.9
100+
101+
102+
################################################################################
103+
# LITELLM PROXY (Optional)
104+
#
105+
# LiteLLM Proxy allows you to run a local proxy server that manages API keys
106+
# and provides a unified interface for multiple LLM providers. In some
107+
# organizations this also provides a way to centralize frontier LLM
108+
# access to employees.
109+
#
110+
################################################################################
111+
112+
# Required: Proxy server URL (typically http://localhost:4000 if running locally, or
113+
https://litellm.your.organization/, no v1)
114+
# LITELLM_PROXY_URL=http://localhost:4000
25115

26-
## OLLAMA (Optional)
27-
OLLAMA_MODEL_ID="ollama/deepseek-r1:latest"
116+
# Required: API key for proxy authentication
117+
# LITELLM_PROXY_API_KEY=
28118

119+
################################################################################
120+
# Models
121+
# Once you've defined the above environment variables, you can run this command
122+
# to check the available models.
123+
# uvx --from litellm[proxy] litellm-proxy models list
124+
#
125+
# This command will display all available models configured on your proxy.
126+
################################################################################
29127

30-
#### CrewAI
128+
# Required: Model name in format: litellm_proxy/<model_name>
129+
# Must start with "litellm_proxy/"
130+
# LITELLM_PROXY_MODEL="litellm_proxy/gpt-4"
131+
# LITELLM_PROXY_MODEL="litellm_proxy/claude-3-sonnet"
31132

32-
CREWAI_DISABLE_TELEMETRY=true
33-
CREWAI_DISABLE_TRACING=true
34-
CREWAI_TELEMETRY=false
35-
OTEL_SDK_DISABLED=true
36-
CREWAI_TRACING_DISABLED=true
37-
CREWAI_SILENT=true
38-
AGENTICS_TRACE_MODE="off"
133+
# Optional temperature and top_p settings
134+
# LITELLM_PROXY_TEMPERATURE=0.8
135+
# LITELLM_PROXY_TOP_P=0.9

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ __*__/
4040
_[a-z]*.py
4141
invoke.json
4242
invoke.y*ml
43+
# Igore profiling flamegraphs
44+
profile*.svg

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ repos:
1919
# # when "--baseline" with "--use-all-plugins", pre-commit scan with all available plugins
2020
# # add "--fail-on-unaudited" to fail pre-commit for unaudited potential secrets
2121
# args: [--baseline, .secrets.baseline, --use-all-plugins]
22-
2322

2423
# - repo: https://github.com/astral-sh/ruff-pre-commit
2524
# # Ruff version.
@@ -45,13 +44,14 @@ repos:
4544
- repo: https://github.com/pre-commit/pre-commit-hooks
4645
rev: v5.0.0
4746
hooks:
48-
- id: trailing-whitespace
49-
exclude: 'docs/.*|\.*.lock|'
50-
- id: check-ast
51-
- id: end-of-file-fixer
47+
- id: trailing-whitespace
48+
exclude: 'docs/.*|\.*.lock|data/.*|tutorials/data/.*'
49+
- id: check-ast
50+
- id: end-of-file-fixer
51+
exclude: "data/.*|tutorials/data/.*"
5252
exclude_types:
5353
- svg
54-
- id: debug-statements
54+
- id: debug-statements
5555
# TODO: Fix this
5656
# - id: name-tests-test
5757

docs/getting_started.md

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,80 @@ ollama pull ollama/deepseek-r1:latest
7272
- `VLLM_URL` - <http://base_url:PORT/v1>
7373
- `VLLM_MODEL_ID` - Your model id (e.g. "hosted_vllm/meta-llama/Llama-3.3-70B-Instruct" )
7474

75+
#### LiteLLM (100+ providers via single interface)
76+
77+
LiteLLM provides a unified interface to access 100+ LLM providers. You can use models from OpenAI, Anthropic, Google, Cohere, Azure, Hugging Face, and more.
78+
79+
**Basic Setup (Local LiteLLM)**:
80+
81+
- `LITELLM_MODEL` - Model in format `provider/model-name` (e.g., `openai/gpt-4`, `claude/claude-opus-4-5-20251101`, `gemini/gemini-2.0-flash`)
82+
- The required API key for your provider should be in environment variables (e.g., `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, etc.)
83+
- Optional: `LITELLM_TEMPERATURE` - Set temperature (default: varies by provider)
84+
- Optional: `LITELLM_TOP_P` - Set top-p sampling (default: varies by provider)
85+
86+
**Examples**:
87+
88+
OpenAI via LiteLLM:
89+
```bash
90+
export LITELLM_MODEL="openai/gpt-4"
91+
export OPENAI_API_KEY="sk-..."
92+
```
93+
94+
Anthropic Claude via LiteLLM:
95+
```bash
96+
export LITELLM_MODEL="claude/claude-opus-4-5-20251101"
97+
export ANTHROPIC_API_KEY="sk-ant-..."
98+
```
99+
100+
Google Gemini via LiteLLM:
101+
```bash
102+
export LITELLM_MODEL="gemini/gemini-2.0-flash"
103+
export GOOGLE_API_KEY="..."
104+
```
105+
106+
**LiteLLM Proxy Server**
107+
108+
If you have a self-hosted LiteLLM proxy server:
109+
110+
- `LITELLM_PROXY_URL` - Base URL of your LiteLLM proxy (e.g., `http://localhost:8000`)
111+
- `LITELLM_PROXY_API_KEY` - API key for the proxy
112+
- `LITELLM_PROXY_MODEL` - Model name in format `litellm_proxy/<model-name>` (e.g., `litellm_proxy/gpt-4`)
113+
- Optional: `LITELLM_PROXY_TEMPERATURE` - Set temperature
114+
- Optional: `LITELLM_PROXY_TOP_P` - Set top-p sampling
115+
116+
**Example**:
117+
```bash
118+
export LITELLM_PROXY_URL="http://localhost:8000"
119+
export LITELLM_PROXY_API_KEY="sk-proxy-key-123"
120+
export LITELLM_PROXY_MODEL="litellm_proxy/my-model"
121+
```
122+
123+
Also you can use the provided script for configuration in the git repo (⚠️not available
124+
through `pip install`)
125+
126+
```bash
127+
uv run tasks.py setup
128+
```
129+
130+
**Checking LiteLLM Status**
131+
132+
After configuration, you can check if your LiteLLM setup is working:
133+
134+
```bash
135+
show-llms
136+
```
137+
138+
This will display a table showing the authentication status of all configured LLMs, including LiteLLM.
139+
75140

76141
## Test Installation
77142

78143
test hello world example (need to set up llm credentials first)
79144

80145
```bash
81-
python python examples/hello_world.py
82-
python examples/self_transduction.py
83-
python examples/agentics_web_search_report.py
146+
uv run examples/hello_world.py
147+
uv run examples/self_transduction.py
148+
uv run examples/agentics_web_search_report.py
84149

85150
```
86151

examples/emotion_extractor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def split_into_chunks(text, chunk_size=200):
3434

3535

3636
async def main():
37-
emotion_detector = AG(atype=EmotionDetector, llm="watsonx/openai/gpt-oss-120b")
37+
emotion_detector = AG(atype=EmotionDetector)
3838

3939
current_file = Path(__file__).resolve()
4040
text = None

examples/generate_tweets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async def main():
1919
"data/categorization_example/movies.csv",
2020
max_rows=2,
2121
)
22-
movies.llm = "watsonx/openai/gpt-oss-120b"
22+
# movies.llm = "watsonx/openai/gpt-oss-120b"
2323
## Step 2. add attribute tweet to be used as a target for transduction
2424
extended_movies = movies.add_attribute(
2525
"tweet", slot_type="str", description="Tweet used to advertise the movie"

examples/relation_extraction.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
N_TERMS = 500
1313
N_CLUSTERS = 5
14-
llm = "watsonx/openai/gpt-oss-120b"
14+
# llm = "watsonx/openai/gpt-oss-120b"
15+
16+
17+
llm = AG.get_llm_provider()
1518

1619

17-
# llm=AG.get_llm_provider()
1820
class InputTerms(BaseModel):
1921
terms: list[str] = None
2022

@@ -73,7 +75,6 @@ async def relation_extracton_map_reduce(
7375

7476

7577
async def evaluate_relation_extraction(outout_file: str = None, n_terms=10000):
76-
7778
terms = random_frequent_terms(n=n_terms)
7879
# for i in range(1000, 1001, 500):
7980

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies = [
3939
"litellm",
4040
"mellea",
4141
"plotly>=6.5.0",
42+
"rich>=13.0.0,<14.0.0",
4243
]
4344

4445

@@ -63,6 +64,8 @@ packages = ["src/agentics"]
6364
[tool.hatch.build.targets.sdist]
6465
packages = ["src/agentics"]
6566

67+
[project.scripts]
68+
show-llms = "agentics.scripts.show_llms:main"
6669

6770
[dependency-groups]
6871
dev = [
@@ -77,6 +80,7 @@ dev = [
7780
"papermill>=2.6.0",
7881
"pytest-xdist>=3.8.0",
7982
"pytest-subtests>=0.15.0",
83+
"hunter>=3.9.0",
8084
]
8185
docling = [
8286
"langchain-docling >=0.2.0,<0.3.0"

0 commit comments

Comments
 (0)