Skip to content

Commit e4a0620

Browse files
feat(tracing): add OCI GenAI tracing function
- Updated the `__init__.py` file to include the new tracing function in the module's exports, improving accessibility for users.
1 parent 9563e88 commit e4a0620

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/openlayer/lib/__init__.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
"trace_anthropic",
77
"trace_openai",
88
"trace_openai_assistant_thread_run",
9+
"trace_oci_genai",
910
"trace_mistral",
1011
"trace_groq",
1112
"trace_async_openai",
1213
"trace_async",
1314
"trace_bedrock",
14-
]
15+
]
1516

1617
# ---------------------------------- Tracing --------------------------------- #
1718
from .tracing import tracer
@@ -103,3 +104,23 @@ def trace_bedrock(client):
103104
if not hasattr(client, "_service_model") or client._service_model.service_name != "bedrock-runtime":
104105
raise ValueError("Invalid client. Please provide a boto3 bedrock-runtime client.")
105106
return bedrock_tracer.trace_bedrock(client)
107+
108+
def trace_oci_genai(client, estimate_tokens: bool = True):
109+
"""Trace OCI GenAI chat completions.
110+
111+
Args:
112+
client: OCI GenAI client.
113+
estimate_tokens: Whether to estimate tokens when not available. Defaults to True.
114+
"""
115+
# pylint: disable=import-outside-toplevel
116+
try:
117+
import oci
118+
except ImportError:
119+
raise ImportError("oci is required for OCI GenAI tracing. Install with: pip install oci")
120+
121+
from .integrations import oci_tracer
122+
123+
if not isinstance(client, oci.generative_ai_inference.GenerativeAiInferenceClient):
124+
raise ValueError("Invalid client. Please provide an OCI GenAI client.")
125+
126+
return oci_tracer.trace_oci_genai(client, estimate_tokens=estimate_tokens)

0 commit comments

Comments
 (0)