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

Add Amazon Bedrock Anthropic Claude v1 and v2 assistants #173

Closed
wants to merge 1 commit into from

Conversation

094459
Copy link

@094459 094459 commented Nov 8, 2023

Additional assistant if you want to use Claudev1 or v2 hosted via Amazon Bedrock.

You need to set AWS environment variables for your AWS credentials (i.e export AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)

Code is currently region specific to where Amazon Bedrock is hosted.

@094459
Copy link
Author

094459 commented Nov 8, 2023

This PR is for #171

Copy link
Member

@pmeier pmeier left a comment

Choose a reason for hiding this comment

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

@094459 it seems there was a misunderstanding. To quote myself from #171 (comment)

we won't accept any components that require additional infrastructure to run.

AWS Bedrock certainly fits that bill. We had some initial ideas to provide a ragna.contrib namespace, but scrapped that idea again in favor of community maintained third-party packages.

Seeing that commit is authored by @ricsue-aws a potential solution would be to create a ragna-aws package that holds configuration for Bedrock assistants. Plus, it could also include something like the S3 document that we have in https://github.com/Quansight/ragna/blob/main/examples/s3_documents/ragna_s3_document.py.

That being said, regardless of where the implementation is ultimately put, it needs to somehow find its way into a configuration file. @094459 could you explain your reasoning why this should be part of the Ragna core library rather than just a local extension that you wrote?

@@ -0,0 +1,79 @@
from typing import cast
import boto3
Copy link
Member

Choose a reason for hiding this comment

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

Ignore this if you go for a third party package that can hard-depend on boto3. Otherwise, this should be a requirement on the class below and imported locally to avoid introducing a hard runtime dependency.



class AmazonBedrockAssistant(ApiAssistant):
_API_KEY_ENV_VAR = "AWS_ACCESS_KEY_ID"
Copy link
Member

Choose a reason for hiding this comment

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

Although we set it here, it is never used anywhere. That hints to the fact that ApiAssistant is probably not the right abstraction and you are better off subclassing from ragna.core.Assistant directly.

Comment on lines +22 to +30
def _instructize_prompt(self, prompt: str, sources: list[Source]) -> str:
instruction = (
"\n\nHuman: "
"Use the following pieces of context to answer the question at the end. "
"If you don't know the answer, just say so. Don't try to make up an answer.\n"
)

instruction += "\n\n".join(source.content for source in sources)
return f"{instruction}\n\nQuestion: {prompt}\n\nAssistant:"
Copy link
Member

Choose a reason for hiding this comment

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

This prompt is special for Anthropic, although it should also be working for other assistants.



class AmazonBedRockClaude(AmazonBedrockAssistant):
"""[Amazon Bedrock Claud v2](https://eu-central-1.console.aws.amazon.com/bedrock/home?region=eu-central-1#/providers?model=anthropic.claude-v2)
Copy link
Member

Choose a reason for hiding this comment

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

That is an internal link that requires an AWS account.

@094459
Copy link
Author

094459 commented Nov 8, 2023

Hi there. I have no strong opinions where this goes, and only wanted to contribute if you found it useful. I guess I was confused by the term 'additional infrastructure' given that Bedrock acts kind of like Anthropic, OpenAI, so apologies for the misunderstanding. I put this together for folks who might want to try this out but be using Claude via Bedrock rather than directly via Anthropic. Hope this makes sense.

@094459
Copy link
Author

094459 commented Nov 8, 2023

I'm not sure what a local extension means but if you mean a local fork then if that is the recommendation of the project then I have no issues with that.

@pmeier
Copy link
Member

pmeier commented Nov 8, 2023

apologies for the misunderstanding.

No worries here.

I put this together for folks who might want to try this out but be using Claude via Bedrock rather than directly via Anthropic. Hope this makes sense.

Yeah, and that is fine. Like I stated above, maybe we can have a ragna-aws package in the future that contains just this functionality. However, since we won't accept the PR as is in the near future, I'm going to close this. If our stance on this changes, we can always re-open.

I'm not sure what a local extension means but if you mean a local fork then if that is the recommendation of the project then I have no issues with that.

What I mean is that you can use the implementation you have with Ragna without it being part of the core package. Just throw your implementation in a ragna_bedrock.py module (make sure that is on the PYTHONPATH; you can test with python -c import ragna_bedrock.py) and add this to your configuration file

[core]
# ...
assistants = [
    # ...
    "ragna_bedrock.AmazonBedRockClaude",
    "ragna_bedrock.AmazonBedRockClaudev1",
]

If you start the UI now, you should be able to select and use them. If not, please open an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants