@arizeai/openinference-instrumentation-openai 4.1.8 → 4.1.9
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 +13 -26
- 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 +14 -28
- 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 +14 -28
- 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/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/instrumentation.ts +20 -25
- 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": "4.1.
|
|
3
|
+
"version": "4.1.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "OpenInference instrumentation for OpenAI",
|
|
6
6
|
"keywords": [],
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@opentelemetry/api": "^1.9.0",
|
|
29
29
|
"@opentelemetry/core": "^2.8.0",
|
|
30
30
|
"@opentelemetry/instrumentation": "^0.46.0",
|
|
31
|
-
"@arizeai/openinference-core": "2.5.
|
|
31
|
+
"@arizeai/openinference-core": "2.5.2",
|
|
32
32
|
"@arizeai/openinference-semantic-conventions": "2.7.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
package/src/instrumentation.ts
CHANGED
|
@@ -132,23 +132,19 @@ function getLLMProvider(clientInstance: unknown): LLMProvider | undefined {
|
|
|
132
132
|
try {
|
|
133
133
|
// The clientInstance might be a sub-object (like Completions) that has a _client property
|
|
134
134
|
// pointing to the actual OpenAI/AzureOpenAI client
|
|
135
|
-
const instance = clientInstance as {
|
|
136
|
-
baseURL?: string | { host?: string };
|
|
137
|
-
_client?: {
|
|
138
|
-
baseURL?: string | { host?: string };
|
|
139
|
-
};
|
|
140
|
-
};
|
|
141
|
-
|
|
142
135
|
let host: string | undefined;
|
|
143
|
-
let baseURL:
|
|
136
|
+
let baseURL: unknown;
|
|
144
137
|
|
|
145
138
|
// First try to get baseURL from the instance itself
|
|
146
|
-
if (
|
|
147
|
-
baseURL =
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
139
|
+
if (clientInstance != null && typeof clientInstance === "object") {
|
|
140
|
+
baseURL = Reflect.get(clientInstance, "baseURL");
|
|
141
|
+
// If not found (or empty), try the _client property (this is where Azure OpenAI stores it)
|
|
142
|
+
if (!baseURL) {
|
|
143
|
+
const nestedClient = Reflect.get(clientInstance, "_client");
|
|
144
|
+
if (nestedClient != null && typeof nestedClient === "object") {
|
|
145
|
+
baseURL = Reflect.get(nestedClient, "baseURL");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
152
148
|
}
|
|
153
149
|
|
|
154
150
|
if (typeof baseURL === "string") {
|
|
@@ -162,7 +158,7 @@ function getLLMProvider(clientInstance: unknown): LLMProvider | undefined {
|
|
|
162
158
|
}
|
|
163
159
|
} else if (baseURL && typeof baseURL === "object" && "host" in baseURL) {
|
|
164
160
|
// Direct host property
|
|
165
|
-
host = baseURL.host;
|
|
161
|
+
host = typeof baseURL.host === "string" ? baseURL.host : undefined;
|
|
166
162
|
}
|
|
167
163
|
|
|
168
164
|
if (host && typeof host === "string") {
|
|
@@ -335,7 +331,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
335
331
|
// handle the chunks and add them to the span
|
|
336
332
|
// First split the stream via tee
|
|
337
333
|
const [leftStream, rightStream] = result.tee();
|
|
338
|
-
consumeChatCompletionStreamChunks(rightStream, span);
|
|
334
|
+
void consumeChatCompletionStreamChunks(rightStream, span);
|
|
339
335
|
result = leftStream;
|
|
340
336
|
}
|
|
341
337
|
|
|
@@ -547,7 +543,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
547
543
|
const [leftStream, rightStream] = result.tee();
|
|
548
544
|
// take the right stream, consuming it and then recording the final chunk
|
|
549
545
|
// into the span
|
|
550
|
-
consumeResponseStreamEvents(rightStream).then(recordSpan);
|
|
546
|
+
void consumeResponseStreamEvents(rightStream).then(recordSpan);
|
|
551
547
|
// give the left stream back to the caller
|
|
552
548
|
result = leftStream;
|
|
553
549
|
}
|
|
@@ -1005,15 +1001,14 @@ function isAPIPromise<T>(promise: unknown): promise is APIPromise<T> {
|
|
|
1005
1001
|
* @param then - The thennable to invoke
|
|
1006
1002
|
* @returns The promise with the thennable invoked
|
|
1007
1003
|
*/
|
|
1008
|
-
function invokeMaybeAPIPromise<T>(
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
)
|
|
1013
|
-
|
|
1014
|
-
return promise._thenUnwrap(then) as T;
|
|
1004
|
+
function invokeMaybeAPIPromise<T>(promise: APIPromise<T>, then: (value: T) => T): APIPromise<T>;
|
|
1005
|
+
function invokeMaybeAPIPromise<T>(promise: Promise<T>, then: (value: T) => T): Promise<T>;
|
|
1006
|
+
function invokeMaybeAPIPromise<T>(promise: T, then: (value: T) => T): T;
|
|
1007
|
+
function invokeMaybeAPIPromise(promise: unknown, then: (value: unknown) => unknown): unknown {
|
|
1008
|
+
if (isAPIPromise<unknown>(promise)) {
|
|
1009
|
+
return promise._thenUnwrap(then);
|
|
1015
1010
|
} else if (promise instanceof Promise) {
|
|
1016
|
-
return promise.then(then)
|
|
1011
|
+
return promise.then(then);
|
|
1017
1012
|
} else {
|
|
1018
1013
|
// eslint-disable-next-line no-console
|
|
1019
1014
|
console.warn("Promise is not an APIPromise or a regular promise, cannot instrument.");
|
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.1.
|
|
2
|
+
export const VERSION = "4.1.9";
|