@arizeai/openinference-instrumentation-openai 4.0.5 → 4.0.6
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.
- package/README.md +1 -3
- package/dist/esm/instrumentation.d.ts +5 -4
- package/dist/esm/instrumentation.d.ts.map +1 -1
- package/dist/esm/instrumentation.js +23 -31
- package/dist/esm/instrumentation.js.map +1 -1
- package/dist/esm/responsesAttributes.d.ts +3 -3
- package/dist/esm/responsesAttributes.d.ts.map +1 -1
- package/dist/esm/responsesAttributes.js +30 -33
- package/dist/esm/responsesAttributes.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esnext/instrumentation.d.ts +5 -4
- package/dist/esnext/instrumentation.d.ts.map +1 -1
- package/dist/esnext/instrumentation.js +21 -28
- package/dist/esnext/instrumentation.js.map +1 -1
- package/dist/esnext/responsesAttributes.d.ts +3 -3
- package/dist/esnext/responsesAttributes.d.ts.map +1 -1
- package/dist/esnext/responsesAttributes.js +30 -33
- package/dist/esnext/responsesAttributes.js.map +1 -1
- package/dist/esnext/tsconfig.esnext.tsbuildinfo +1 -1
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/src/instrumentation.d.ts +5 -4
- package/dist/src/instrumentation.d.ts.map +1 -1
- package/dist/src/instrumentation.js +20 -27
- package/dist/src/instrumentation.js.map +1 -1
- package/dist/src/responsesAttributes.d.ts +3 -3
- package/dist/src/responsesAttributes.d.ts.map +1 -1
- package/dist/src/responsesAttributes.js +30 -33
- package/dist/src/responsesAttributes.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -19
- package/src/instrumentation.ts +126 -254
- package/src/responsesAttributes.ts +49 -90
- package/src/version.ts +1 -1
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { Attributes } from "@opentelemetry/api";
|
|
5
|
-
|
|
6
|
-
import {
|
|
1
|
+
import type { Attributes } from "@opentelemetry/api";
|
|
2
|
+
import type {
|
|
7
3
|
Response as ResponseType,
|
|
8
4
|
ResponseCreateParamsBase,
|
|
9
5
|
ResponseInputItem,
|
|
10
6
|
ResponseOutputItem,
|
|
11
7
|
ResponseStreamEvent,
|
|
12
8
|
} from "openai/resources/responses/responses";
|
|
13
|
-
import { Stream } from "openai/streaming";
|
|
9
|
+
import type { Stream } from "openai/streaming";
|
|
10
|
+
|
|
11
|
+
import { safelyJSONStringify } from "@arizeai/openinference-core";
|
|
12
|
+
import { SemanticConventions } from "@arizeai/openinference-semantic-conventions";
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* Get attributes for responses api Items that are not typical messages with role
|
|
@@ -31,23 +30,17 @@ function getResponseItemAttributes(
|
|
|
31
30
|
case "function_call": {
|
|
32
31
|
attributes[`${prefix}${SemanticConventions.MESSAGE_ROLE}`] = "assistant";
|
|
33
32
|
// now using tool call prefix to simulate multiple tool calls per message
|
|
34
|
-
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_ID}`] =
|
|
35
|
-
|
|
36
|
-
attributes[
|
|
37
|
-
|
|
38
|
-
] = item.name;
|
|
39
|
-
attributes[
|
|
40
|
-
`${toolCallPrefix}${SemanticConventions.TOOL_CALL_FUNCTION_ARGUMENTS_JSON}`
|
|
41
|
-
] = item.arguments;
|
|
33
|
+
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_ID}`] = item.call_id;
|
|
34
|
+
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_FUNCTION_NAME}`] = item.name;
|
|
35
|
+
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_FUNCTION_ARGUMENTS_JSON}`] =
|
|
36
|
+
item.arguments;
|
|
42
37
|
break;
|
|
43
38
|
}
|
|
44
39
|
case "function_call_output": {
|
|
45
40
|
attributes[`${prefix}${SemanticConventions.MESSAGE_ROLE}`] = "tool";
|
|
46
|
-
attributes[`${prefix}${SemanticConventions.MESSAGE_TOOL_CALL_ID}`] =
|
|
47
|
-
item.call_id;
|
|
41
|
+
attributes[`${prefix}${SemanticConventions.MESSAGE_TOOL_CALL_ID}`] = item.call_id;
|
|
48
42
|
if (typeof item.output === "string") {
|
|
49
|
-
attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] =
|
|
50
|
-
item.output;
|
|
43
|
+
attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] = item.output;
|
|
51
44
|
} else {
|
|
52
45
|
// TODO(2410): figure out how to serialize the list of tools
|
|
53
46
|
attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] =
|
|
@@ -61,12 +54,10 @@ function getResponseItemAttributes(
|
|
|
61
54
|
item.summary.forEach((summaryItem, index) => {
|
|
62
55
|
const summaryItemPrefix = `${prefix}${SemanticConventions.MESSAGE_CONTENTS}.${index}.`;
|
|
63
56
|
if (summaryItem.type === "summary_text") {
|
|
64
|
-
attributes[
|
|
65
|
-
|
|
66
|
-
] =
|
|
67
|
-
|
|
68
|
-
`${summaryItemPrefix}${SemanticConventions.MESSAGE_CONTENT_TEXT}`
|
|
69
|
-
] = summaryItem.text;
|
|
57
|
+
attributes[`${summaryItemPrefix}${SemanticConventions.MESSAGE_CONTENT_TYPE}`] =
|
|
58
|
+
"summary_text";
|
|
59
|
+
attributes[`${summaryItemPrefix}${SemanticConventions.MESSAGE_CONTENT_TEXT}`] =
|
|
60
|
+
summaryItem.text;
|
|
70
61
|
}
|
|
71
62
|
});
|
|
72
63
|
break;
|
|
@@ -77,56 +68,42 @@ function getResponseItemAttributes(
|
|
|
77
68
|
case "file_search_call": {
|
|
78
69
|
if (!item.results) {
|
|
79
70
|
// its a tool call
|
|
80
|
-
attributes[`${prefix}${SemanticConventions.MESSAGE_ROLE}`] =
|
|
81
|
-
"assistant";
|
|
71
|
+
attributes[`${prefix}${SemanticConventions.MESSAGE_ROLE}`] = "assistant";
|
|
82
72
|
// now using tool call prefix to simulate multiple tool calls per message
|
|
83
|
-
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_ID}`] =
|
|
84
|
-
|
|
85
|
-
attributes[
|
|
86
|
-
|
|
87
|
-
] = item.type;
|
|
88
|
-
attributes[
|
|
89
|
-
`${toolCallPrefix}${SemanticConventions.TOOL_CALL_FUNCTION_ARGUMENTS_JSON}`
|
|
90
|
-
] = JSON.stringify(item.queries);
|
|
73
|
+
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_ID}`] = item.id;
|
|
74
|
+
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_FUNCTION_NAME}`] = item.type;
|
|
75
|
+
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_FUNCTION_ARGUMENTS_JSON}`] =
|
|
76
|
+
JSON.stringify(item.queries);
|
|
91
77
|
} else {
|
|
92
78
|
// its a tool call output
|
|
93
79
|
attributes[`${prefix}${SemanticConventions.MESSAGE_ROLE}`] = "tool";
|
|
94
|
-
attributes[`${prefix}${SemanticConventions.MESSAGE_TOOL_CALL_ID}`] =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
80
|
+
attributes[`${prefix}${SemanticConventions.MESSAGE_TOOL_CALL_ID}`] = item.id;
|
|
81
|
+
attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] = JSON.stringify(
|
|
82
|
+
item.results,
|
|
83
|
+
);
|
|
98
84
|
}
|
|
99
85
|
break;
|
|
100
86
|
}
|
|
101
87
|
case "computer_call": {
|
|
102
88
|
attributes[`${prefix}${SemanticConventions.MESSAGE_ROLE}`] = "assistant";
|
|
103
89
|
// now using tool call prefix to simulate multiple tool calls per message
|
|
104
|
-
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_ID}`] =
|
|
105
|
-
|
|
106
|
-
attributes[
|
|
107
|
-
|
|
108
|
-
] = item.type;
|
|
109
|
-
attributes[
|
|
110
|
-
`${toolCallPrefix}${SemanticConventions.TOOL_CALL_FUNCTION_ARGUMENTS_JSON}`
|
|
111
|
-
] = JSON.stringify(item.action);
|
|
90
|
+
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_ID}`] = item.id;
|
|
91
|
+
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_FUNCTION_NAME}`] = item.type;
|
|
92
|
+
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_FUNCTION_ARGUMENTS_JSON}`] =
|
|
93
|
+
JSON.stringify(item.action);
|
|
112
94
|
break;
|
|
113
95
|
}
|
|
114
96
|
case "computer_call_output": {
|
|
115
97
|
attributes[`${prefix}${SemanticConventions.MESSAGE_ROLE}`] = "tool";
|
|
116
|
-
attributes[`${prefix}${SemanticConventions.MESSAGE_TOOL_CALL_ID}`] =
|
|
117
|
-
|
|
118
|
-
attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] =
|
|
119
|
-
JSON.stringify(item.output);
|
|
98
|
+
attributes[`${prefix}${SemanticConventions.MESSAGE_TOOL_CALL_ID}`] = item.call_id;
|
|
99
|
+
attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] = JSON.stringify(item.output);
|
|
120
100
|
break;
|
|
121
101
|
}
|
|
122
102
|
case "web_search_call": {
|
|
123
103
|
attributes[`${prefix}${SemanticConventions.MESSAGE_ROLE}`] = "assistant";
|
|
124
104
|
// now using tool call prefix to simulate multiple tool calls per message
|
|
125
|
-
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_ID}`] =
|
|
126
|
-
|
|
127
|
-
attributes[
|
|
128
|
-
`${toolCallPrefix}${SemanticConventions.TOOL_CALL_FUNCTION_NAME}`
|
|
129
|
-
] = item.type;
|
|
105
|
+
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_ID}`] = item.id;
|
|
106
|
+
attributes[`${toolCallPrefix}${SemanticConventions.TOOL_CALL_FUNCTION_NAME}`] = item.type;
|
|
130
107
|
// web search call does not share its arguments with the caller
|
|
131
108
|
// it will show "undefined" in the arguments when traced
|
|
132
109
|
break;
|
|
@@ -159,29 +136,21 @@ function getResponseItemMessageAttributes(
|
|
|
159
136
|
};
|
|
160
137
|
// add contents from message
|
|
161
138
|
if (typeof message.content === "string") {
|
|
162
|
-
attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] =
|
|
163
|
-
message.content;
|
|
139
|
+
attributes[`${prefix}${SemanticConventions.MESSAGE_CONTENT}`] = message.content;
|
|
164
140
|
} else if (Array.isArray(message.content)) {
|
|
165
141
|
message.content.forEach((part, index) => {
|
|
166
142
|
const contentsIndexPrefix = `${prefix}${SemanticConventions.MESSAGE_CONTENTS}.${index}.`;
|
|
167
143
|
if (part.type === "input_text") {
|
|
168
|
-
attributes[
|
|
169
|
-
|
|
170
|
-
] =
|
|
171
|
-
attributes[
|
|
172
|
-
`${contentsIndexPrefix}${SemanticConventions.MESSAGE_CONTENT_TEXT}`
|
|
173
|
-
] = part.text;
|
|
144
|
+
attributes[`${contentsIndexPrefix}${SemanticConventions.MESSAGE_CONTENT_TYPE}`] =
|
|
145
|
+
"input_text";
|
|
146
|
+
attributes[`${contentsIndexPrefix}${SemanticConventions.MESSAGE_CONTENT_TEXT}`] = part.text;
|
|
174
147
|
} else if (part.type === "output_text") {
|
|
175
|
-
attributes[
|
|
176
|
-
|
|
177
|
-
] =
|
|
178
|
-
attributes[
|
|
179
|
-
`${contentsIndexPrefix}${SemanticConventions.MESSAGE_CONTENT_TEXT}`
|
|
180
|
-
] = part.text;
|
|
148
|
+
attributes[`${contentsIndexPrefix}${SemanticConventions.MESSAGE_CONTENT_TYPE}`] =
|
|
149
|
+
"output_text";
|
|
150
|
+
attributes[`${contentsIndexPrefix}${SemanticConventions.MESSAGE_CONTENT_TEXT}`] = part.text;
|
|
181
151
|
} else if (part.type === "input_image") {
|
|
182
|
-
attributes[
|
|
183
|
-
|
|
184
|
-
] = "input_image";
|
|
152
|
+
attributes[`${contentsIndexPrefix}${SemanticConventions.MESSAGE_CONTENT_TYPE}`] =
|
|
153
|
+
"input_image";
|
|
185
154
|
if (part.image_url) {
|
|
186
155
|
attributes[
|
|
187
156
|
`${contentsIndexPrefix}${SemanticConventions.MESSAGE_CONTENT_IMAGE}.${SemanticConventions.IMAGE_URL}`
|
|
@@ -190,12 +159,9 @@ function getResponseItemMessageAttributes(
|
|
|
190
159
|
} else if (part.type === "input_file") {
|
|
191
160
|
// TODO: Handle input file
|
|
192
161
|
} else if (part.type === "refusal") {
|
|
193
|
-
attributes[
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
attributes[
|
|
197
|
-
`${contentsIndexPrefix}${SemanticConventions.MESSAGE_CONTENT_TEXT}`
|
|
198
|
-
] = part.refusal;
|
|
162
|
+
attributes[`${contentsIndexPrefix}${SemanticConventions.MESSAGE_CONTENT_TYPE}`] = "refusal";
|
|
163
|
+
attributes[`${contentsIndexPrefix}${SemanticConventions.MESSAGE_CONTENT_TEXT}`] =
|
|
164
|
+
part.refusal;
|
|
199
165
|
}
|
|
200
166
|
});
|
|
201
167
|
}
|
|
@@ -219,9 +185,7 @@ function getResponseItemMessageAttributes(
|
|
|
219
185
|
return attributes;
|
|
220
186
|
}
|
|
221
187
|
|
|
222
|
-
export function getResponsesInputMessagesAttributes(
|
|
223
|
-
body: ResponseCreateParamsBase,
|
|
224
|
-
): Attributes {
|
|
188
|
+
export function getResponsesInputMessagesAttributes(body: ResponseCreateParamsBase): Attributes {
|
|
225
189
|
const attributes: Attributes = {};
|
|
226
190
|
const items: ResponseInputItem[] = [];
|
|
227
191
|
if (body.instructions) {
|
|
@@ -243,13 +207,10 @@ export function getResponsesInputMessagesAttributes(
|
|
|
243
207
|
return attributes;
|
|
244
208
|
}
|
|
245
209
|
|
|
246
|
-
export function getResponsesUsageAttributes(
|
|
247
|
-
response: ResponseType,
|
|
248
|
-
): Attributes {
|
|
210
|
+
export function getResponsesUsageAttributes(response: ResponseType): Attributes {
|
|
249
211
|
if (response.usage) {
|
|
250
212
|
return {
|
|
251
|
-
[SemanticConventions.LLM_TOKEN_COUNT_COMPLETION]:
|
|
252
|
-
response.usage.output_tokens,
|
|
213
|
+
[SemanticConventions.LLM_TOKEN_COUNT_COMPLETION]: response.usage.output_tokens,
|
|
253
214
|
[SemanticConventions.LLM_TOKEN_COUNT_PROMPT]: response.usage.input_tokens,
|
|
254
215
|
[SemanticConventions.LLM_TOKEN_COUNT_TOTAL]: response.usage.total_tokens,
|
|
255
216
|
[SemanticConventions.LLM_TOKEN_COUNT_PROMPT_DETAILS_CACHE_READ]:
|
|
@@ -262,9 +223,7 @@ export function getResponsesUsageAttributes(
|
|
|
262
223
|
return {};
|
|
263
224
|
}
|
|
264
225
|
|
|
265
|
-
export function getResponsesOutputMessagesAttributes(
|
|
266
|
-
response: ResponseType,
|
|
267
|
-
): Attributes {
|
|
226
|
+
export function getResponsesOutputMessagesAttributes(response: ResponseType): Attributes {
|
|
268
227
|
const attributes: Attributes = {};
|
|
269
228
|
const items = response.output;
|
|
270
229
|
items.forEach((item, index) => {
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// this is an auto-generated file. see js/scripts/version-update.js
|
|
2
|
-
export const VERSION = "4.0.
|
|
2
|
+
export const VERSION = "4.0.6";
|