Skip to content

Commit

Permalink
Usage null check
Browse files Browse the repository at this point in the history
  • Loading branch information
Cerlancism committed Sep 28, 2024
1 parent cf3635e commit e94257d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/translator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ export class Translator
// process.stdout.write("\n")
this.services.onStreamEnd?.()
})
const prompt_tokens = usage.prompt_tokens
const completion_tokens = usage.completion_tokens
const prompt_tokens = usage?.prompt_tokens
const completion_tokens = usage?.completion_tokens
const output = new TranslationOutput(
getOutput(streamOutput),
prompt_tokens,
Expand Down
6 changes: 3 additions & 3 deletions src/translatorStructuredArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ export class TranslatorStructuredArray extends TranslatorStructuredBase

const translationOutput = new TranslationOutput(
linesOut,
output.usage.prompt_tokens,
output.usage.completion_tokens,
output.usage.total_tokens,
output.usage?.prompt_tokens,
output.usage?.completion_tokens,
output.usage?.total_tokens,
output.choices[0].message.refusal
)

Expand Down
6 changes: 3 additions & 3 deletions src/translatorStructuredObject.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export class TranslatorStructuredObject extends TranslatorStructuredBase

const translationOutput = new TranslationOutput(
linesOut,
output.usage.prompt_tokens,
output.usage.completion_tokens,
output.usage.total_tokens,
output.usage?.prompt_tokens,
output.usage?.completion_tokens,
output.usage?.total_tokens,
output.choices[0].message.refusal
)

Expand Down

0 comments on commit e94257d

Please sign in to comment.