8000 try to fix tests · traceloop/openllmetry-js@4a20088 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4a20088

Browse files
committed
try to fix tests
1 parent 7aba0ba commit 4a20088

File tree

1 file changed

+50
-16
lines changed

1 file changed

+50
-16
lines changed

packages/instrumentation-openai/src/instrumentation.ts

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -536,24 +536,58 @@ export class OpenAIInstrumentation extends InstrumentationBase {
536536
promise: APIPromise<T>,
537537
): APIPromise<T> {
538538
return new APIPromise<T>(
539-
new Promise((resolve, reject) => {
540539
promise
541-
._thenUnwrap((result) => {
542-
const data = version === "v3" ? (result as any).data : result;
543-
544-
this._endSpan({ type, span, result: data as any });
545-
return result;
546-
})
547-
.catch((error: Error) => {
548-
span.setStatus({
549-
code: SpanStatusCode.ERROR,
550-
message: error.message,
551-
});
552-
span.recordException(error);
553-
span.end();
554-
throw error;
540+
._thenUnwrap((data, props) => {
541+
if (version === "v3") {
542+
if (type === "chat") {
543+
this._addLogProbsEvent(
544+
span,
545+
(data as ChatCompletion).choices[0].logprobs,
546+
);
547+
this._endSpan({
548+
type,
549+
span,
550+
result: data as ChatCompletion,
551+
});
552+
} else {
553+
this._addLogProbsEvent(
554+
span,
555+
(data as Completion).choices[0].logprobs,
556+
);
557+
this._endSpan({
558+
type,
559+
span,
560+
result: data as Completion,
561+
});
562+
}
563+
} else {
564+
if (type === "chat") {
565+
this._addLogProbsEvent(
566+
span,
567+
(data as ChatCompletion).choices[0].logprobs,
568+
);
569+
this._endSpan({ type, span, result: data as ChatCompletion });
570+
} else {
571+
this._addLogProbsEvent(
572+
span,
573+
(data as Completion).choices[0].logprobs,
574+
);
575+
this._endSpan({ type, span, result: data as Completion });
576+
}
577+
}
578+
579+
return props;
580+
})
581+
.catch((error: Error) => {
582+
span.setStatus({
583+
code: SpanStatusCode.ERROR,
584+
message: error.message,
555585
});
556-
}),
586+
span.recordException(error);
587+
span.end();
588+
589+
throw error;
590+
})
557591
);
558592
}
559593

0 commit comments

Comments
 (0)
0