Skip to content

Commit

Permalink
fix: remove httpx dependency (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerHYang authored Oct 31, 2024
1 parent 067b9e6 commit 41c6557
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ dependencies = [
instruments = [
"openai >= 1.0.0",
]
test = [
"openai == 1.0.0",
"opentelemetry-sdk",
"opentelemetry-instrumentation-httpx",
"respx",
"numpy",
"pytest-vcr",
]

[project.urls]
Homepage = "https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-openai"
Expand All @@ -56,7 +48,6 @@ path = "src/openinference/instrumentation/openai/version.py"
[tool.hatch.build.targets.sdist]
include = [
"/src",
"/tests",
]

[tool.hatch.build.targets.wheel]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from types import ModuleType
from typing import Any, Awaitable, Callable, Iterable, Iterator, Mapping, Tuple

from httpx import URL
from opentelemetry import context as context_api
from opentelemetry import trace as trace_api
from opentelemetry.context import _SUPPRESS_INSTRUMENTATION_KEY
Expand Down Expand Up @@ -123,11 +122,15 @@ def _get_span_kind(self, cast_to: type) -> str:
)

def _get_attributes_from_instance(self, instance: Any) -> Iterator[Tuple[str, AttributeValue]]:
if not isinstance(base_url := getattr(instance, "base_url", None), URL):
if (
not (base_url := getattr(instance, "base_url", None))
or not (host := getattr(base_url, "host", None))
or not isinstance(host, str)
):
return
if base_url.host.endswith("api.openai.com"):
if host.endswith("api.openai.com"):
yield SpanAttributes.LLM_PROVIDER, OpenInferenceLLMProviderValues.OPENAI.value
if base_url.host.endswith("openai.azure.com"):
elif host.endswith("openai.azure.com"):
yield SpanAttributes.LLM_PROVIDER, OpenInferenceLLMProviderValues.AZURE.value

def _get_attributes_from_request(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
openai==1.0.0
opentelemetry-sdk
opentelemetry-instrumentation-httpx
respx
numpy
pytest-vcr
5 changes: 4 additions & 1 deletion python/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ commands_pre =
bedrock-latest: uv pip install -U boto3
mistralai: uv pip install --reinstall {toxinidir}/instrumentation/openinference-instrumentation-mistralai[test]
mistralai-latest: uv pip install -U mistralai
openai: uv pip install --reinstall {toxinidir}/instrumentation/openinference-instrumentation-openai[test]
openai: uv pip uninstall -r test-requirements.txt
openai: uv pip install --reinstall-package openinference-instrumentation-openai .
openai: python -c 'import openinference.instrumentation.openai'
openai: uv pip install -r test-requirements.txt
openai-latest: uv pip install -U openai
vertexai: uv pip install --reinstall {toxinidir}/instrumentation/openinference-instrumentation-vertexai[test]
vertexai-latest: uv pip install -U vertexai
Expand Down

0 comments on commit 41c6557

Please sign in to comment.