openlit 1.34.3__py3-none-any.whl → 1.34.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openlit/instrumentation/ai21/__init__.py +22 -23
- openlit/instrumentation/ai21/ai21.py +58 -51
- openlit/instrumentation/ai21/async_ai21.py +58 -51
- openlit/instrumentation/ai21/utils.py +134 -243
- openlit/instrumentation/google_ai_studio/__init__.py +2 -4
- openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +0 -6
- openlit/instrumentation/google_ai_studio/google_ai_studio.py +0 -6
- openlit/instrumentation/google_ai_studio/utils.py +1 -2
- openlit/instrumentation/together/__init__.py +3 -5
- openlit/instrumentation/together/async_together.py +70 -476
- openlit/instrumentation/together/together.py +69 -475
- openlit/instrumentation/together/utils.py +320 -0
- {openlit-1.34.3.dist-info → openlit-1.34.5.dist-info}/METADATA +1 -1
- {openlit-1.34.3.dist-info → openlit-1.34.5.dist-info}/RECORD +16 -15
- {openlit-1.34.3.dist-info → openlit-1.34.5.dist-info}/LICENSE +0 -0
- {openlit-1.34.3.dist-info → openlit-1.34.5.dist-info}/WHEEL +0 -0
@@ -13,53 +13,52 @@ from openlit.instrumentation.ai21.async_ai21 import (
|
|
13
13
|
async_chat, async_chat_rag
|
14
14
|
)
|
15
15
|
|
16
|
-
_instruments = (
|
16
|
+
_instruments = ("ai21 >= 3.0.0",)
|
17
17
|
|
18
18
|
class AI21Instrumentor(BaseInstrumentor):
|
19
19
|
"""
|
20
|
-
An instrumentor for AI21
|
20
|
+
An instrumentor for AI21 client library.
|
21
21
|
"""
|
22
22
|
|
23
23
|
def instrumentation_dependencies(self) -> Collection[str]:
|
24
24
|
return _instruments
|
25
25
|
|
26
26
|
def _instrument(self, **kwargs):
|
27
|
-
application_name = kwargs.get(
|
28
|
-
environment = kwargs.get(
|
29
|
-
tracer = kwargs.get(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
version = importlib.metadata.version('ai21')
|
27
|
+
application_name = kwargs.get("application_name", "default")
|
28
|
+
environment = kwargs.get("environment", "default")
|
29
|
+
tracer = kwargs.get("tracer")
|
30
|
+
metrics = kwargs.get("metrics_dict")
|
31
|
+
pricing_info = kwargs.get("pricing_info", {})
|
32
|
+
capture_message_content = kwargs.get("capture_message_content", False)
|
33
|
+
disable_metrics = kwargs.get("disable_metrics")
|
34
|
+
version = importlib.metadata.version("ai21")
|
36
35
|
|
37
36
|
#sync
|
38
37
|
wrap_function_wrapper(
|
39
|
-
|
40
|
-
|
38
|
+
"ai21.clients.studio.resources.chat.chat_completions",
|
39
|
+
"ChatCompletions.create",
|
41
40
|
chat(version, environment, application_name,
|
42
|
-
tracer,
|
41
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
43
42
|
)
|
44
43
|
wrap_function_wrapper(
|
45
|
-
|
46
|
-
|
44
|
+
"ai21.clients.studio.resources.studio_conversational_rag",
|
45
|
+
"StudioConversationalRag.create",
|
47
46
|
chat_rag(version, environment, application_name,
|
48
|
-
tracer,
|
47
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
49
48
|
)
|
50
49
|
|
51
50
|
#Async
|
52
51
|
wrap_function_wrapper(
|
53
|
-
|
54
|
-
|
52
|
+
"ai21.clients.studio.resources.chat.async_chat_completions",
|
53
|
+
"AsyncChatCompletions.create",
|
55
54
|
async_chat(version, environment, application_name,
|
56
|
-
tracer,
|
55
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
57
56
|
)
|
58
57
|
wrap_function_wrapper(
|
59
|
-
|
60
|
-
|
58
|
+
"ai21.clients.studio.resources.studio_conversational_rag",
|
59
|
+
"AsyncStudioConversationalRag.create",
|
61
60
|
async_chat_rag(version, environment, application_name,
|
62
|
-
tracer,
|
61
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
63
62
|
)
|
64
63
|
|
65
64
|
def _uninstrument(self, **kwargs):
|
@@ -22,7 +22,7 @@ from openlit.semcov import SemanticConvention
|
|
22
22
|
logger = logging.getLogger(__name__)
|
23
23
|
|
24
24
|
def chat(version, environment, application_name,
|
25
|
-
tracer,
|
25
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics):
|
26
26
|
"""
|
27
27
|
Generates a telemetry wrapper for GenAI function call
|
28
28
|
"""
|
@@ -46,9 +46,9 @@ def chat(version, environment, application_name,
|
|
46
46
|
self._span = span
|
47
47
|
self._span_name = span_name
|
48
48
|
# Placeholder for aggregating streaming response
|
49
|
-
self._llmresponse =
|
50
|
-
self._response_id =
|
51
|
-
self._finish_reason =
|
49
|
+
self._llmresponse = ""
|
50
|
+
self._response_id = ""
|
51
|
+
self._finish_reason = ""
|
52
52
|
self._input_tokens = 0
|
53
53
|
self._output_tokens = 0
|
54
54
|
self._choices = []
|
@@ -92,14 +92,13 @@ def chat(version, environment, application_name,
|
|
92
92
|
environment=environment,
|
93
93
|
application_name=application_name,
|
94
94
|
metrics=metrics,
|
95
|
-
event_provider=event_provider,
|
96
95
|
capture_message_content=capture_message_content,
|
97
96
|
disable_metrics=disable_metrics,
|
98
97
|
version=version
|
99
98
|
)
|
100
99
|
except Exception as e:
|
101
100
|
handle_exception(self._span, e)
|
102
|
-
logger.error(
|
101
|
+
logger.error("Error in trace creation: %s", e)
|
103
102
|
raise
|
104
103
|
|
105
104
|
def wrapper(wrapped, instance, args, kwargs):
|
@@ -108,12 +107,12 @@ def chat(version, environment, application_name,
|
|
108
107
|
"""
|
109
108
|
|
110
109
|
# Check if streaming is enabled for the API call
|
111
|
-
streaming = kwargs.get(
|
110
|
+
streaming = kwargs.get("stream", False)
|
112
111
|
|
113
|
-
server_address, server_port = set_server_address_and_port(instance,
|
114
|
-
request_model = kwargs.get(
|
112
|
+
server_address, server_port = set_server_address_and_port(instance, "api.ai21.com", 443)
|
113
|
+
request_model = kwargs.get("model", "jamba-1.5-mini")
|
115
114
|
|
116
|
-
span_name = f
|
115
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
117
116
|
|
118
117
|
# pylint: disable=no-else-return
|
119
118
|
if streaming:
|
@@ -127,30 +126,34 @@ def chat(version, environment, application_name,
|
|
127
126
|
with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
|
128
127
|
start_time = time.time()
|
129
128
|
response = wrapped(*args, **kwargs)
|
130
|
-
response = process_chat_response(
|
131
|
-
response=response,
|
132
|
-
request_model=request_model,
|
133
|
-
pricing_info=pricing_info,
|
134
|
-
server_port=server_port,
|
135
|
-
server_address=server_address,
|
136
|
-
environment=environment,
|
137
|
-
application_name=application_name,
|
138
|
-
metrics=metrics,
|
139
|
-
event_provider=event_provider,
|
140
|
-
start_time=start_time,
|
141
|
-
span=span,
|
142
|
-
capture_message_content=capture_message_content,
|
143
|
-
disable_metrics=disable_metrics,
|
144
|
-
version=version,
|
145
|
-
**kwargs
|
146
|
-
)
|
147
129
|
|
148
|
-
|
130
|
+
try:
|
131
|
+
response = process_chat_response(
|
132
|
+
response=response,
|
133
|
+
request_model=request_model,
|
134
|
+
pricing_info=pricing_info,
|
135
|
+
server_port=server_port,
|
136
|
+
server_address=server_address,
|
137
|
+
environment=environment,
|
138
|
+
application_name=application_name,
|
139
|
+
metrics=metrics,
|
140
|
+
start_time=start_time,
|
141
|
+
span=span,
|
142
|
+
capture_message_content=capture_message_content,
|
143
|
+
disable_metrics=disable_metrics,
|
144
|
+
version=version,
|
145
|
+
**kwargs
|
146
|
+
)
|
147
|
+
|
148
|
+
except Exception as e:
|
149
|
+
handle_exception(span, e)
|
150
|
+
|
151
|
+
return response
|
149
152
|
|
150
153
|
return wrapper
|
151
154
|
|
152
155
|
def chat_rag(version, environment, application_name,
|
153
|
-
tracer,
|
156
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics):
|
154
157
|
"""
|
155
158
|
Generates a telemetry wrapper for GenAI function call
|
156
159
|
"""
|
@@ -160,32 +163,36 @@ def chat_rag(version, environment, application_name,
|
|
160
163
|
Wraps the GenAI function call.
|
161
164
|
"""
|
162
165
|
|
163
|
-
server_address, server_port = set_server_address_and_port(instance,
|
164
|
-
request_model = kwargs.get(
|
166
|
+
server_address, server_port = set_server_address_and_port(instance, "api.ai21.com", 443)
|
167
|
+
request_model = kwargs.get("model", "jamba-1.5-mini")
|
165
168
|
|
166
|
-
span_name = f
|
169
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
167
170
|
|
168
171
|
with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
|
169
172
|
start_time = time.time()
|
170
173
|
response = wrapped(*args, **kwargs)
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
174
|
+
|
175
|
+
try:
|
176
|
+
response = process_chat_rag_response(
|
177
|
+
response=response,
|
178
|
+
request_model=request_model,
|
179
|
+
pricing_info=pricing_info,
|
180
|
+
server_port=server_port,
|
181
|
+
server_address=server_address,
|
182
|
+
environment=environment,
|
183
|
+
application_name=application_name,
|
184
|
+
metrics=metrics,
|
185
|
+
start_time=start_time,
|
186
|
+
span=span,
|
187
|
+
capture_message_content=capture_message_content,
|
188
|
+
disable_metrics=disable_metrics,
|
189
|
+
version=version,
|
190
|
+
**kwargs
|
191
|
+
)
|
192
|
+
|
193
|
+
except Exception as e:
|
194
|
+
handle_exception(span, e)
|
195
|
+
|
196
|
+
return response
|
190
197
|
|
191
198
|
return wrapper
|
@@ -22,7 +22,7 @@ from openlit.semcov import SemanticConvention
|
|
22
22
|
logger = logging.getLogger(__name__)
|
23
23
|
|
24
24
|
def async_chat(version, environment, application_name,
|
25
|
-
tracer,
|
25
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics):
|
26
26
|
"""
|
27
27
|
Generates a telemetry wrapper for GenAI function call
|
28
28
|
"""
|
@@ -46,9 +46,9 @@ def async_chat(version, environment, application_name,
|
|
46
46
|
self._span = span
|
47
47
|
self._span_name = span_name
|
48
48
|
# Placeholder for aggregating streaming response
|
49
|
-
self._llmresponse =
|
50
|
-
self._response_id =
|
51
|
-
self._finish_reason =
|
49
|
+
self._llmresponse = ""
|
50
|
+
self._response_id = ""
|
51
|
+
self._finish_reason = ""
|
52
52
|
self._input_tokens = 0
|
53
53
|
self._output_tokens = 0
|
54
54
|
self._choices = []
|
@@ -92,14 +92,13 @@ def async_chat(version, environment, application_name,
|
|
92
92
|
environment=environment,
|
93
93
|
application_name=application_name,
|
94
94
|
metrics=metrics,
|
95
|
-
event_provider=event_provider,
|
96
95
|
capture_message_content=capture_message_content,
|
97
96
|
disable_metrics=disable_metrics,
|
98
97
|
version=version
|
99
98
|
)
|
100
99
|
except Exception as e:
|
101
100
|
handle_exception(self._span, e)
|
102
|
-
|
101
|
+
|
103
102
|
raise
|
104
103
|
|
105
104
|
async def wrapper(wrapped, instance, args, kwargs):
|
@@ -108,12 +107,12 @@ def async_chat(version, environment, application_name,
|
|
108
107
|
"""
|
109
108
|
|
110
109
|
# Check if streaming is enabled for the API call
|
111
|
-
streaming = kwargs.get(
|
110
|
+
streaming = kwargs.get("stream", False)
|
112
111
|
|
113
|
-
server_address, server_port = set_server_address_and_port(instance,
|
114
|
-
request_model = kwargs.get(
|
112
|
+
server_address, server_port = set_server_address_and_port(instance, "api.ai21.com", 443)
|
113
|
+
request_model = kwargs.get("model", "jamba-1.5-mini")
|
115
114
|
|
116
|
-
span_name = f
|
115
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
117
116
|
|
118
117
|
# pylint: disable=no-else-return
|
119
118
|
if streaming:
|
@@ -127,30 +126,34 @@ def async_chat(version, environment, application_name,
|
|
127
126
|
with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
|
128
127
|
start_time = time.time()
|
129
128
|
response = await wrapped(*args, **kwargs)
|
130
|
-
response = process_chat_response(
|
131
|
-
response=response,
|
132
|
-
request_model=request_model,
|
133
|
-
pricing_info=pricing_info,
|
134
|
-
server_port=server_port,
|
135
|
-
server_address=server_address,
|
136
|
-
environment=environment,
|
137
|
-
application_name=application_name,
|
138
|
-
metrics=metrics,
|
139
|
-
event_provider=event_provider,
|
140
|
-
start_time=start_time,
|
141
|
-
span=span,
|
142
|
-
capture_message_content=capture_message_content,
|
143
|
-
disable_metrics=disable_metrics,
|
144
|
-
version=version,
|
145
|
-
**kwargs
|
146
|
-
)
|
147
129
|
|
148
|
-
|
130
|
+
try:
|
131
|
+
response = process_chat_response(
|
132
|
+
response=response,
|
133
|
+
request_model=request_model,
|
134
|
+
pricing_info=pricing_info,
|
135
|
+
server_port=server_port,
|
136
|
+
server_address=server_address,
|
137
|
+
environment=environment,
|
138
|
+
application_name=application_name,
|
139
|
+
metrics=metrics,
|
140
|
+
start_time=start_time,
|
141
|
+
span=span,
|
142
|
+
capture_message_content=capture_message_content,
|
143
|
+
disable_metrics=disable_metrics,
|
144
|
+
version=version,
|
145
|
+
**kwargs
|
146
|
+
)
|
147
|
+
|
148
|
+
except Exception as e:
|
149
|
+
handle_exception(span, e)
|
150
|
+
|
151
|
+
return response
|
149
152
|
|
150
153
|
return wrapper
|
151
154
|
|
152
155
|
def async_chat_rag(version, environment, application_name,
|
153
|
-
tracer,
|
156
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics):
|
154
157
|
"""
|
155
158
|
Generates a telemetry wrapper for GenAI function call
|
156
159
|
"""
|
@@ -160,32 +163,36 @@ def async_chat_rag(version, environment, application_name,
|
|
160
163
|
Wraps the GenAI function call.
|
161
164
|
"""
|
162
165
|
|
163
|
-
server_address, server_port = set_server_address_and_port(instance,
|
164
|
-
request_model = kwargs.get(
|
166
|
+
server_address, server_port = set_server_address_and_port(instance, "api.ai21.com", 443)
|
167
|
+
request_model = kwargs.get("model", "jamba-1.5-mini")
|
165
168
|
|
166
|
-
span_name = f
|
169
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
167
170
|
|
168
171
|
with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
|
169
172
|
start_time = time.time()
|
170
173
|
response = await wrapped(*args, **kwargs)
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
174
|
+
|
175
|
+
try:
|
176
|
+
response = process_chat_rag_response(
|
177
|
+
response=response,
|
178
|
+
request_model=request_model,
|
179
|
+
pricing_info=pricing_info,
|
180
|
+
server_port=server_port,
|
181
|
+
server_address=server_address,
|
182
|
+
environment=environment,
|
183
|
+
application_name=application_name,
|
184
|
+
metrics=metrics,
|
185
|
+
start_time=start_time,
|
186
|
+
span=span,
|
187
|
+
capture_message_content=capture_message_content,
|
188
|
+
disable_metrics=disable_metrics,
|
189
|
+
version=version,
|
190
|
+
**kwargs
|
191
|
+
)
|
192
|
+
|
193
|
+
except Exception as e:
|
194
|
+
handle_exception(span, e)
|
195
|
+
|
196
|
+
return response
|
190
197
|
|
191
198
|
return wrapper
|