Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Added support for Bedrock invoke model user request #2721

Conversation

cmcadams-newrelic
Copy link
Contributor

@cmcadams-newrelic cmcadams-newrelic commented Nov 11, 2024

Description

This Pr will improve the support for using the invoke model with bedrock LLM. the Invoke API expects the body to be of type {[content: "user or assistant message"]}.

We will now check for the type of the input if the type is a string we will return the value as is. If the param is an object we will attempt to reduce the object to just the message value.

How to Test

run test suite.

Related Issues

https://new-relic.atlassian.net/browse/NR-326020

@CLAassistant
Copy link

CLAassistant commented Nov 11, 2024

CLA assistant check
All committers have signed the CLA.

@cmcadams-newrelic cmcadams-newrelic marked this pull request as ready for review November 11, 2024 16:02
Copy link
Contributor

@jsumners-nr jsumners-nr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see any tests for this change.

@@ -77,15 +77,19 @@ class BedrockCommand {
} else if (this.isCohereEmbed() === true) {
result = this.#body.texts.join(' ')
} else if (
this.isClaude() === true ||
(this.isClaude() === true && this.isClaude3() === false) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this condition change necessary? The isClaude method does not match for v3, or it shouldn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review, and yes, you are correct! this.isClaude3() === false is unneeded at this time, and is pushing the solution into redundancy. Im happy to remove this change from the PR.


For context:

I want to add this change because I think it improves readability by explicitly calling out this will not match claude 3.x.

Currently, Claude is the only llm that we treat as a separate llm based on its version. I get that is because of the API. But thinking about the future would isClaude support anthropic.claude-v4 or would we need to continue the pattern of creating a new possible llm isClaude4?

Furthermore, I think this will help developers of all exp. levels to quickly consume the code and be able to contribute.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it depends on how they provide these things via the AWS API. We initially had one "Claude". So we implemented an isClaude method. Then they put out a "Claude v3" with a completely different identifier. So we added an isClaude3 method.

I think this discussion is valid, but probably one to have separate from this PR.

Copy link

codecov bot commented Nov 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.20%. Comparing base (7ae4af4) to head (28fff12).
Report is 77 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2721      +/-   ##
==========================================
- Coverage   97.22%   97.20%   -0.02%     
==========================================
  Files         290      294       +4     
  Lines       45882    46198     +316     
==========================================
+ Hits        44608    44908     +300     
- Misses       1274     1290      +16     
Flag Coverage Δ
integration-tests-cjs-18.x 74.27% <0.00%> (+0.18%) ⬆️
integration-tests-cjs-20.x 74.27% <0.00%> (+0.18%) ⬆️
integration-tests-cjs-22.x 74.32% <0.00%> (+0.19%) ⬆️
integration-tests-esm-18.x 49.88% <0.00%> (+0.17%) ⬆️
integration-tests-esm-20.x 49.89% <0.00%> (+0.17%) ⬆️
integration-tests-esm-22.x 49.91% <0.00%> (+0.17%) ⬆️
unit-tests-18.x 88.93% <100.00%> (+0.06%) ⬆️
unit-tests-20.x 88.93% <100.00%> (+0.06%) ⬆️
unit-tests-22.x 88.93% <100.00%> (+0.06%) ⬆️
versioned-tests-18.x 78.96% <60.00%> (-0.23%) ⬇️
versioned-tests-20.x 78.97% <60.00%> (-0.23%) ⬇️
versioned-tests-22.x 78.97% <60.00%> (-0.23%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cmcadams-newrelic
Copy link
Contributor Author

I do not see any tests for this change.

@jsumners-nr. Thank you for the review, I have included tests in my latest commit. the tests are to cover the changes in Claude 3.5 and the invoke model. In addition I have updated this PR's description calling out the scope of this change.

https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html#API_runtime_InvokeModel_RequestBody

@jsumners-nr jsumners-nr changed the title Nr-326020 support user input bedrock feat: Added support for Bedrock invoke model user request Nov 11, 2024
@cmcadams-newrelic cmcadams-newrelic force-pushed the NR-326020-support-user-input-bedrock branch from e5975b9 to 66dfcb3 Compare November 12, 2024 01:07
@jsumners-nr jsumners-nr merged commit a901a24 into newrelic:main Nov 12, 2024
26 of 27 checks passed
jsumners-nr added a commit to jsumners-nr/node-newrelic that referenced this pull request Nov 12, 2024
)

Co-authored-by: James Sumners <jsumners@newrelic.com>
@github-actions github-actions bot mentioned this pull request Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants