@arizeai/openinference-instrumentation-openai 0.4.1 → 0.6.0
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/dist/esm/instrumentation.d.ts.map +1 -1
- package/dist/esm/instrumentation.js +21 -3
- package/dist/esm/instrumentation.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.map +1 -1
- package/dist/esnext/instrumentation.js +21 -3
- package/dist/esnext/instrumentation.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.map +1 -1
- package/dist/src/instrumentation.js +20 -2
- package/dist/src/instrumentation.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/test/openai.test.js +178 -152
- package/dist/test/openai.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -2
- package/src/instrumentation.ts +29 -0
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arizeai/openinference-instrumentation-openai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "OpenInference instrumentation for OpenAI",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"@opentelemetry/api": "^1.9.0",
|
|
16
16
|
"@opentelemetry/core": "^1.25.1",
|
|
17
17
|
"@opentelemetry/instrumentation": "^0.46.0",
|
|
18
|
-
"@arizeai/openinference-
|
|
18
|
+
"@arizeai/openinference-core": "0.3.0",
|
|
19
|
+
"@arizeai/openinference-semantic-conventions": "0.11.0"
|
|
19
20
|
},
|
|
20
21
|
"keywords": [],
|
|
21
22
|
"files": [
|
|
@@ -25,10 +26,12 @@
|
|
|
25
26
|
"author": "oss-devs@arize.com",
|
|
26
27
|
"license": "Apache-2.0",
|
|
27
28
|
"devDependencies": {
|
|
29
|
+
"@opentelemetry/exporter-trace-otlp-proto": "^0.50.0",
|
|
28
30
|
"@opentelemetry/resources": "^1.25.1",
|
|
29
31
|
"@opentelemetry/sdk-trace-base": "^1.25.1",
|
|
30
32
|
"@opentelemetry/sdk-trace-node": "^1.25.1",
|
|
31
33
|
"@opentelemetry/semantic-conventions": "^1.25.1",
|
|
34
|
+
"jest": "^29.7.0",
|
|
32
35
|
"openai": "^4.52.7"
|
|
33
36
|
},
|
|
34
37
|
"scripts": {
|
package/src/instrumentation.ts
CHANGED
|
@@ -20,6 +20,8 @@ import {
|
|
|
20
20
|
SemanticConventions,
|
|
21
21
|
OpenInferenceSpanKind,
|
|
22
22
|
MimeType,
|
|
23
|
+
LLMSystem,
|
|
24
|
+
LLMProvider,
|
|
23
25
|
} from "@arizeai/openinference-semantic-conventions";
|
|
24
26
|
import {
|
|
25
27
|
ChatCompletion,
|
|
@@ -38,6 +40,8 @@ import {
|
|
|
38
40
|
import { assertUnreachable, isString } from "./typeUtils";
|
|
39
41
|
import { isTracingSuppressed } from "@opentelemetry/core";
|
|
40
42
|
|
|
43
|
+
import { safelyJSONStringify } from "@arizeai/openinference-core";
|
|
44
|
+
|
|
41
45
|
const MODULE_NAME = "openai";
|
|
42
46
|
|
|
43
47
|
/**
|
|
@@ -139,7 +143,10 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
139
143
|
[SemanticConventions.INPUT_MIME_TYPE]: MimeType.JSON,
|
|
140
144
|
[SemanticConventions.LLM_INVOCATION_PARAMETERS]:
|
|
141
145
|
JSON.stringify(invocationParameters),
|
|
146
|
+
[SemanticConventions.LLM_SYSTEM]: LLMSystem.OPENAI,
|
|
147
|
+
[SemanticConventions.LLM_PROVIDER]: LLMProvider.OPENAI,
|
|
142
148
|
...getLLMInputMessagesAttributes(body),
|
|
149
|
+
...getLLMToolsJSONSchema(body),
|
|
143
150
|
},
|
|
144
151
|
},
|
|
145
152
|
);
|
|
@@ -217,6 +224,8 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
217
224
|
[SemanticConventions.LLM_MODEL_NAME]: body.model,
|
|
218
225
|
[SemanticConventions.LLM_INVOCATION_PARAMETERS]:
|
|
219
226
|
JSON.stringify(invocationParameters),
|
|
227
|
+
[SemanticConventions.LLM_SYSTEM]: LLMSystem.OPENAI,
|
|
228
|
+
[SemanticConventions.LLM_PROVIDER]: LLMProvider.OPENAI,
|
|
220
229
|
...getCompletionInputValueAndMimeType(body),
|
|
221
230
|
},
|
|
222
231
|
});
|
|
@@ -409,6 +418,26 @@ function getLLMInputMessagesAttributes(
|
|
|
409
418
|
}, {} as Attributes);
|
|
410
419
|
}
|
|
411
420
|
|
|
421
|
+
/**
|
|
422
|
+
* Converts each tool definition into a json schema
|
|
423
|
+
*/
|
|
424
|
+
function getLLMToolsJSONSchema(
|
|
425
|
+
body: ChatCompletionCreateParamsBase,
|
|
426
|
+
): Attributes {
|
|
427
|
+
if (!body.tools) {
|
|
428
|
+
// If tools is undefined, return an empty object
|
|
429
|
+
return {};
|
|
430
|
+
}
|
|
431
|
+
return body.tools.reduce((acc: Attributes, tool, index) => {
|
|
432
|
+
const toolJsonSchema = safelyJSONStringify(tool);
|
|
433
|
+
const key = `${SemanticConventions.LLM_TOOLS}.${index}.${SemanticConventions.TOOL_JSON_SCHEMA}`;
|
|
434
|
+
if (toolJsonSchema) {
|
|
435
|
+
acc[key] = toolJsonSchema;
|
|
436
|
+
}
|
|
437
|
+
return acc;
|
|
438
|
+
}, {});
|
|
439
|
+
}
|
|
440
|
+
|
|
412
441
|
function getChatCompletionInputMessageAttributes(
|
|
413
442
|
message: ChatCompletionMessageParam,
|
|
414
443
|
): Attributes {
|
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 = "0.
|
|
2
|
+
export const VERSION = "0.6.0";
|