Skip to content

Commit

Permalink
chore: update branch with main
Browse files Browse the repository at this point in the history
  • Loading branch information
VisargD committed Mar 9, 2024
1 parent fc98459 commit 3439bcb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/providers/openai/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,23 @@ export const OpenAIChatCompleteResponseTransform: (response: OpenAIChatCompleteR
export const OpenAIChatCompleteJSONToStreamResponseTransform: (response: OpenAIChatCompleteResponse, provider: string) => Array<string> = (response, provider) => {
const streamChunkArray: Array<string> = [];
const { id, model, system_fingerprint, choices } = response;
const streamChunkTemplate = {

const { prompt_tokens, completion_tokens } = response.usage || {};

let total_tokens;
if (prompt_tokens && completion_tokens) total_tokens = prompt_tokens + completion_tokens;

const streamChunkTemplate: Record<string, any> = {
id,
object: "chat.completion.chunk",
created: Date.now(),
model: model || "",
system_fingerprint: system_fingerprint || null,
provider,
usage: {}
}

if (response.usage?.completion_tokens) {
streamChunkTemplate.usage = {
completion_tokens: response.usage?.completion_tokens
usage: {
...(completion_tokens && {completion_tokens}),
...(prompt_tokens && {prompt_tokens}),
...(total_tokens && {total_tokens})
}
}

Expand Down

0 comments on commit 3439bcb

Please sign in to comment.