openlit 1.34.17__py3-none-any.whl → 1.34.19__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/anthropic/__init__.py +20 -22
- openlit/instrumentation/anthropic/anthropic.py +39 -46
- openlit/instrumentation/anthropic/async_anthropic.py +40 -47
- openlit/instrumentation/anthropic/utils.py +144 -170
- openlit/instrumentation/cohere/__init__.py +42 -28
- openlit/instrumentation/cohere/async_cohere.py +148 -557
- openlit/instrumentation/cohere/cohere.py +147 -556
- openlit/instrumentation/cohere/utils.py +330 -0
- {openlit-1.34.17.dist-info → openlit-1.34.19.dist-info}/METADATA +1 -1
- {openlit-1.34.17.dist-info → openlit-1.34.19.dist-info}/RECORD +12 -11
- {openlit-1.34.17.dist-info → openlit-1.34.19.dist-info}/LICENSE +0 -0
- {openlit-1.34.17.dist-info → openlit-1.34.19.dist-info}/WHEEL +0 -0
@@ -3,63 +3,92 @@ Anthropic OpenTelemetry instrumentation utility functions
|
|
3
3
|
"""
|
4
4
|
import time
|
5
5
|
|
6
|
-
from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
|
7
6
|
from opentelemetry.trace import Status, StatusCode
|
8
7
|
|
9
8
|
from openlit.__helpers import (
|
10
9
|
calculate_ttft,
|
11
10
|
response_as_dict,
|
12
11
|
calculate_tbt,
|
13
|
-
extract_and_format_input,
|
14
12
|
get_chat_model_cost,
|
15
|
-
|
16
|
-
|
17
|
-
concatenate_all_contents
|
13
|
+
record_completion_metrics,
|
14
|
+
common_span_attributes,
|
18
15
|
)
|
19
16
|
from openlit.semcov import SemanticConvention
|
20
17
|
|
21
|
-
def
|
18
|
+
def format_content(messages):
|
19
|
+
"""
|
20
|
+
Format the messages into a string for span events.
|
21
|
+
"""
|
22
|
+
|
23
|
+
if not messages:
|
24
|
+
return ""
|
25
|
+
|
26
|
+
formatted_messages = []
|
27
|
+
for message in messages:
|
28
|
+
if isinstance(message, dict):
|
29
|
+
role = message.get("role", "user")
|
30
|
+
content = message.get("content", "")
|
31
|
+
else:
|
32
|
+
# Handle Anthropic object format
|
33
|
+
role = getattr(message, "role", "user")
|
34
|
+
content = getattr(message, "content", "")
|
35
|
+
|
36
|
+
if isinstance(content, list):
|
37
|
+
# Handle structured content (e.g., text + images)
|
38
|
+
text_parts = []
|
39
|
+
for part in content:
|
40
|
+
if isinstance(part, dict) and part.get("type") == "text":
|
41
|
+
text_parts.append(part.get("text", ""))
|
42
|
+
content = " ".join(text_parts)
|
43
|
+
elif not isinstance(content, str):
|
44
|
+
content = str(content)
|
45
|
+
|
46
|
+
formatted_messages.append(f"{role}: {content}")
|
47
|
+
|
48
|
+
return "\n".join(formatted_messages)
|
49
|
+
|
50
|
+
def process_chunk(scope, chunk):
|
22
51
|
"""
|
23
52
|
Process a chunk of response data and update state.
|
24
53
|
"""
|
25
54
|
|
26
55
|
end_time = time.time()
|
27
56
|
# Record the timestamp for the current chunk
|
28
|
-
|
57
|
+
scope._timestamps.append(end_time)
|
29
58
|
|
30
|
-
if len(
|
59
|
+
if len(scope._timestamps) == 1:
|
31
60
|
# Calculate time to first chunk
|
32
|
-
|
61
|
+
scope._ttft = calculate_ttft(scope._timestamps, scope._start_time)
|
33
62
|
|
34
63
|
chunked = response_as_dict(chunk)
|
35
64
|
|
36
65
|
# Collect message IDs and input token from events
|
37
|
-
if chunked.get(
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
66
|
+
if chunked.get("type") == "message_start":
|
67
|
+
scope._response_id = chunked.get("message").get("id")
|
68
|
+
scope._input_tokens = chunked.get("message").get("usage").get("input_tokens")
|
69
|
+
scope._response_model = chunked.get("message").get("model")
|
70
|
+
scope._response_role = chunked.get("message").get("role")
|
42
71
|
|
43
72
|
# Collect message IDs and aggregated response from events
|
44
|
-
if chunked.get(
|
45
|
-
if chunked.get(
|
46
|
-
|
47
|
-
elif chunked.get(
|
48
|
-
|
49
|
-
|
50
|
-
if chunked.get(
|
51
|
-
if chunked.get(
|
52
|
-
|
53
|
-
if chunked.get(
|
54
|
-
|
73
|
+
if chunked.get("type") == "content_block_delta":
|
74
|
+
if chunked.get("delta").get("text"):
|
75
|
+
scope._llmresponse += chunked.get("delta").get("text")
|
76
|
+
elif chunked.get("delta").get("partial_json"):
|
77
|
+
scope._tool_arguments += chunked.get("delta").get("partial_json")
|
78
|
+
|
79
|
+
if chunked.get("type") == "content_block_start":
|
80
|
+
if chunked.get("content_block").get("id"):
|
81
|
+
scope._tool_id = chunked.get("content_block").get("id")
|
82
|
+
if chunked.get("content_block").get("name"):
|
83
|
+
scope._tool_name = chunked.get("content_block").get("name")
|
55
84
|
|
56
85
|
# Collect output tokens and stop reason from events
|
57
|
-
if chunked.get(
|
58
|
-
|
59
|
-
|
86
|
+
if chunked.get("type") == "message_delta":
|
87
|
+
scope._output_tokens = chunked.get("usage").get("output_tokens")
|
88
|
+
scope._finish_reason = chunked.get("delta").get("stop_reason")
|
60
89
|
|
61
90
|
def common_chat_logic(scope, pricing_info, environment, application_name, metrics,
|
62
|
-
|
91
|
+
capture_message_content, disable_metrics, version, is_stream):
|
63
92
|
"""
|
64
93
|
Process chat request and generate Telemetry
|
65
94
|
"""
|
@@ -68,48 +97,56 @@ def common_chat_logic(scope, pricing_info, environment, application_name, metric
|
|
68
97
|
if len(scope._timestamps) > 1:
|
69
98
|
scope._tbt = calculate_tbt(scope._timestamps)
|
70
99
|
|
71
|
-
formatted_messages =
|
72
|
-
request_model = scope._kwargs.get(
|
100
|
+
formatted_messages = format_content(scope._kwargs.get("messages", []))
|
101
|
+
request_model = scope._kwargs.get("model", "claude-3-5-sonnet-latest")
|
73
102
|
|
74
103
|
cost = get_chat_model_cost(request_model, pricing_info, scope._input_tokens, scope._output_tokens)
|
75
104
|
|
76
|
-
#
|
77
|
-
scope
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
scope._span.set_attribute(SemanticConvention.
|
84
|
-
scope._span.set_attribute(SemanticConvention.
|
85
|
-
scope._span.set_attribute(SemanticConvention.
|
86
|
-
scope._span.set_attribute(SemanticConvention.
|
87
|
-
scope._span.set_attribute(SemanticConvention.
|
105
|
+
# Common Span Attributes
|
106
|
+
common_span_attributes(scope,
|
107
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT, SemanticConvention.GEN_AI_SYSTEM_ANTHROPIC,
|
108
|
+
scope._server_address, scope._server_port, request_model, scope._response_model,
|
109
|
+
environment, application_name, is_stream, scope._tbt, scope._ttft, version)
|
110
|
+
|
111
|
+
# Span Attributes for Request parameters
|
112
|
+
scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS, scope._kwargs.get("max_tokens", -1))
|
113
|
+
scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES, scope._kwargs.get("stop_sequences", []))
|
114
|
+
scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE, scope._kwargs.get("temperature", 1.0))
|
115
|
+
scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_K, scope._kwargs.get("top_k", 1.0))
|
116
|
+
scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P, scope._kwargs.get("top_p", 1.0))
|
117
|
+
|
118
|
+
# Span Attributes for Response parameters
|
88
119
|
scope._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID, scope._response_id)
|
89
|
-
scope._span.set_attribute(SemanticConvention.
|
120
|
+
scope._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON, [scope._finish_reason])
|
121
|
+
scope._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE, "text" if isinstance(scope._llmresponse, str) else "json")
|
122
|
+
|
123
|
+
# Span Attributes for Cost and Tokens
|
90
124
|
scope._span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS, scope._input_tokens)
|
91
125
|
scope._span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS, scope._output_tokens)
|
92
|
-
scope._span.set_attribute(SemanticConvention.SERVER_ADDRESS, scope._server_address)
|
93
|
-
|
94
|
-
scope._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
95
|
-
'text' if isinstance(scope._llmresponse, str) else 'json')
|
96
|
-
|
97
|
-
scope._span.set_attribute(DEPLOYMENT_ENVIRONMENT, environment)
|
98
|
-
scope._span.set_attribute(SERVICE_NAME, application_name)
|
99
|
-
scope._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM, is_stream)
|
100
126
|
scope._span.set_attribute(SemanticConvention.GEN_AI_CLIENT_TOKEN_USAGE, scope._input_tokens + scope._output_tokens)
|
101
127
|
scope._span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST, cost)
|
102
|
-
scope._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TBT, scope._tbt)
|
103
|
-
scope._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT, scope._ttft)
|
104
|
-
scope._span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION, version)
|
105
128
|
|
106
|
-
#
|
107
|
-
|
129
|
+
# Handle tool calls if present
|
130
|
+
if scope._tool_calls:
|
131
|
+
# Optimized tool handling - extract name, id, and arguments
|
132
|
+
tool_name = scope._tool_calls.get("name", "")
|
133
|
+
tool_id = scope._tool_calls.get("id", "")
|
134
|
+
tool_args = scope._tool_calls.get("input", "")
|
135
|
+
|
136
|
+
scope._span.set_attribute(SemanticConvention.GEN_AI_TOOL_NAME, tool_name)
|
137
|
+
scope._span.set_attribute(SemanticConvention.GEN_AI_TOOL_CALL_ID, tool_id)
|
138
|
+
scope._span.set_attribute(SemanticConvention.GEN_AI_TOOL_ARGS, str(tool_args))
|
139
|
+
|
140
|
+
# Span Attributes for Content
|
108
141
|
if capture_message_content:
|
142
|
+
scope._span.set_attribute(SemanticConvention.GEN_AI_CONTENT_PROMPT, formatted_messages)
|
143
|
+
scope._span.set_attribute(SemanticConvention.GEN_AI_CONTENT_COMPLETION, scope._llmresponse)
|
144
|
+
|
145
|
+
# To be removed once the change to span_attributes (from span events) is complete
|
109
146
|
scope._span.add_event(
|
110
147
|
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
111
148
|
attributes={
|
112
|
-
SemanticConvention.GEN_AI_CONTENT_PROMPT:
|
149
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: formatted_messages,
|
113
150
|
},
|
114
151
|
)
|
115
152
|
scope._span.add_event(
|
@@ -119,133 +156,70 @@ def common_chat_logic(scope, pricing_info, environment, application_name, metric
|
|
119
156
|
},
|
120
157
|
)
|
121
158
|
|
122
|
-
choice_event_body = {
|
123
|
-
'finish_reason': scope._finish_reason,
|
124
|
-
'index': 0,
|
125
|
-
'message': {
|
126
|
-
**({'content': scope._llmresponse} if capture_message_content else {}),
|
127
|
-
'role': scope._response_role
|
128
|
-
}
|
129
|
-
}
|
130
|
-
|
131
|
-
if scope._tool_calls:
|
132
|
-
choice_event_body['message'].update({
|
133
|
-
'tool_calls': {
|
134
|
-
'function': {
|
135
|
-
'name': scope._tool_calls.get('name', ''),
|
136
|
-
'arguments': scope._tool_calls.get('input', '')
|
137
|
-
},
|
138
|
-
'id': scope._tool_calls.get('id', ''),
|
139
|
-
'type': 'function'
|
140
|
-
}
|
141
|
-
})
|
142
|
-
|
143
|
-
# Emit events
|
144
|
-
for role in ['user', 'system', 'assistant', 'tool']:
|
145
|
-
if formatted_messages.get(role, {}).get('content', ''):
|
146
|
-
event = otel_event(
|
147
|
-
name=getattr(SemanticConvention, f'GEN_AI_{role.upper()}_MESSAGE'),
|
148
|
-
attributes={
|
149
|
-
SemanticConvention.GEN_AI_SYSTEM: SemanticConvention.GEN_AI_SYSTEM_ANTHROPIC
|
150
|
-
},
|
151
|
-
body = {
|
152
|
-
# pylint: disable=line-too-long
|
153
|
-
**({'content': formatted_messages.get(role, {}).get('content', '')} if capture_message_content else {}),
|
154
|
-
'role': formatted_messages.get(role, {}).get('role', []),
|
155
|
-
**({
|
156
|
-
'tool_calls': {
|
157
|
-
'function': {
|
158
|
-
# pylint: disable=line-too-long
|
159
|
-
'name': (scope._tool_calls[0].get('function', {}).get('name', '') if scope._tool_calls else ''),
|
160
|
-
'arguments': (scope._tool_calls[0].get('function', {}).get('arguments', '') if scope._tool_calls else '')
|
161
|
-
},
|
162
|
-
'id': (scope._tool_calls[0].get('id', '') if scope._tool_calls else ''),
|
163
|
-
'type': 'function'
|
164
|
-
}
|
165
|
-
} if role == 'assistant' else {}),
|
166
|
-
**({
|
167
|
-
'id': (scope._tool_calls[0].get('id', '') if scope._tool_calls else '')
|
168
|
-
} if role == 'tool' else {})
|
169
|
-
}
|
170
|
-
)
|
171
|
-
event_provider.emit(event)
|
172
|
-
|
173
|
-
choice_event = otel_event(
|
174
|
-
name=SemanticConvention.GEN_AI_CHOICE,
|
175
|
-
attributes={
|
176
|
-
SemanticConvention.GEN_AI_SYSTEM: SemanticConvention.GEN_AI_SYSTEM_ANTHROPIC
|
177
|
-
},
|
178
|
-
body=choice_event_body
|
179
|
-
)
|
180
|
-
event_provider.emit(choice_event)
|
181
|
-
|
182
159
|
scope._span.set_status(Status(StatusCode.OK))
|
183
160
|
|
161
|
+
# Record metrics
|
184
162
|
if not disable_metrics:
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
system=SemanticConvention.GEN_AI_SYSTEM_ANTHROPIC,
|
190
|
-
request_model=request_model,
|
191
|
-
server_address=scope._server_address,
|
192
|
-
server_port=scope._server_port,
|
193
|
-
response_model=scope._response_model,
|
194
|
-
)
|
163
|
+
record_completion_metrics(metrics, SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT, SemanticConvention.GEN_AI_SYSTEM_ANTHROPIC,
|
164
|
+
scope._server_address, scope._server_port, request_model, scope._response_model, environment,
|
165
|
+
application_name, scope._start_time, scope._end_time, scope._input_tokens, scope._output_tokens,
|
166
|
+
cost, scope._tbt, scope._ttft)
|
195
167
|
|
196
|
-
|
197
|
-
|
198
|
-
metrics['genai_server_tbt'].record(scope._tbt, metrics_attributes)
|
199
|
-
metrics['genai_server_ttft'].record(scope._ttft, metrics_attributes)
|
200
|
-
metrics['genai_requests'].add(1, metrics_attributes)
|
201
|
-
metrics['genai_completion_tokens'].add(scope._output_tokens, metrics_attributes)
|
202
|
-
metrics['genai_prompt_tokens'].add(scope._input_tokens, metrics_attributes)
|
203
|
-
metrics['genai_cost'].record(cost, metrics_attributes)
|
204
|
-
|
205
|
-
def process_streaming_chat_response(self, pricing_info, environment, application_name, metrics,
|
206
|
-
event_provider, capture_message_content=False, disable_metrics=False, version=''):
|
168
|
+
def process_streaming_chat_response(scope, pricing_info, environment, application_name, metrics,
|
169
|
+
capture_message_content=False, disable_metrics=False, version=""):
|
207
170
|
"""
|
208
|
-
Process chat
|
171
|
+
Process streaming chat response and generate telemetry.
|
209
172
|
"""
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
173
|
+
|
174
|
+
if scope._tool_id != "":
|
175
|
+
scope._tool_calls = {
|
176
|
+
"id": scope._tool_id,
|
177
|
+
"name": scope._tool_name,
|
178
|
+
"input": scope._tool_arguments
|
215
179
|
}
|
216
180
|
|
217
|
-
common_chat_logic(
|
218
|
-
|
181
|
+
common_chat_logic(scope, pricing_info, environment, application_name, metrics,
|
182
|
+
capture_message_content, disable_metrics, version, is_stream=True)
|
219
183
|
|
220
184
|
def process_chat_response(response, request_model, pricing_info, server_port, server_address,
|
221
|
-
environment, application_name, metrics,
|
222
|
-
span, capture_message_content=False, disable_metrics=False, version=
|
185
|
+
environment, application_name, metrics, start_time,
|
186
|
+
span, capture_message_content=False, disable_metrics=False, version="1.0.0", **kwargs):
|
223
187
|
"""
|
224
|
-
Process chat
|
188
|
+
Process non-streaming chat response and generate telemetry.
|
225
189
|
"""
|
226
190
|
|
227
|
-
|
191
|
+
scope = type("GenericScope", (), {})()
|
228
192
|
response_dict = response_as_dict(response)
|
229
193
|
|
230
194
|
# pylint: disable = no-member
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
195
|
+
scope._start_time = start_time
|
196
|
+
scope._end_time = time.time()
|
197
|
+
scope._span = span
|
198
|
+
scope._llmresponse = response_dict.get("content", [{}])[0].get("text", "")
|
199
|
+
scope._response_role = response_dict.get("role", "assistant")
|
200
|
+
scope._input_tokens = response_dict.get("usage").get("input_tokens")
|
201
|
+
scope._output_tokens = response_dict.get("usage").get("output_tokens")
|
202
|
+
scope._response_model = response_dict.get("model", "")
|
203
|
+
scope._finish_reason = response_dict.get("stop_reason", "")
|
204
|
+
scope._response_id = response_dict.get("id", "")
|
205
|
+
scope._timestamps = []
|
206
|
+
scope._ttft, scope._tbt = scope._end_time - scope._start_time, 0
|
207
|
+
scope._server_address, scope._server_port = server_address, server_port
|
208
|
+
scope._kwargs = kwargs
|
209
|
+
|
210
|
+
# Handle tool calls if present
|
211
|
+
content_blocks = response_dict.get("content", [])
|
212
|
+
scope._tool_calls = None
|
213
|
+
for block in content_blocks:
|
214
|
+
if block.get("type") == "tool_use":
|
215
|
+
scope._tool_calls = {
|
216
|
+
"id": block.get("id", ""),
|
217
|
+
"name": block.get("name", ""),
|
218
|
+
"input": block.get("input", "")
|
219
|
+
}
|
220
|
+
break
|
221
|
+
|
222
|
+
common_chat_logic(scope, pricing_info, environment, application_name, metrics,
|
223
|
+
capture_message_content, disable_metrics, version, is_stream=False)
|
250
224
|
|
251
225
|
return response
|
@@ -1,74 +1,88 @@
|
|
1
|
-
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
1
|
"""Initializer of Auto Instrumentation of Cohere Functions"""
|
2
|
+
|
3
3
|
from typing import Collection
|
4
4
|
import importlib.metadata
|
5
5
|
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
6
6
|
from wrapt import wrap_function_wrapper
|
7
7
|
|
8
|
-
from openlit.instrumentation.cohere.cohere import
|
9
|
-
|
10
|
-
|
8
|
+
from openlit.instrumentation.cohere.cohere import (
|
9
|
+
chat,
|
10
|
+
chat_stream,
|
11
|
+
embed
|
12
|
+
)
|
13
|
+
from openlit.instrumentation.cohere.async_cohere import (
|
14
|
+
async_chat,
|
15
|
+
async_chat_stream,
|
16
|
+
async_embed
|
17
|
+
)
|
11
18
|
|
12
19
|
_instruments = ("cohere >= 5.14.0",)
|
13
20
|
|
14
21
|
class CohereInstrumentor(BaseInstrumentor):
|
15
|
-
"""
|
22
|
+
"""
|
23
|
+
An instrumentor for Cohere client library.
|
24
|
+
"""
|
16
25
|
|
17
26
|
def instrumentation_dependencies(self) -> Collection[str]:
|
18
27
|
return _instruments
|
19
28
|
|
20
29
|
def _instrument(self, **kwargs):
|
21
|
-
application_name = kwargs.get("application_name")
|
22
|
-
environment = kwargs.get("environment")
|
30
|
+
application_name = kwargs.get("application_name", "default")
|
31
|
+
environment = kwargs.get("environment", "default")
|
23
32
|
tracer = kwargs.get("tracer")
|
24
33
|
metrics = kwargs.get("metrics_dict")
|
25
|
-
pricing_info = kwargs.get("pricing_info")
|
26
|
-
capture_message_content = kwargs.get("capture_message_content")
|
34
|
+
pricing_info = kwargs.get("pricing_info", {})
|
35
|
+
capture_message_content = kwargs.get("capture_message_content", False)
|
27
36
|
disable_metrics = kwargs.get("disable_metrics")
|
28
37
|
version = importlib.metadata.version("cohere")
|
29
38
|
|
30
|
-
#
|
39
|
+
# sync chat completions
|
31
40
|
wrap_function_wrapper(
|
32
|
-
"cohere.client_v2",
|
33
|
-
"ClientV2.chat",
|
41
|
+
"cohere.client_v2",
|
42
|
+
"ClientV2.chat",
|
34
43
|
chat(version, environment, application_name,
|
35
|
-
|
44
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
36
45
|
)
|
46
|
+
|
47
|
+
# sync chat streaming
|
37
48
|
wrap_function_wrapper(
|
38
|
-
"cohere.client_v2",
|
39
|
-
"ClientV2.chat_stream",
|
49
|
+
"cohere.client_v2",
|
50
|
+
"ClientV2.chat_stream",
|
40
51
|
chat_stream(version, environment, application_name,
|
41
|
-
|
52
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
42
53
|
)
|
54
|
+
|
55
|
+
# sync embeddings
|
43
56
|
wrap_function_wrapper(
|
44
|
-
"cohere.client_v2",
|
45
|
-
"ClientV2.embed",
|
57
|
+
"cohere.client_v2",
|
58
|
+
"ClientV2.embed",
|
46
59
|
embed(version, environment, application_name,
|
47
60
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
48
61
|
)
|
49
62
|
|
50
|
-
#
|
63
|
+
# async chat completions
|
51
64
|
wrap_function_wrapper(
|
52
|
-
"cohere.client_v2",
|
53
|
-
"AsyncClientV2.chat",
|
65
|
+
"cohere.client_v2",
|
66
|
+
"AsyncClientV2.chat",
|
54
67
|
async_chat(version, environment, application_name,
|
55
|
-
|
68
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
56
69
|
)
|
57
70
|
|
71
|
+
# async chat streaming
|
58
72
|
wrap_function_wrapper(
|
59
|
-
"cohere.client_v2",
|
60
|
-
"AsyncClientV2.chat_stream",
|
73
|
+
"cohere.client_v2",
|
74
|
+
"AsyncClientV2.chat_stream",
|
61
75
|
async_chat_stream(version, environment, application_name,
|
62
|
-
|
76
|
+
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
63
77
|
)
|
64
78
|
|
79
|
+
# async embeddings
|
65
80
|
wrap_function_wrapper(
|
66
|
-
"cohere.client_v2",
|
67
|
-
"AsyncClientV2.embed",
|
81
|
+
"cohere.client_v2",
|
82
|
+
"AsyncClientV2.embed",
|
68
83
|
async_embed(version, environment, application_name,
|
69
84
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
70
85
|
)
|
71
86
|
|
72
|
-
@staticmethod
|
73
87
|
def _uninstrument(self, **kwargs):
|
74
88
|
pass
|