Skip to content

armgit / burr

Public Imported from GitHub
0

Build applications that make decisions (chatbots, agents, simulations, etc...). Monitor, trace, persist, and execute on your own infrastructure.

improved Literal; updated notebooks; added test

ziltoaecca27a4541
diff --git a/burr/integrations/opentelemetry.py b/burr/integrations/opentelemetry.py
index b59e12bf..b4936737 100644
--- a/burr/integrations/opentelemetry.py
+++ b/burr/integrations/opentelemetry.py
@@ -1,6 +1,5 @@
import dataclasses
import datetime
-import functools
import importlib
import importlib.metadata
import json
@@ -563,10 +562,39 @@ INSTRUMENTS_SPECS = {
"urllib3": ("urllib3", "opentelemetry.instrumentation.urllib3", "URLLib3Instrumentor"),
}
-INSTRUMENTS = Literal[tuple(INSTRUMENTS_SPECS)]
+INSTRUMENTS = Literal[
+ "openai",
+ "anthropic",
+ "cohere",
+ "google_generativeai",
+ "mistral",
+ "ollama",
+ "transformers",
+ "together",
+ "bedrock",
+ "replicate",
+ "vertexai",
+ "groq",
+ "watsonx",
+ "alephalpha",
+ "pinecone",
+ "qdrant",
+ "chroma",
+ "milvus",
+ "weaviate",
+ "lancedb",
+ "marqo",
+ "redis",
+ "langchain",
+ "llama_index",
+ "haystack",
+ "requests",
+ "httpx",
+ "urllib",
+ "urllib3",
+]
def available_dists() -> set[str]:
return set((dist.name for dist in importlib.metadata.distributions()))
@@ -575,29 +603,40 @@ def _init_instrument(
module_name: str, instrumentation_module_name: str, instrumentor_name: str
) -> None:
if module_name not in sys.modules:
+ logger.debug(f"`{module_name}` wasn't imported. Skipping instrumentation.")
return
- if instrumentation_module_name not in available_dists():
- logger.debug(f"{module_name} is installed, but {instrumentation_module_name} isn't")
+ instrumentation_package_name = instrumentation_module_name.replace(".", "-")
+ if instrumentation_package_name not in available_dists():
+ logger.info(
+ f"Couldn't instrument `{module_name}`. Package `{instrumentation_package_name}` is missing."
+ )
return
try:
instrumentation_module = importlib.import_module(instrumentation_module_name)
instrumentor = getattr(instrumentation_module, instrumentor_name)
- if not instrumentor.is_instrumented_by_opentelemetry:
+ if instrumentor.is_instrumented_by_opentelemetry:
+ logger.debug(f"`{module_name}` is already instrumented.")
+ else:
instrumentor.instrument()
+ logger.info(f"`{module_name}` is now instrumented.")
+
except BaseException:
- logger.debug(f"Failed to instrument {module_name} with {instrumentation_module_name}")
+ logger.error(f"Failed to instrument `{module_name}` with `{instrumentation_package_name}`.")
-def init_instruments(*instruments: INSTRUMENTS):
+def init_instruments(*instruments: INSTRUMENTS, init_all: bool = False):
# if no instrument explicitly passed, default to trying to instrument all available packages
- if len(instruments) == 0:
+ if init_all:
+ logger.debug("Instrumenting all libraries.")
instruments = INSTRUMENTS_SPECS.keys()
for instrument in instruments:
specs = INSTRUMENTS_SPECS[instrument]
- _init_instrument(*specs)
+ module_name, instrumentation_module_name, instrumentor_name = specs
+
+ _init_instrument(module_name, instrumentation_module_name, instrumentor_name)
if __name__ == "__main__":
diff --git a/examples/opentelemetry/notebook.ipynb b/examples/opentelemetry/notebook.ipynb
index e6de3b58..2caa646c 100644
--- a/examples/opentelemetry/notebook.ipynb
+++ b/examples/opentelemetry/notebook.ipynb
@@ -7,118 +7,9 @@
"metadata": {
"scrolled": true
},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Requirement already satisfied: burr[start] in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (0.24.0)\n",
- "Requirement already satisfied: graphviz in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (0.20.3)\n",
- "Requirement already satisfied: sf-hamilton in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (1.72.1)\n",
- "Requirement already satisfied: streamlit in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (1.37.0)\n",
- "Requirement already satisfied: matplotlib in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (3.9.1)\n",
- "Requirement already satisfied: loguru in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (0.7.2)\n",
- "Requirement already satisfied: pydantic in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (2.8.2)\n",
- "Requirement already satisfied: click in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (8.1.7)\n",
- "Requirement already satisfied: fastapi in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (0.111.1)\n",
- "Requirement already satisfied: uvicorn in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (0.30.3)\n",
- "Requirement already satisfied: fastapi-pagination in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (0.12.26)\n",
- "Requirement already satisfied: aiofiles in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (24.1.0)\n",
- "Requirement already satisfied: requests in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (2.32.3)\n",
- "Requirement already satisfied: jinja2 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (3.1.4)\n",
- "Requirement already satisfied: openai in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from burr[start]) (1.37.1)\n",
- "Requirement already satisfied: contourpy>=1.0.1 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from matplotlib->burr[start]) (1.2.1)\n",
- "Requirement already satisfied: cycler>=0.10 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from matplotlib->burr[start]) (0.12.1)\n",
- "Requirement already satisfied: fonttools>=4.22.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from matplotlib->burr[start]) (4.53.1)\n",
- "Requirement already satisfied: kiwisolver>=1.3.1 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from matplotlib->burr[start]) (1.4.5)\n",
- "Requirement already satisfied: numpy>=1.23 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from matplotlib->burr[start]) (1.26.4)\n",
- "Requirement already satisfied: packaging>=20.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from matplotlib->burr[start]) (24.1)\n",
- "Requirement already satisfied: pillow>=8 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from matplotlib->burr[start]) (10.4.0)\n",
- "Requirement already satisfied: pyparsing>=2.3.1 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from matplotlib->burr[start]) (3.1.2)\n",
- "Requirement already satisfied: python-dateutil>=2.7 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from matplotlib->burr[start]) (2.9.0.post0)\n",
- "Requirement already satisfied: typing-extensions>4.0.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from sf-hamilton->burr[start]) (4.12.2)\n",
- "Requirement already satisfied: pandas in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from sf-hamilton->burr[start]) (2.2.2)\n",
- "Requirement already satisfied: typing-inspect in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from sf-hamilton->burr[start]) (0.9.0)\n",
- "Requirement already satisfied: altair<6,>=4.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from streamlit->burr[start]) (5.3.0)\n",
- "Requirement already satisfied: blinker<2,>=1.0.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from streamlit->burr[start]) (1.8.2)\n",
- "Requirement already satisfied: cachetools<6,>=4.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from streamlit->burr[start]) (5.4.0)\n",
- "Requirement already satisfied: protobuf<6,>=3.20 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from streamlit->burr[start]) (4.25.4)\n",
- "Requirement already satisfied: pyarrow>=7.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from streamlit->burr[start]) (17.0.0)\n",
- "Requirement already satisfied: rich<14,>=10.14.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from streamlit->burr[start]) (13.7.1)\n",
- "Requirement already satisfied: tenacity<9,>=8.1.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from streamlit->burr[start]) (8.5.0)\n",
- "Requirement already satisfied: toml<2,>=0.10.1 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from streamlit->burr[start]) (0.10.2)\n",
- "Requirement already satisfied: gitpython!=3.1.19,<4,>=3.0.7 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from streamlit->burr[start]) (3.1.43)\n",
- "Requirement already satisfied: pydeck<1,>=0.8.0b4 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from streamlit->burr[start]) (0.9.1)\n",
- "Requirement already satisfied: tornado<7,>=6.0.3 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from streamlit->burr[start]) (6.4.1)\n",
- "Requirement already satisfied: jsonschema>=3.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from altair<6,>=4.0->streamlit->burr[start]) (4.23.0)\n",
- "Requirement already satisfied: toolz in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from altair<6,>=4.0->streamlit->burr[start]) (0.12.1)\n",
- "Requirement already satisfied: gitdb<5,>=4.0.1 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from gitpython!=3.1.19,<4,>=3.0.7->streamlit->burr[start]) (4.0.11)\n",
- "Requirement already satisfied: pytz>=2020.1 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from pandas->sf-hamilton->burr[start]) (2024.1)\n",
- "Requirement already satisfied: tzdata>=2022.7 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from pandas->sf-hamilton->burr[start]) (2024.1)\n",
- "Requirement already satisfied: MarkupSafe>=2.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from jinja2->burr[start]) (2.1.5)\n",
- "Requirement already satisfied: six>=1.5 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from python-dateutil>=2.7->matplotlib->burr[start]) (1.16.0)\n",
- "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from requests->burr[start]) (3.3.2)\n",
- "Requirement already satisfied: idna<4,>=2.5 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from requests->burr[start]) (3.7)\n",
- "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from requests->burr[start]) (2.2.2)\n",
- "Requirement already satisfied: certifi>=2017.4.17 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from requests->burr[start]) (2024.7.4)\n",
- "Requirement already satisfied: markdown-it-py>=2.2.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from rich<14,>=10.14.0->streamlit->burr[start]) (3.0.0)\n",
- "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from rich<14,>=10.14.0->streamlit->burr[start]) (2.18.0)\n",
- "Requirement already satisfied: starlette<0.38.0,>=0.37.2 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from fastapi->burr[start]) (0.37.2)\n",
- "Requirement already satisfied: fastapi-cli>=0.0.2 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from fastapi->burr[start]) (0.0.4)\n",
- "Requirement already satisfied: httpx>=0.23.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from fastapi->burr[start]) (0.27.0)\n",
- "Requirement already satisfied: python-multipart>=0.0.7 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from fastapi->burr[start]) (0.0.9)\n",
- "Requirement already satisfied: email_validator>=2.0.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from fastapi->burr[start]) (2.2.0)\n",
- "Requirement already satisfied: annotated-types>=0.4.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from pydantic->burr[start]) (0.7.0)\n",
- "Requirement already satisfied: pydantic-core==2.20.1 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from pydantic->burr[start]) (2.20.1)\n",
- "Requirement already satisfied: anyio<5,>=3.5.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from openai->burr[start]) (4.4.0)\n",
- "Requirement already satisfied: distro<2,>=1.7.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from openai->burr[start]) (1.9.0)\n",
- "Requirement already satisfied: sniffio in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from openai->burr[start]) (1.3.1)\n",
- "Requirement already satisfied: tqdm>4 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from openai->burr[start]) (4.66.4)\n",
- "Requirement already satisfied: mypy-extensions>=0.3.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from typing-inspect->sf-hamilton->burr[start]) (1.0.0)\n",
- "Requirement already satisfied: h11>=0.8 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from uvicorn->burr[start]) (0.14.0)\n",
- "Requirement already satisfied: dnspython>=2.0.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from email_validator>=2.0.0->fastapi->burr[start]) (2.6.1)\n",
- "Requirement already satisfied: typer>=0.12.3 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from fastapi-cli>=0.0.2->fastapi->burr[start]) (0.12.3)\n",
- "Requirement already satisfied: smmap<6,>=3.0.1 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from gitdb<5,>=4.0.1->gitpython!=3.1.19,<4,>=3.0.7->streamlit->burr[start]) (5.0.1)\n",
- "Requirement already satisfied: httpcore==1.* in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from httpx>=0.23.0->fastapi->burr[start]) (1.0.5)\n",
- "Requirement already satisfied: attrs>=22.2.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit->burr[start]) (23.2.0)\n",
- "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit->burr[start]) (2023.12.1)\n",
- "Requirement already satisfied: referencing>=0.28.4 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit->burr[start]) (0.35.1)\n",
- "Requirement already satisfied: rpds-py>=0.7.1 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit->burr[start]) (0.19.1)\n",
- "Requirement already satisfied: mdurl~=0.1 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from markdown-it-py>=2.2.0->rich<14,>=10.14.0->streamlit->burr[start]) (0.1.2)\n",
- "Requirement already satisfied: httptools>=0.5.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from uvicorn->burr[start]) (0.6.1)\n",
- "Requirement already satisfied: python-dotenv>=0.13 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from uvicorn->burr[start]) (1.0.1)\n",
- "Requirement already satisfied: pyyaml>=5.1 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from uvicorn->burr[start]) (6.0.1)\n",
- "Requirement already satisfied: uvloop!=0.15.0,!=0.15.1,>=0.14.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from uvicorn->burr[start]) (0.19.0)\n",
- "Requirement already satisfied: watchfiles>=0.13 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from uvicorn->burr[start]) (0.22.0)\n",
- "Requirement already satisfied: websockets>=10.4 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from uvicorn->burr[start]) (12.0)\n",
- "Requirement already satisfied: shellingham>=1.3.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from typer>=0.12.3->fastapi-cli>=0.0.2->fastapi->burr[start]) (1.5.4)\n",
- "\n",
- "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.2.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n",
- "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3.12 -m pip install --upgrade pip\u001b[0m\n",
- "Requirement already satisfied: opentelemetry-instrumentation-openai in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (0.26.4)\n",
- "Requirement already satisfied: opentelemetry-api<2.0.0,>=1.26.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from opentelemetry-instrumentation-openai) (1.26.0)\n",
- "Requirement already satisfied: opentelemetry-instrumentation<0.48,>=0.47b0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from opentelemetry-instrumentation-openai) (0.47b0)\n",
- "Requirement already satisfied: opentelemetry-semantic-conventions<0.48,>=0.47b0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from opentelemetry-instrumentation-openai) (0.47b0)\n",
- "Requirement already satisfied: opentelemetry-semantic-conventions-ai==0.4.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from opentelemetry-instrumentation-openai) (0.4.0)\n",
- "Requirement already satisfied: tiktoken<1,>=0.6.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from opentelemetry-instrumentation-openai) (0.7.0)\n",
- "Requirement already satisfied: deprecated>=1.2.6 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from opentelemetry-api<2.0.0,>=1.26.0->opentelemetry-instrumentation-openai) (1.2.14)\n",
- "Requirement already satisfied: importlib-metadata<=8.0.0,>=6.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from opentelemetry-api<2.0.0,>=1.26.0->opentelemetry-instrumentation-openai) (8.0.0)\n",
- "Requirement already satisfied: setuptools>=16.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from opentelemetry-instrumentation<0.48,>=0.47b0->opentelemetry-instrumentation-openai) (72.1.0)\n",
- "Requirement already satisfied: wrapt<2.0.0,>=1.0.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from opentelemetry-instrumentation<0.48,>=0.47b0->opentelemetry-instrumentation-openai) (1.16.0)\n",
- "Requirement already satisfied: regex>=2022.1.18 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from tiktoken<1,>=0.6.0->opentelemetry-instrumentation-openai) (2024.7.24)\n",
- "Requirement already satisfied: requests>=2.26.0 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from tiktoken<1,>=0.6.0->opentelemetry-instrumentation-openai) (2.32.3)\n",
- "Requirement already satisfied: zipp>=0.5 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from importlib-metadata<=8.0.0,>=6.0->opentelemetry-api<2.0.0,>=1.26.0->opentelemetry-instrumentation-openai) (3.19.2)\n",
- "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from requests>=2.26.0->tiktoken<1,>=0.6.0->opentelemetry-instrumentation-openai) (3.3.2)\n",
- "Requirement already satisfied: idna<4,>=2.5 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from requests>=2.26.0->tiktoken<1,>=0.6.0->opentelemetry-instrumentation-openai) (3.7)\n",
- "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from requests>=2.26.0->tiktoken<1,>=0.6.0->opentelemetry-instrumentation-openai) (2.2.2)\n",
- "Requirement already satisfied: certifi>=2017.4.17 in /Users/elijahbenizzy/.pyenv/versions/3.12.0/envs/burr-3-12/lib/python3.12/site-packages (from requests>=2.26.0->tiktoken<1,>=0.6.0->opentelemetry-instrumentation-openai) (2024.7.4)\n",
- "\n",
- "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.2.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n",
- "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3.12 -m pip install --upgrade pip\u001b[0m\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
+ "%%capture\n",
"!pip install \"burr[start]\"\n",
"!pip install opentelemetry-instrumentation-openai"
]
@@ -150,7 +41,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 3,
"id": "1540b34e-dfd8-49f6-8d6c-5585af0596ab",
"metadata": {},
"outputs": [
@@ -160,172 +51,173 @@
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
- "<!-- Generated by graphviz version 12.0.0 (20240704.0754)\n",
+ "<!-- Generated by graphviz version 2.43.0 (0)\n",
" -->\n",
- "<!-- Pages: 1 -->\n",
- "<svg width=\"642pt\" height=\"414pt\"\n",
- " viewBox=\"0.00 0.00 641.85 413.60\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
- "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 409.6)\">\n",
- "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-409.6 637.85,-409.6 637.85,4 -4,4\"/>\n",
+ "<!-- Title: %3 Pages: 1 -->\n",
+ "<svg width=\"740pt\" height=\"413pt\"\n",
+ " viewBox=\"0.00 0.00 739.50 413.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
+ "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 409)\">\n",
+ "<title>%3</title>\n",
+ "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-409 735.5,-409 735.5,4 -4,4\"/>\n",
"<!-- prompt -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>prompt</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M603.47,-338C603.47,-338 563.12,-338 563.12,-338 557.12,-338 551.12,-332 551.12,-326 551.12,-326 551.12,-313.4 551.12,-313.4 551.12,-307.4 557.12,-301.4 563.12,-301.4 563.12,-301.4 603.47,-301.4 603.47,-301.4 609.47,-301.4 615.47,-307.4 615.47,-313.4 615.47,-313.4 615.47,-326 615.47,-326 615.47,-332 609.47,-338 603.47,-338\"/>\n",
- "<text text-anchor=\"middle\" x=\"583.3\" y=\"-313.9\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">prompt</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M697,-337C697,-337 648,-337 648,-337 642,-337 636,-331 636,-325 636,-325 636,-312 636,-312 636,-306 642,-300 648,-300 648,-300 697,-300 697,-300 703,-300 709,-306 709,-312 709,-312 709,-325 709,-325 709,-331 703,-337 697,-337\"/>\n",
+ "<text text-anchor=\"middle\" x=\"672.5\" y=\"-314.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">prompt</text>\n",
"</g>\n",
"<!-- check_safety -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>check_safety</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M582.47,-270.4C582.47,-270.4 506.12,-270.4 506.12,-270.4 500.12,-270.4 494.12,-264.4 494.12,-258.4 494.12,-258.4 494.12,-245.8 494.12,-245.8 494.12,-239.8 500.12,-233.8 506.12,-233.8 506.12,-233.8 582.47,-233.8 582.47,-233.8 588.47,-233.8 594.47,-239.8 594.47,-245.8 594.47,-245.8 594.47,-258.4 594.47,-258.4 594.47,-264.4 588.47,-270.4 582.47,-270.4\"/>\n",
- "<text text-anchor=\"middle\" x=\"544.3\" y=\"-246.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">check_safety</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M675,-269C675,-269 586,-269 586,-269 580,-269 574,-263 574,-257 574,-257 574,-244 574,-244 574,-238 580,-232 586,-232 586,-232 675,-232 675,-232 681,-232 687,-238 687,-244 687,-244 687,-257 687,-257 687,-263 681,-269 675,-269\"/>\n",
+ "<text text-anchor=\"middle\" x=\"630.5\" y=\"-246.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">check_safety</text>\n",
"</g>\n",
"<!-- prompt&#45;&gt;check_safety -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
"<title>prompt&#45;&gt;check_safety</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M572.85,-301.12C569.09,-294.8 564.75,-287.5 560.61,-280.54\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"563.67,-278.84 555.55,-272.03 557.66,-282.41 563.67,-278.84\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M661.24,-299.81C657.01,-293.15 652.09,-285.43 647.45,-278.13\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"650.11,-275.79 641.79,-269.24 644.2,-279.55 650.11,-275.79\"/>\n",
"</g>\n",
"<!-- input__prompt -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>input__prompt</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"633.85,-405.6 532.75,-405.6 532.75,-369 633.85,-369 633.85,-405.6\"/>\n",
- "<text text-anchor=\"middle\" x=\"583.3\" y=\"-381.5\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: prompt</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"731.5,-405 613.5,-405 613.5,-368 731.5,-368 731.5,-405\"/>\n",
+ "<text text-anchor=\"middle\" x=\"672.5\" y=\"-382.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: prompt</text>\n",
"</g>\n",
"<!-- input__prompt&#45;&gt;prompt -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>input__prompt&#45;&gt;prompt</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M583.3,-368.72C583.3,-362.84 583.3,-356.12 583.3,-349.6\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"586.8,-349.84 583.3,-339.84 579.8,-349.84 586.8,-349.84\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M672.5,-367.81C672.5,-361.6 672.5,-354.45 672.5,-347.6\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"676,-347.24 672.5,-337.24 669,-347.24 676,-347.24\"/>\n",
"</g>\n",
"<!-- decide_mode -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>decide_mode</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M268.97,-187.3C268.97,-187.3 189.62,-187.3 189.62,-187.3 183.62,-187.3 177.62,-181.3 177.62,-175.3 177.62,-175.3 177.62,-162.7 177.62,-162.7 177.62,-156.7 183.62,-150.7 189.62,-150.7 189.62,-150.7 268.97,-150.7 268.97,-150.7 274.97,-150.7 280.97,-156.7 280.97,-162.7 280.97,-162.7 280.97,-175.3 280.97,-175.3 280.97,-181.3 274.97,-187.3 268.97,-187.3\"/>\n",
- "<text text-anchor=\"middle\" x=\"229.3\" y=\"-163.2\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">decide_mode</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M288.5,-187C288.5,-187 198.5,-187 198.5,-187 192.5,-187 186.5,-181 186.5,-175 186.5,-175 186.5,-162 186.5,-162 186.5,-156 192.5,-150 198.5,-150 198.5,-150 288.5,-150 288.5,-150 294.5,-150 300.5,-156 300.5,-162 300.5,-162 300.5,-175 300.5,-175 300.5,-181 294.5,-187 288.5,-187\"/>\n",
+ "<text text-anchor=\"middle\" x=\"243.5\" y=\"-164.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">decide_mode</text>\n",
"</g>\n",
"<!-- check_safety&#45;&gt;decide_mode -->\n",
"<g id=\"edge6\" class=\"edge\">\n",
"<title>check_safety&#45;&gt;decide_mode</title>\n",
- "<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M493.69,-238.07C438.96,-223.98 351.62,-201.49 292.43,-186.25\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"293.38,-182.88 282.82,-183.78 291.63,-189.66 293.38,-182.88\"/>\n",
- "<text text-anchor=\"middle\" x=\"443.05\" y=\"-205.5\" font-family=\"Times,serif\" font-size=\"14.00\">safe=True</text>\n",
+ "<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M573.81,-237.78C503.93,-223.34 385.31,-198.82 310.86,-183.42\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"311.16,-179.91 300.65,-181.31 309.74,-186.77 311.16,-179.91\"/>\n",
+ "<text text-anchor=\"middle\" x=\"510\" y=\"-205.8\" font-family=\"Times,serif\" font-size=\"14.00\">safe=True</text>\n",
"</g>\n",
"<!-- response -->\n",
"<g id=\"node10\" class=\"node\">\n",
"<title>response</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M476.85,-36.6C476.85,-36.6 423.75,-36.6 423.75,-36.6 417.75,-36.6 411.75,-30.6 411.75,-24.6 411.75,-24.6 411.75,-12 411.75,-12 411.75,-6 417.75,0 423.75,0 423.75,0 476.85,0 476.85,0 482.85,0 488.85,-6 488.85,-12 488.85,-12 488.85,-24.6 488.85,-24.6 488.85,-30.6 482.85,-36.6 476.85,-36.6\"/>\n",
- "<text text-anchor=\"middle\" x=\"450.3\" y=\"-12.5\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">response</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M561.5,-37C561.5,-37 499.5,-37 499.5,-37 493.5,-37 487.5,-31 487.5,-25 487.5,-25 487.5,-12 487.5,-12 487.5,-6 493.5,0 499.5,0 499.5,0 561.5,0 561.5,0 567.5,0 573.5,-6 573.5,-12 573.5,-12 573.5,-25 573.5,-25 573.5,-31 567.5,-37 561.5,-37\"/>\n",
+ "<text text-anchor=\"middle\" x=\"530.5\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">response</text>\n",
"</g>\n",
"<!-- check_safety&#45;&gt;response -->\n",
"<g id=\"edge7\" class=\"edge\">\n",
"<title>check_safety&#45;&gt;response</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M553.33,-233.41C569.76,-198.48 599.82,-119.54 565.3,-67.6 550.76,-45.73 524.18,-33.74 500.24,-27.18\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"501.14,-23.79 490.59,-24.81 499.47,-30.59 501.14,-23.79\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M640.56,-231.91C658.95,-197.19 692.95,-118.82 657.5,-68 640.8,-44.06 610.58,-31.93 583.82,-25.79\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"584.26,-22.3 573.76,-23.71 582.85,-29.16 584.26,-22.3\"/>\n",
"</g>\n",
"<!-- generate_image -->\n",
"<g id=\"node5\" class=\"node\">\n",
"<title>generate_image</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M414.22,-104.2C414.22,-104.2 318.37,-104.2 318.37,-104.2 312.37,-104.2 306.37,-98.2 306.37,-92.2 306.37,-92.2 306.37,-79.6 306.37,-79.6 306.37,-73.6 312.37,-67.6 318.37,-67.6 318.37,-67.6 414.22,-67.6 414.22,-67.6 420.22,-67.6 426.22,-73.6 426.22,-79.6 426.22,-79.6 426.22,-92.2 426.22,-92.2 426.22,-98.2 420.22,-104.2 414.22,-104.2\"/>\n",
- "<text text-anchor=\"middle\" x=\"366.3\" y=\"-80.1\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">generate_image</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M493.5,-105C493.5,-105 383.5,-105 383.5,-105 377.5,-105 371.5,-99 371.5,-93 371.5,-93 371.5,-80 371.5,-80 371.5,-74 377.5,-68 383.5,-68 383.5,-68 493.5,-68 493.5,-68 499.5,-68 505.5,-74 505.5,-80 505.5,-80 505.5,-93 505.5,-93 505.5,-99 499.5,-105 493.5,-105\"/>\n",
+ "<text text-anchor=\"middle\" x=\"438.5\" y=\"-82.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">generate_image</text>\n",
"</g>\n",
"<!-- decide_mode&#45;&gt;generate_image -->\n",
"<g id=\"edge8\" class=\"edge\">\n",
"<title>decide_mode&#45;&gt;generate_image</title>\n",
- "<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M234.67,-150.37C238.71,-139.91 245.25,-127.19 255.05,-119.2 258.82,-116.13 275.58,-110.78 295,-105.3\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"295.83,-108.7 304.54,-102.67 293.97,-101.96 295.83,-108.7\"/>\n",
- "<text text-anchor=\"middle\" x=\"317.92\" y=\"-122.4\" font-family=\"Times,serif\" font-size=\"14.00\">mode=generate_image</text>\n",
+ "<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M248.76,-149.9C252.77,-139.56 259.36,-127.16 269.5,-120 301.29,-97.54 318.84,-110.82 361.33,-104.9\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"362.13,-108.31 371.41,-103.2 360.97,-101.41 362.13,-108.31\"/>\n",
+ "<text text-anchor=\"middle\" x=\"352.5\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">mode=generate_image</text>\n",
"</g>\n",
"<!-- generate_code -->\n",
"<g id=\"node7\" class=\"node\">\n",
"<title>generate_code</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M544.1,-104.2C544.1,-104.2 456.5,-104.2 456.5,-104.2 450.5,-104.2 444.5,-98.2 444.5,-92.2 444.5,-92.2 444.5,-79.6 444.5,-79.6 444.5,-73.6 450.5,-67.6 456.5,-67.6 456.5,-67.6 544.1,-67.6 544.1,-67.6 550.1,-67.6 556.1,-73.6 556.1,-79.6 556.1,-79.6 556.1,-92.2 556.1,-92.2 556.1,-98.2 550.1,-104.2 544.1,-104.2\"/>\n",
- "<text text-anchor=\"middle\" x=\"500.3\" y=\"-80.1\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">generate_code</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M637,-105C637,-105 536,-105 536,-105 530,-105 524,-99 524,-93 524,-93 524,-80 524,-80 524,-74 530,-68 536,-68 536,-68 637,-68 637,-68 643,-68 649,-74 649,-80 649,-80 649,-93 649,-93 649,-99 643,-105 637,-105\"/>\n",
+ "<text text-anchor=\"middle\" x=\"586.5\" y=\"-82.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">generate_code</text>\n",
"</g>\n",
"<!-- decide_mode&#45;&gt;generate_code -->\n",
"<g id=\"edge9\" class=\"edge\">\n",
"<title>decide_mode&#45;&gt;generate_code</title>\n",
- "<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M281.24,-159.22C310.64,-153.68 347.89,-145.67 380.3,-135.7 393.67,-131.59 422.37,-119.95 448.35,-109.08\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"449.63,-112.34 457.49,-105.23 446.91,-105.88 449.63,-112.34\"/>\n",
- "<text text-anchor=\"middle\" x=\"480.8\" y=\"-122.4\" font-family=\"Times,serif\" font-size=\"14.00\">mode=generate_code</text>\n",
+ "<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M300.71,-160.27C339.15,-154.82 390.77,-146.33 435.5,-135 455.53,-129.93 459.83,-126.34 479.5,-120 491.87,-116.01 505.09,-111.89 517.86,-107.97\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"518.98,-111.29 527.52,-105.03 516.94,-104.6 518.98,-111.29\"/>\n",
+ "<text text-anchor=\"middle\" x=\"557\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">mode=generate_code</text>\n",
"</g>\n",
"<!-- answer_question -->\n",
"<g id=\"node8\" class=\"node\">\n",
"<title>answer_question</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M276.1,-104.2C276.1,-104.2 176.5,-104.2 176.5,-104.2 170.5,-104.2 164.5,-98.2 164.5,-92.2 164.5,-92.2 164.5,-79.6 164.5,-79.6 164.5,-73.6 170.5,-67.6 176.5,-67.6 176.5,-67.6 276.1,-67.6 276.1,-67.6 282.1,-67.6 288.1,-73.6 288.1,-79.6 288.1,-79.6 288.1,-92.2 288.1,-92.2 288.1,-98.2 282.1,-104.2 276.1,-104.2\"/>\n",
- "<text text-anchor=\"middle\" x=\"226.3\" y=\"-80.1\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">answer_question</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M341.5,-105C341.5,-105 225.5,-105 225.5,-105 219.5,-105 213.5,-99 213.5,-93 213.5,-93 213.5,-80 213.5,-80 213.5,-74 219.5,-68 225.5,-68 225.5,-68 341.5,-68 341.5,-68 347.5,-68 353.5,-74 353.5,-80 353.5,-80 353.5,-93 353.5,-93 353.5,-99 347.5,-105 341.5,-105\"/>\n",
+ "<text text-anchor=\"middle\" x=\"283.5\" y=\"-82.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">answer_question</text>\n",
"</g>\n",
"<!-- decide_mode&#45;&gt;answer_question -->\n",
"<g id=\"edge10\" class=\"edge\">\n",
"<title>decide_mode&#45;&gt;answer_question</title>\n",
- "<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M177.37,-163.83C138.52,-159.51 90.05,-151.14 77.55,-135.7 72.94,-130 72.95,-124.91 77.55,-119.2 80.18,-115.94 116.74,-107.97 152.95,-100.77\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"153.52,-104.23 162.66,-98.86 152.17,-97.36 153.52,-104.23\"/>\n",
- "<text text-anchor=\"middle\" x=\"143.17\" y=\"-122.4\" font-family=\"Times,serif\" font-size=\"14.00\">mode=answer_question</text>\n",
+ "<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M186.19,-165.83C135.42,-163 66.76,-155.4 49.5,-135 45.19,-129.91 45.12,-125.03 49.5,-120 50.8,-118.51 135.83,-106.97 203.01,-98.06\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"203.75,-101.49 213.2,-96.71 202.83,-94.55 203.75,-101.49\"/>\n",
+ "<text text-anchor=\"middle\" x=\"135.5\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">mode=answer_question</text>\n",
"</g>\n",
"<!-- prompt_for_more -->\n",
"<g id=\"node9\" class=\"node\">\n",
"<title>prompt_for_more</title>\n",
- "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M114.6,-104.2C114.6,-104.2 12,-104.2 12,-104.2 6,-104.2 0,-98.2 0,-92.2 0,-92.2 0,-79.6 0,-79.6 0,-73.6 6,-67.6 12,-67.6 12,-67.6 114.6,-67.6 114.6,-67.6 120.6,-67.6 126.6,-73.6 126.6,-79.6 126.6,-79.6 126.6,-92.2 126.6,-92.2 126.6,-98.2 120.6,-104.2 114.6,-104.2\"/>\n",
- "<text text-anchor=\"middle\" x=\"63.3\" y=\"-80.1\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">prompt_for_more</text>\n",
+ "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M129,-105C129,-105 12,-105 12,-105 6,-105 0,-99 0,-93 0,-93 0,-80 0,-80 0,-74 6,-68 12,-68 12,-68 129,-68 129,-68 135,-68 141,-74 141,-80 141,-80 141,-93 141,-93 141,-99 135,-105 129,-105\"/>\n",
+ "<text text-anchor=\"middle\" x=\"70.5\" y=\"-82.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">prompt_for_more</text>\n",
"</g>\n",
"<!-- decide_mode&#45;&gt;prompt_for_more -->\n",
"<g id=\"edge11\" class=\"edge\">\n",
"<title>decide_mode&#45;&gt;prompt_for_more</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M177.14,-163.83C136.55,-159.46 84.75,-151.01 70.3,-135.7 65.21,-130.31 62.77,-122.98 61.76,-115.64\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"65.26,-115.69 61.26,-105.88 58.27,-116.05 65.26,-115.69\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M186.14,-166.23C133.38,-163.71 60.66,-156.33 42.5,-135 36.97,-128.5 38.68,-120.77 43.27,-113.46\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"46.34,-115.2 49.71,-105.15 40.81,-110.91 46.34,-115.2\"/>\n",
"</g>\n",
"<!-- generate_image&#45;&gt;response -->\n",
"<g id=\"edge12\" class=\"edge\">\n",
"<title>generate_image&#45;&gt;response</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M388.81,-67.32C398.04,-60.11 408.88,-51.65 418.87,-43.85\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"420.81,-46.77 426.53,-37.86 416.5,-41.26 420.81,-46.77\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M463.15,-67.81C473.76,-60.21 486.31,-51.2 497.68,-43.05\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"500.01,-45.68 506.1,-37.01 495.93,-39.99 500.01,-45.68\"/>\n",
"</g>\n",
"<!-- input__model -->\n",
"<g id=\"node6\" class=\"node\">\n",
"<title>input__model</title>\n",
- "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"556.22,-187.3 460.37,-187.3 460.37,-150.7 556.22,-150.7 556.22,-187.3\"/>\n",
- "<text text-anchor=\"middle\" x=\"508.3\" y=\"-163.2\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: model</text>\n",
+ "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"649.5,-187 539.5,-187 539.5,-150 649.5,-150 649.5,-187\"/>\n",
+ "<text text-anchor=\"middle\" x=\"594.5\" y=\"-164.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: model</text>\n",
"</g>\n",
"<!-- input__model&#45;&gt;generate_image -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>input__model&#45;&gt;generate_image</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M519.46,-150.49C524.38,-140.34 527.59,-127.89 520.3,-119.2 509.46,-106.29 466.51,-107.58 437.52,-104.04\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"438.38,-100.63 427.95,-102.49 437.26,-107.54 438.38,-100.63\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M609.87,-149.76C616.31,-140.12 620.8,-128.49 613.5,-120 600.47,-104.84 548.58,-108.18 515.86,-104.71\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"515.97,-101.19 505.58,-103.24 514.98,-108.12 515.97,-101.19\"/>\n",
"</g>\n",
"<!-- input__model&#45;&gt;generate_code -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>input__model&#45;&gt;generate_code</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M533.96,-150.48C543.61,-141.6 551.03,-130.36 545.3,-119.2 544.12,-116.91 542.7,-114.74 541.09,-112.7\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"543.64,-110.3 534.14,-105.61 538.65,-115.2 543.64,-110.3\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M626.11,-149.99C636.81,-141.67 644.66,-131.11 638.5,-120 636.87,-117.07 634.86,-114.36 632.58,-111.88\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"634.82,-109.18 625.06,-105.06 630.12,-114.37 634.82,-109.18\"/>\n",
"</g>\n",
"<!-- input__model&#45;&gt;answer_question -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>input__model&#45;&gt;answer_question</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M460.09,-158.85C436.44,-153.54 407.84,-145.86 383.3,-135.7 369.96,-130.17 368.67,-124.68 355.3,-119.2 352.28,-117.96 326.79,-111.53 299.26,-104.72\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"300.25,-101.36 289.71,-102.36 298.58,-108.15 300.25,-101.36\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M539.29,-159.96C508.96,-154.84 471,-146.81 438.5,-135 425.23,-130.18 423.66,-125.12 410.5,-120 401.11,-116.35 383.03,-111.33 363.4,-106.34\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"364.21,-102.94 353.66,-103.89 362.51,-109.73 364.21,-102.94\"/>\n",
"</g>\n",
"<!-- generate_code&#45;&gt;response -->\n",
"<g id=\"edge14\" class=\"edge\">\n",
"<title>generate_code&#45;&gt;response</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M486.9,-67.32C481.86,-60.7 476,-53.02 470.48,-45.77\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"473.5,-43.96 464.65,-38.13 467.93,-48.21 473.5,-43.96\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M571.49,-67.81C565.59,-60.86 558.7,-52.74 552.27,-45.16\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"554.69,-42.6 545.55,-37.24 549.35,-47.13 554.69,-42.6\"/>\n",
"</g>\n",
"<!-- answer_question&#45;&gt;response -->\n",
"<g id=\"edge13\" class=\"edge\">\n",
"<title>answer_question&#45;&gt;response</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M286.92,-67.15C322.54,-56.72 367.01,-43.69 400.56,-33.87\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"401.43,-37.26 410.04,-31.09 399.46,-30.54 401.43,-37.26\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M349.04,-67.99C389.19,-57.26 439.9,-43.71 477.5,-33.66\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"478.5,-37.02 487.25,-31.06 476.69,-30.26 478.5,-37.02\"/>\n",
"</g>\n",
"<!-- prompt_for_more&#45;&gt;response -->\n",
"<g id=\"edge15\" class=\"edge\">\n",
"<title>prompt_for_more&#45;&gt;response</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M126.61,-72.79C136.22,-71.01 146.02,-69.23 155.3,-67.6 241.31,-52.47 341.72,-36.36 400.42,-27.1\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"400.77,-30.59 410.1,-25.57 399.68,-23.67 400.77,-30.59\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M141.12,-75.37C233.83,-62.07 394.53,-39.01 477.51,-27.1\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"478.08,-30.56 487.48,-25.67 477.09,-23.63 478.08,-30.56\"/>\n",
"</g>\n",
"<!-- response&#45;&gt;prompt -->\n",
"<g id=\"edge16\" class=\"edge\">\n",
"<title>response&#45;&gt;prompt</title>\n",
- "<path fill=\"none\" stroke=\"black\" d=\"M489.33,-26.11C540.08,-36.08 622.3,-56.62 622.3,-84.9 622.3,-253.1 622.3,-253.1 622.3,-253.1 622.3,-267.28 615.48,-281.07 607.55,-292.32\"/>\n",
- "<polygon fill=\"black\" stroke=\"black\" points=\"605.02,-289.87 601.67,-299.92 610.56,-294.15 605.02,-289.87\"/>\n",
+ "<path fill=\"none\" stroke=\"black\" d=\"M573.87,-26.1C628.55,-35.66 715.5,-55.58 715.5,-85.5 715.5,-251.5 715.5,-251.5 715.5,-251.5 715.5,-266.47 707.64,-280.7 698.64,-292.09\"/>\n",
+ "<polygon fill=\"black\" stroke=\"black\" points=\"695.84,-289.98 691.99,-299.85 701.15,-294.54 695.84,-289.98\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
@@ -334,7 +226,7 @@
"Graph(actions=[prompt: {} -> chat_history, prompt, check_safety: prompt -> safe, decide_mode: prompt -> mode, generate_image: prompt, chat_history, mode -> response, generate_code: prompt, chat_history, mode -> response, answer_question: prompt, chat_history, mode -> response, prompt_for_more: prompt, chat_history -> response, response: response, safe, mode -> chat_history], transitions=[Transition(from_=prompt: {} -> chat_history, prompt, to=check_safety: prompt -> safe, condition=condition: default), Transition(from_=check_safety: prompt -> safe, to=decide_mode: prompt -> mode, condition=condition: safe=True), Transition(from_=check_safety: prompt -> safe, to=response: response, safe, mode -> chat_history, condition=condition: default), Transition(from_=decide_mode: prompt -> mode, to=generate_image: prompt, chat_history, mode -> response, condition=condition: mode=generate_image), Transition(from_=decide_mode: prompt -> mode, to=generate_code: prompt, chat_history, mode -> response, condition=condition: mode=generate_code), Transition(from_=decide_mode: prompt -> mode, to=answer_question: prompt, chat_history, mode -> response, condition=condition: mode=answer_question), Transition(from_=decide_mode: prompt -> mode, to=prompt_for_more: prompt, chat_history -> response, condition=condition: default), Transition(from_=generate_image: prompt, chat_history, mode -> response, to=response: response, safe, mode -> chat_history, condition=condition: default), Transition(from_=answer_question: prompt, chat_history, mode -> response, to=response: response, safe, mode -> chat_history, condition=condition: default), Transition(from_=generate_code: prompt, chat_history, mode -> response, to=response: response, safe, mode -> chat_history, condition=condition: default), Transition(from_=prompt_for_more: prompt, chat_history -> response, to=response: response, safe, mode -> chat_history, condition=condition: default), Transition(from_=response: response, safe, mode -> chat_history, to=prompt: {} -> chat_history, prompt, condition=condition: default)])"
]
},
- "execution_count": 2,
+ "execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
@@ -358,25 +250,10 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 4,
"id": "bba29bd1-3e59-4050-821c-8da44c2c583f",
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "(response: response, safe, mode -> chat_history,\n",
- " {'chat_item': {'content': 'The capital of France is Paris.',\n",
- " 'type': 'text',\n",
- " 'role': 'assistant'}},\n",
- " {'chat_history': [{'role': 'user', 'content': 'Please answer the following question:: What is the capital of France?', 'type': 'text'}, {'content': 'The capital of France is Paris.', 'type': 'text', 'role': 'assistant'}], '__SEQUENCE_ID': 4, 'prompt': 'What is the capital of France?', '__PRIOR_STEP': 'response', 'safe': True, 'mode': 'answer_question', 'response': {'content': 'The capital of France is Paris.', 'type': 'text', 'role': 'assistant'}})"
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"from burr.core import ApplicationBuilder\n",
"app = (\n",
@@ -404,7 +281,7 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 5,
"id": "b7a26a51-103e-4400-8c43-9ebffebd6313",
"metadata": {},
"outputs": [],
@@ -413,6 +290,96 @@
"OpenAIInstrumentor().instrument()"
]
},
+ {
+ "cell_type": "markdown",
+ "id": "31074710",
+ "metadata": {},
+ "source": [
+ " Burr also provides a convenience function `init_instruments()` to instrument common 3rd party libraries."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "id": "a5752d60",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from burr.integrations.opentelemetry import init_instruments, available_dists, _init_instrument\n",
+ "\n",
+ "init_instruments(\"openai\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "bafc59c1",
+ "metadata": {},
+ "source": [
+ "You can specify `init_all=True` instead of passing individual libraries as string. This will try to instrument currently imported libraries with the available instrumentation package you have installed (find some more [here](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation) and [here](https://github.com/traceloop/openllmetry/tree/main/packages)).\n",
+ "\n",
+ "You can get the logger to view which library is successfully instrumented."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "id": "3843f98b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import logging\n",
+ "logger = logging.getLogger(\"burr.integrations.opentelemetry\")\n",
+ "logger.addHandler(logging.StreamHandler())\n",
+ "logger.setLevel(logging.DEBUG)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "id": "950f701a",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "Instrumenting all libraries.\n",
+ "`openai` is already instrumented.\n",
+ "`anthropic` wasn't imported. Skipping instrumentation.\n",
+ "`cohere` wasn't imported. Skipping instrumentation.\n",
+ "`google.generativeai` wasn't imported. Skipping instrumentation.\n",
+ "`mistralai` wasn't imported. Skipping instrumentation.\n",
+ "`ollama` wasn't imported. Skipping instrumentation.\n",
+ "`transformers` wasn't imported. Skipping instrumentation.\n",
+ "`together` wasn't imported. Skipping instrumentation.\n",
+ "`bedrock` wasn't imported. Skipping instrumentation.\n",
+ "`replicate` wasn't imported. Skipping instrumentation.\n",
+ "`vertexai` wasn't imported. Skipping instrumentation.\n",
+ "`groq` wasn't imported. Skipping instrumentation.\n",
+ "`ibm-watsonx-ai` wasn't imported. Skipping instrumentation.\n",
+ "`aleph_alpha_client` wasn't imported. Skipping instrumentation.\n",
+ "`pinecone` wasn't imported. Skipping instrumentation.\n",
+ "`qdrant_client` wasn't imported. Skipping instrumentation.\n",
+ "`chromadb` wasn't imported. Skipping instrumentation.\n",
+ "`pymilvus` wasn't imported. Skipping instrumentation.\n",
+ "`weaviate` wasn't imported. Skipping instrumentation.\n",
+ "`lancedb` wasn't imported. Skipping instrumentation.\n",
+ "`marqo` wasn't imported. Skipping instrumentation.\n",
+ "`redis` wasn't imported. Skipping instrumentation.\n",
+ "`langchain` wasn't imported. Skipping instrumentation.\n",
+ "`llama_index` wasn't imported. Skipping instrumentation.\n",
+ "`haystack` wasn't imported. Skipping instrumentation.\n",
+ "`requests` is already instrumented.\n",
+ "Couldn't instrument `httpx`. Package `opentelemetry-instrumentation-httpx` is missing.\n",
+ "Couldn't instrument `urllib`. Package `opentelemetry-instrumentation-urllib` is missing.\n",
+ "`urllib3` is already instrumented.\n"
+ ]
+ }
+ ],
+ "source": [
+ "init_instruments(init_all=True)"
+ ]
+ },
{
"cell_type": "markdown",
"id": "8c756b22-42d4-49f6-b57f-436bc7555295",
@@ -436,36 +403,12 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": null,
"id": "7502ab1a-dd74-4e3d-8948-5a88ecb6ee56",
"metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "\u001b[32mTraceloop syncing configuration and prompts\u001b[39m\n",
- "\u001b[32mTraceloop exporting traces to https://api.traceloop.com authenticating with bearer token\n",
- "\u001b[39m\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "(response: response, safe, mode -> chat_history,\n",
- " {'chat_item': {'content': 'The capital of France is Paris.',\n",
- " 'type': 'text',\n",
- " 'role': 'assistant'}},\n",
- " {'chat_history': [{'role': 'user', 'content': 'Please answer the following question:: What is the capital of France?', 'type': 'text'}, {'content': 'The capital of France is Paris.', 'type': 'text', 'role': 'assistant'}, {'role': 'user', 'content': 'Please answer the following question:: What is the capital of France?', 'type': 'text'}, {'content': 'The capital of France is Paris.', 'type': 'text', 'role': 'assistant'}, {'role': 'user', 'content': 'Please answer the following question:: What is the capital of France?', 'type': 'text'}, {'content': 'The capital of France is Paris.', 'type': 'text', 'role': 'assistant'}, {'role': 'user', 'content': 'Please answer the following question:: What is the capital of France?', 'type': 'text'}, {'content': 'The capital of France is Paris.', 'type': 'text', 'role': 'assistant'}], '__SEQUENCE_ID': 19, 'prompt': 'What is the capital of France?', '__PRIOR_STEP': 'response', 'safe': True, 'mode': 'answer_question', 'response': {'content': 'The capital of France is Paris.', 'type': 'text', 'role': 'assistant'}})"
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
- "# from traceloop.sdk import Traceloop\n",
+ "from traceloop.sdk import Traceloop\n",
"import os\n",
"from burr.integrations import opentelemetry\n",
"from burr.core import ApplicationBuilder\n",
@@ -499,34 +442,20 @@
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": null,
"id": "c0c1e26e-5b75-4bab-ad58-83aaea9f88af",
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "(response: response, safe, mode -> chat_history,\n",
- " {'chat_item': {'content': 'The capital of France is Paris.',\n",
- " 'type': 'text',\n",
- " 'role': 'assistant'}},\n",
- " {'chat_history': [{'role': 'user', 'content': 'Please answer the following question:: What is the capital of France?', 'type': 'text'}, {'content': 'The capital of France is Paris.', 'type': 'text', 'role': 'assistant'}], '__SEQUENCE_ID': 4, 'prompt': 'What is the capital of France?', '__PRIOR_STEP': 'response', 'safe': True, 'mode': 'answer_question', 'response': {'content': 'The capital of France is Paris.', 'type': 'text', 'role': 'assistant'}})"
- ]
- },
- "execution_count": 12,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
- "app = (ApplicationBuilder()\n",
- " .with_entrypoint(\"prompt\")\n",
- " .with_state(chat_history=[])\n",
- " .with_graph(graph)\n",
- " .with_tracker(\n",
- " project=\"demo_opentelemetry\",\n",
- " use_otel_tracing=True)\n",
- " .build()\n",
+ "app = (\n",
+ " ApplicationBuilder()\n",
+ " .with_entrypoint(\"prompt\")\n",
+ " .with_state(chat_history=[])\n",
+ " .with_graph(graph)\n",
+ " .with_tracker(\n",
+ " project=\"demo_opentelemetry\",\n",
+ " use_otel_tracing=True)\n",
+ " .build()\n",
")\n",
"\n",
"app.run(inputs={\"prompt\":\"What is the capital of France?\"}, halt_after=[\"response\"])"
@@ -544,24 +473,10 @@
},
{
"cell_type": "code",
- "execution_count": 13,
+ "execution_count": null,
"id": "93cad8f7-9f0b-4b20-bc75-2adaca5bfde9",
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/markdown": [
- "[Link to UI](http://localhost:7241/project/demo_tracing/null/01492754-b899-410f-83c6-b5b86ef457c5)"
- ],
- "text/plain": [
- "<IPython.core.display.Markdown object>"
- ]
- },
- "execution_count": 13,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"from IPython.display import Markdown\n",
"url = f\"[Link to UI](http://localhost:7241/project/demo_tracing/null/{app.uid})\"\n",
@@ -585,7 +500,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.12.0"
+ "version": "3.11.9"
}
},
"nbformat": 4,
diff --git a/examples/rag-lancedb-ingestion/application.py b/examples/rag-lancedb-ingestion/application.py
index 2b693000..82b4bb6b 100644
--- a/examples/rag-lancedb-ingestion/application.py
+++ b/examples/rag-lancedb-ingestion/application.py
@@ -85,8 +85,10 @@ def build_application() -> Application:
if __name__ == "__main__":
import utils
+ from burr.integrations.opentelemetry import init_instruments
+
utils.set_environment_variables() # set environment variables for LanceDB
- utils.instrument() # register the OpenTelemetry instrumentation
+ init_instruments("openai", "lancedb") # register the OpenTelemetry instrumentation
# build the Burr `Application`
app = build_application()
diff --git a/examples/rag-lancedb-ingestion/notebook.ipynb b/examples/rag-lancedb-ingestion/notebook.ipynb
index 6a070772..06e719b1 100644
--- a/examples/rag-lancedb-ingestion/notebook.ipynb
+++ b/examples/rag-lancedb-ingestion/notebook.ipynb
@@ -579,11 +579,10 @@
],
"source": [
"from burr.core import ApplicationBuilder\n",
- "from opentelemetry.instrumentation.openai import OpenAIInstrumentor\n",
- "from opentelemetry.instrumentation.lancedb import LanceInstrumentor\n",
+ "from burr.integrations.opentelemetry import init_instruments\n",
+ "\n",
+ "init_instruments(\"openai\", \"lancedb\")\n",
"\n",
- "LanceInstrumentor().instrument()\n",
- "OpenAIInstrumentor().instrument()\n",
"\n",
"llm_client = openai.OpenAI()\n",
"lancedb_con = lancedb.connect(os.environ[\"DESTINATION__LANCEDB__CREDENTIALS__URI\"])\n",
diff --git a/examples/rag-lancedb-ingestion/utils.py b/examples/rag-lancedb-ingestion/utils.py
index ece96683..041160ff 100644
--- a/examples/rag-lancedb-ingestion/utils.py
+++ b/examples/rag-lancedb-ingestion/utils.py
@@ -19,14 +19,6 @@ def set_environment_variables():
]
-def instrument():
- from opentelemetry.instrumentation.lancedb import LanceInstrumentor
- from opentelemetry.instrumentation.openai import OpenAIInstrumentor
-
- LanceInstrumentor().instrument()
- OpenAIInstrumentor().instrument()
-
-
def _compact_hash(digest: bytes) -> str:
"""Compact the hash to a string that's safe to pass around."""
return base64.urlsafe_b64encode(digest).decode()
diff --git a/tests/integrations/test_opentelemetry.py b/tests/integrations/test_opentelemetry.py
new file mode 100644
index 00000000..af9b217b
--- /dev/null
+++ b/tests/integrations/test_opentelemetry.py
@@ -0,0 +1,7 @@
+import typing
+
+import burr.integrations.opentelemetry as burr_otel
+
+
+def test_instrument_specs_match_instruments_literal():
+ assert set(typing.get_args(burr_otel.INSTRUMENTS)) == set(burr_otel.INSTRUMENTS_SPECS.keys())