@arizeai/openinference-instrumentation-openai 4.1.7 → 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 +17 -27
- 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 +18 -29
- 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 +18 -29
- 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 +3 -3
- package/src/instrumentation.ts +24 -26
- 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,8 +28,8 @@
|
|
|
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.
|
|
32
|
-
"@arizeai/openinference-semantic-conventions": "2.
|
|
31
|
+
"@arizeai/openinference-core": "2.5.2",
|
|
32
|
+
"@arizeai/openinference-semantic-conventions": "2.7.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@opentelemetry/exporter-trace-otlp-proto": "^0.50.0",
|
package/src/instrumentation.ts
CHANGED
|
@@ -75,6 +75,7 @@ export const HOST_SUFFIX_TO_PROVIDER: Record<string, LLMProvider> = {
|
|
|
75
75
|
"api.perplexity.ai": LLMProvider.PERPLEXITY,
|
|
76
76
|
"api.together.ai": LLMProvider.TOGETHER,
|
|
77
77
|
"api.together.xyz": LLMProvider.TOGETHER,
|
|
78
|
+
"ollama.com": LLMProvider.OLLAMA,
|
|
78
79
|
};
|
|
79
80
|
|
|
80
81
|
/**
|
|
@@ -83,7 +84,9 @@ export const HOST_SUFFIX_TO_PROVIDER: Record<string, LLMProvider> = {
|
|
|
83
84
|
export function getProviderFromHost(host: string): LLMProvider | undefined {
|
|
84
85
|
const normalised = host.toLowerCase().trim();
|
|
85
86
|
for (const [suffix, provider] of Object.entries(HOST_SUFFIX_TO_PROVIDER)) {
|
|
86
|
-
|
|
87
|
+
// Anchor at a label boundary so e.g. "smollama.com" does not match the
|
|
88
|
+
// "ollama.com" suffix.
|
|
89
|
+
if (normalised === suffix || normalised.endsWith("." + suffix)) {
|
|
87
90
|
return provider;
|
|
88
91
|
}
|
|
89
92
|
}
|
|
@@ -129,23 +132,19 @@ function getLLMProvider(clientInstance: unknown): LLMProvider | undefined {
|
|
|
129
132
|
try {
|
|
130
133
|
// The clientInstance might be a sub-object (like Completions) that has a _client property
|
|
131
134
|
// pointing to the actual OpenAI/AzureOpenAI client
|
|
132
|
-
const instance = clientInstance as {
|
|
133
|
-
baseURL?: string | { host?: string };
|
|
134
|
-
_client?: {
|
|
135
|
-
baseURL?: string | { host?: string };
|
|
136
|
-
};
|
|
137
|
-
};
|
|
138
|
-
|
|
139
135
|
let host: string | undefined;
|
|
140
|
-
let baseURL:
|
|
136
|
+
let baseURL: unknown;
|
|
141
137
|
|
|
142
138
|
// First try to get baseURL from the instance itself
|
|
143
|
-
if (
|
|
144
|
-
baseURL =
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
+
}
|
|
149
148
|
}
|
|
150
149
|
|
|
151
150
|
if (typeof baseURL === "string") {
|
|
@@ -159,7 +158,7 @@ function getLLMProvider(clientInstance: unknown): LLMProvider | undefined {
|
|
|
159
158
|
}
|
|
160
159
|
} else if (baseURL && typeof baseURL === "object" && "host" in baseURL) {
|
|
161
160
|
// Direct host property
|
|
162
|
-
host = baseURL.host;
|
|
161
|
+
host = typeof baseURL.host === "string" ? baseURL.host : undefined;
|
|
163
162
|
}
|
|
164
163
|
|
|
165
164
|
if (host && typeof host === "string") {
|
|
@@ -332,7 +331,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
332
331
|
// handle the chunks and add them to the span
|
|
333
332
|
// First split the stream via tee
|
|
334
333
|
const [leftStream, rightStream] = result.tee();
|
|
335
|
-
consumeChatCompletionStreamChunks(rightStream, span);
|
|
334
|
+
void consumeChatCompletionStreamChunks(rightStream, span);
|
|
336
335
|
result = leftStream;
|
|
337
336
|
}
|
|
338
337
|
|
|
@@ -544,7 +543,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
544
543
|
const [leftStream, rightStream] = result.tee();
|
|
545
544
|
// take the right stream, consuming it and then recording the final chunk
|
|
546
545
|
// into the span
|
|
547
|
-
consumeResponseStreamEvents(rightStream).then(recordSpan);
|
|
546
|
+
void consumeResponseStreamEvents(rightStream).then(recordSpan);
|
|
548
547
|
// give the left stream back to the caller
|
|
549
548
|
result = leftStream;
|
|
550
549
|
}
|
|
@@ -1002,15 +1001,14 @@ function isAPIPromise<T>(promise: unknown): promise is APIPromise<T> {
|
|
|
1002
1001
|
* @param then - The thennable to invoke
|
|
1003
1002
|
* @returns The promise with the thennable invoked
|
|
1004
1003
|
*/
|
|
1005
|
-
function invokeMaybeAPIPromise<T>(
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
)
|
|
1010
|
-
|
|
1011
|
-
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);
|
|
1012
1010
|
} else if (promise instanceof Promise) {
|
|
1013
|
-
return promise.then(then)
|
|
1011
|
+
return promise.then(then);
|
|
1014
1012
|
} else {
|
|
1015
1013
|
// eslint-disable-next-line no-console
|
|
1016
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";
|