Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Include usage object in stream response of chat completion response by default #690

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/providers/openai/chatComplete.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ANTHROPIC, OPEN_AI } from '../../globals';
import { Params } from '../../types/requestBody';
import {
ChatCompletionResponse,
ErrorResponse,
Expand Down Expand Up @@ -89,6 +90,12 @@ export const OpenAIChatCompleteConfig: ProviderConfig = {
},
stream_options: {
param: 'stream_options',
transform: (params: Params) => {
if (params.stream_options) return params.stream_options;
return {
include_usage: true,
};
},
},
service_tier: {
param: 'service_tier',
Expand Down
3 changes: 3 additions & 0 deletions src/types/requestBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ export interface Params {
top_p?: number;
n?: number;
stream?: boolean;
stream_options?: {
include_usage: boolean;
};
logprobs?: number;
echo?: boolean;
stop?: string | string[];
Expand Down
Loading