Skip to content

Commit f7ce245

Browse files
authored
Merge pull request #15 from IBM/Bedrock_using_litellm
Bedrock application using litellm
2 parents 43b68a2 + cc27c30 commit f7ce245

File tree

6 files changed

+3068
-0
lines changed

6 files changed

+3068
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

Bedrock-using-litellm/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
This guide explains how to set up and run your **Python app (`main.py`)** using **`uv`** for environment and dependency management.
2+
3+
## Prerequisites
4+
5+
Make sure the new system has:
6+
- **Python 3.8+**
7+
- **Internet access**
8+
- **`uv`** installed
9+
10+
If `uv` is not installed, run one of the following commands:
11+
12+
```bash
13+
curl -LsSf https://astral.sh/uv/install.sh | sh
14+
```
15+
or
16+
```bash
17+
pip install uv
18+
```
19+
## Steps for running the application
20+
21+
### 1. Sync Dependencies
22+
23+
Install all dependencies listed in `pyproject.toml` and `uv.lock`:
24+
25+
```bash
26+
uv sync
27+
```
28+
29+
### 2. Activate the Environment
30+
31+
You can manually activate the environment:
32+
33+
```bash
34+
source .venv/bin/activate
35+
```
36+
37+
### 3. Update the envs in `.env` file
38+
39+
Update **AWS Bedrock** creds such as
40+
- AWS_ACCESS_KEY_ID
41+
- AWS_SECRET_ACCESS_KEY
42+
- AWS_SESSION_TOKEN
43+
44+
45+
Refer following documentation to know about **Traceloop environmental variables**:
46+
https://www.ibm.com/docs/en/instana-observability/1.0.300?topic=started-traceloop-instrumentation#configuring-the-environment
47+
48+
49+
50+
### 4. For the collection of metrics, Install OTel Data Collector for GenAI (ODCG)
51+
52+
To install the data collector, Refer: https://www.ibm.com/docs/en/instana-observability/1.0.300?topic=started-install-otel-data-collector-genai-odcg
53+
54+
### 5. Run the App
55+
56+
Run the application using:
57+
58+
```bash
59+
uv run main.py
60+
```
61+
### Output
62+
![Traces](image.png)

Bedrock-using-litellm/image.png

335 KB
Loading

Bedrock-using-litellm/main.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from litellm import completion
2+
import litellm
3+
litellm.callbacks = ["otel"]
4+
5+
from dotenv import load_dotenv
6+
load_dotenv()
7+
8+
from traceloop.sdk import Traceloop
9+
Traceloop.init(app_name="LitellmApp")
10+
11+
# Example: Using Amazon Titan Text Express on Bedrock
12+
response = completion(
13+
model="bedrock/amazon.titan-text-express-v1",
14+
messages=[
15+
{"role": "system", "content": "You are an assistant that summarizes text."},
16+
{"role": "user", "content": "Summarize this: Large language models are transforming the way software is built."},
17+
],
18+
)
19+
20+
print("Response from Bedrock model:")
21+
print(response['choices'][0]['message']['content'])
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[project]
2+
name = "bedrock-using-litellm"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
dependencies = [
8+
"litellm[proxy]>=1.79.0",
9+
"python-dotenv>=1.2.1",
10+
"traceloop-sdk==0.47.4",
11+
]

0 commit comments

Comments
 (0)