Skip to content

Commit

Permalink
feat: Added support for Bedrock invoke model user request (#2721)
Browse files Browse the repository at this point in the history
Co-authored-by: James Sumners <jsumners@newrelic.com>
  • Loading branch information
cmcadams-newrelic and jsumners-nr authored Nov 12, 2024
1 parent a158bde commit a901a24
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/llm-events/aws-bedrock/bedrock-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ class BedrockCommand {
result = this.#body.prompt
} else if (this.isClaude3() === true) {
result = this.#body?.messages?.reduce((acc, curr) => {
acc += curr?.content ?? ''
if (typeof curr?.content === 'string') {
acc += curr?.content
} else if (Object.keys(curr?.content).length) {
acc += curr?.content.text ?? ''
}
return acc
}, '')
}
Expand Down
43 changes: 43 additions & 0 deletions test/unit/llm-events/aws-bedrock/bedrock-command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ const claude = {
}
}

const claude35 = {
modelId: 'anthropic.claude-3-5-sonnet-20240620-v1:0',
body: {
messages: [{ role: 'user', content: { type: 'text', text: 'who are you' } }]
}
}

const claude3 = {
modelId: 'anthropic.claude-3-haiku-20240307-v1:0',
body: {
Expand Down Expand Up @@ -182,6 +189,42 @@ test('claude3 complete command works', async (t) => {
assert.equal(cmd.temperature, payload.body.temperature)
})

test('claude35 minimal command works with claude 3 api', async (t) => {
t.nr.updatePayload(structuredClone(claude3))
const cmd = new BedrockCommand(t.nr.input)
assert.equal(cmd.isClaude3(), true)
assert.equal(cmd.maxTokens, undefined)
assert.equal(cmd.modelId, claude3.modelId)
assert.equal(cmd.modelType, 'completion')
assert.equal(cmd.prompt, claude3.body.messages[0].content)
assert.equal(cmd.temperature, undefined)
})

test('claude35 minimal command works', async (t) => {
t.nr.updatePayload(structuredClone(claude35))
const cmd = new BedrockCommand(t.nr.input)
assert.equal(cmd.isClaude3(), true)
assert.equal(cmd.maxTokens, undefined)
assert.equal(cmd.modelId, claude35.modelId)
assert.equal(cmd.modelType, 'completion')
assert.equal(cmd.prompt, claude35.body.messages[0].content.text)
assert.equal(cmd.temperature, undefined)
})

test('claude35 complete command works', async (t) => {
const payload = structuredClone(claude35)
payload.body.max_tokens = 25
payload.body.temperature = 0.5
t.nr.updatePayload(payload)
const cmd = new BedrockCommand(t.nr.input)
assert.equal(cmd.isClaude3(), true)
assert.equal(cmd.maxTokens, 25)
assert.equal(cmd.modelId, payload.modelId)
assert.equal(cmd.modelType, 'completion')
assert.equal(cmd.prompt, payload.body.messages[0].content.text)
assert.equal(cmd.temperature, payload.body.temperature)
})

test('cohere minimal command works', async (t) => {
t.nr.updatePayload(structuredClone(cohere))
const cmd = new BedrockCommand(t.nr.input)
Expand Down

0 comments on commit a901a24

Please sign in to comment.