Skip to content

Commit f71c668

Browse files
gustavocidornelaswhoseoyster
authored andcommitted
feat: add OpenLIT notebook example
1 parent 7269136 commit f71c668

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "2722b419",
6+
"metadata": {},
7+
"source": [
8+
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openlayer-ai/openlayer-python/blob/main/examples/tracing/openlit/openlit_tracing.ipynb)\n",
9+
"\n",
10+
"\n",
11+
"# <a id=\"top\">OpenLIT quickstart</a>\n",
12+
"\n",
13+
"This notebook shows how to export traces captured by [OpenLIT](https://docs.openlit.io/latest/features/tracing) to Openlayer. The integration is done via the Openlayer's [OpenTelemetry endpoint](https://www.openlayer.com/docs/integrations/opentelemetry). For more information, refer to the [OpenLIT integration guide](https://www.openlayer.com/docs/integrations/openlit)."
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": null,
19+
"id": "020c8f6a",
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"!pip install openai openlit"
24+
]
25+
},
26+
{
27+
"cell_type": "markdown",
28+
"id": "75c2a473",
29+
"metadata": {},
30+
"source": [
31+
"## 1. Set the environment variables"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": 1,
37+
"id": "f3f4fa13",
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"import os\n",
42+
"\n",
43+
"import openai\n",
44+
"\n",
45+
"os.environ[\"OPENAI_API_KEY\"] = \"YOUR_OPENAI_API_KEY_HERE\"\n",
46+
"\n",
47+
"os.environ[\"OTEL_EXPORTER_OTLP_ENDPOINT\"] = \"https://api.openlayer.com/v1/otel\"\n",
48+
"os.environ[\"OTEL_EXPORTER_OTLP_HEADERS\"] = \"Authorization=Bearer YOUR_OPENLAYER_API_KEY_HERE, x-bt-parent=pipeline_id:YOUR_OPENLAYER_PIPELINE_ID_HERE\""
49+
]
50+
},
51+
{
52+
"cell_type": "markdown",
53+
"id": "9758533f",
54+
"metadata": {},
55+
"source": [
56+
"## 2. Initialize OpenLIT instrumentation"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"id": "c35d9860-dc41-4f7c-8d69-cc2ac7e5e485",
63+
"metadata": {},
64+
"outputs": [],
65+
"source": [
66+
"import openlit\n",
67+
"\n",
68+
"openlit.init(disable_batch=True)"
69+
]
70+
},
71+
{
72+
"cell_type": "markdown",
73+
"id": "72a6b954",
74+
"metadata": {},
75+
"source": [
76+
"## 3. Use LLMs and workflows as usual\n",
77+
"\n",
78+
"That's it! Now you can continue using LLMs and workflows as usual.The trace data is automatically exported to Openlayer and you can start creating tests around it."
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": 3,
84+
"id": "e00c1c79",
85+
"metadata": {},
86+
"outputs": [],
87+
"source": [
88+
"client = openai.OpenAI()"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": null,
94+
"id": "abaf6987-c257-4f0d-96e7-3739b24c7206",
95+
"metadata": {},
96+
"outputs": [],
97+
"source": [
98+
"client.chat.completions.create(\n",
99+
" model=\"gpt-4o-mini\", messages=[{\"role\": \"user\", \"content\": \"How are you doing today?\"}]\n",
100+
")"
101+
]
102+
}
103+
],
104+
"metadata": {
105+
"kernelspec": {
106+
"display_name": "openlayer-assistant",
107+
"language": "python",
108+
"name": "python3"
109+
},
110+
"language_info": {
111+
"codemirror_mode": {
112+
"name": "ipython",
113+
"version": 3
114+
},
115+
"file_extension": ".py",
116+
"mimetype": "text/x-python",
117+
"name": "python",
118+
"nbconvert_exporter": "python",
119+
"pygments_lexer": "ipython3",
120+
"version": "3.9.18"
121+
}
122+
},
123+
"nbformat": 4,
124+
"nbformat_minor": 5
125+
}

0 commit comments

Comments
 (0)