Skip to content

Commit 755cd47

Browse files
committed
fix: APIPromise import
1 parent a05c4dd commit 755cd47

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/instrumentation-openai/src/instrumentation.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ import type {
3939
import type { Stream } from "openai/streaming";
4040
import { version } from "../package.json";
4141
import { encodingForModel, TiktokenModel, Tiktoken } from "js-tiktoken";
42-
import { APIPromise } from "openai/core";
42+
// Type definition for APIPromise - compatible with both OpenAI v4 and v5+
43+
// The actual import is handled at runtime via require() calls in the _wrapPromise method
44+
type APIPromiseType<T> = Promise<T> & {
45+
_thenUnwrap: <U>(onFulfilled: (value: T) => U) => APIPromiseType<U>;
46+
};
4347
import {
4448
wrapImageGeneration,
4549
wrapImageEdit,
@@ -415,13 +419,13 @@ export class OpenAIInstrumentation extends InstrumentationBase {
415419
span: Span;
416420
type: "chat";
417421
params: ChatCompletionCreateParamsStreaming;
418-
promise: APIPromise<Stream<ChatCompletionChunk>>;
422+
promise: APIPromiseType<Stream<ChatCompletionChunk>>;
419423
}
420424
| {
421425
span: Span;
422426
params: CompletionCreateParamsStreaming;
423427
type: "completion";
424-
promise: APIPromise<Stream<Completion>>;
428+
promise: APIPromiseType<Stream<Completion>>;
425429
}) {
426430
if (type === "chat") {
427431
const result: ChatCompletion = {
@@ -608,8 +612,8 @@ export class OpenAIInstrumentation extends InstrumentationBase {
608612
type: "chat" | "completion",
609613
version: "v3" | "v4",
610614
span: Span,
611-
promise: APIPromise<T>,
612-
): APIPromise<T> {
615+
promise: APIPromiseType<T>,
616+
): APIPromiseType<T> {
613617
return promise._thenUnwrap((result) => {
614618
if (version === "v3") {
615619
if (type === "chat") {

0 commit comments

Comments
 (0)