Skip to content

Commit

Permalink
chore: Changed token_count to only use tokenCountCallback (newrelic#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr authored Mar 11, 2024
1 parent d2af144 commit a9dbf26
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
6 changes: 2 additions & 4 deletions lib/llm/chat-completion-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ class LlmChatCompletionMessage extends LlmEvent {
this.#setId(index)
if (this.is_response === true) {
this.role = 'assistant'
this.token_count = this.bedrockResponse.outputTokenCount
if (this.token_count === undefined && typeof tokenCB === 'function') {
if (typeof tokenCB === 'function') {
this.token_count = tokenCB(this.bedrockCommand.modelId, content)
}
} else {
this.role = 'user'
this.content = recordContent === true ? this.bedrockCommand.prompt : undefined
this.token_count = this.bedrockResponse.inputTokenCount
if (this.token_count === undefined && typeof tokenCB === 'function') {
if (typeof tokenCB === 'function') {
this.token_count = tokenCB(this.bedrockCommand.modelId, this.bedrockCommand.prompt)
}
}
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/llm/chat-completion-message.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ tap.test('create creates a non-response instance', async (t) => {
t.equal(event.content, 'who are you')
t.equal(event.role, 'user')
t.match(event.id, /[\w-]{36}/)
t.equal(event.token_count, 8)
})

tap.test('create creates a titan response instance', async (t) => {
Expand All @@ -108,7 +107,6 @@ tap.test('create creates a titan response instance', async (t) => {
t.equal(event.content, 'a response')
t.equal(event.role, 'assistant')
t.match(event.id, /[\w-]{36}-0/)
t.equal(event.token_count, 4)
})

tap.test('create creates a cohere response instance', async (t) => {
Expand All @@ -124,7 +122,6 @@ tap.test('create creates a cohere response instance', async (t) => {
t.equal(event.content, 'a response')
t.equal(event.role, 'assistant')
t.match(event.id, /42-0/)
t.equal(event.token_count, 4)
})

tap.test('create creates a ai21 response instance when response.id is undefined', async (t) => {
Expand All @@ -140,7 +137,6 @@ tap.test('create creates a ai21 response instance when response.id is undefined'
t.equal(event.content, 'a response')
t.equal(event.role, 'assistant')
t.match(event.id, /[\w-]{36}-0/)
t.equal(event.token_count, 4)
})

tap.test(
Expand Down

0 comments on commit a9dbf26

Please sign in to comment.