-
Notifications
You must be signed in to change notification settings - Fork 585
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 support #483
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import os | ||
|
||
import boto3 | ||
import litellm | ||
import openai | ||
from litellm import acompletion | ||
|
@@ -24,6 +25,7 @@ def __init__(self): | |
Raises a ValueError if the OpenAI key is missing. | ||
""" | ||
self.azure = False | ||
self.aws_bedrock_client = None | ||
|
||
if get_settings().get("OPENAI.KEY", None): | ||
openai.api_key = get_settings().openai.key | ||
|
@@ -60,6 +62,12 @@ def __init__(self): | |
litellm.vertex_location = get_settings().get( | ||
"VERTEXAI.VERTEX_LOCATION", None | ||
) | ||
if get_settings().get("AWS.BEDROCK_REGION", None): | ||
litellm.AmazonAnthropicConfig.max_tokens_to_sample = 2000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this because |
||
self.aws_bedrock_client = boto3.client( | ||
service_name="bedrock-runtime", | ||
region_name=get_settings().aws.bedrock_region, | ||
) | ||
|
||
@property | ||
def deployment_id(self): | ||
|
@@ -100,13 +108,16 @@ async def chat_completion(self, model: str, system: str, user: str, temperature: | |
if self.azure: | ||
model = 'azure/' + model | ||
messages = [{"role": "system", "content": system}, {"role": "user", "content": user}] | ||
response = await acompletion( | ||
model=model, | ||
deployment_id=deployment_id, | ||
messages=messages, | ||
temperature=temperature, | ||
force_timeout=get_settings().config.ai_timeout | ||
) | ||
kwargs = { | ||
"model": model, | ||
"deployment_id": deployment_id, | ||
"messages": messages, | ||
"temperature": temperature, | ||
"force_timeout": get_settings().config.ai_timeout, | ||
} | ||
if self.aws_bedrock_client: | ||
kwargs["aws_bedrock_client"] = self.aws_bedrock_client | ||
response = await acompletion(**kwargs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding
|
||
except (APIError, Timeout, TryAgain) as e: | ||
get_logger().error("Error during OpenAI inference: ", e) | ||
raise | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ GitPython==3.1.32 | |
PyYAML==6.0 | ||
starlette-context==0.3.6 | ||
litellm==0.12.5 | ||
boto3==1.28.25 | ||
boto3==1.33.1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. litellm requires |
||
google-cloud-storage==2.10.0 | ||
ujson==5.8.0 | ||
azure-devops==7.1.0b3 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add support only for Claude for now because it's difficult to tune more parameters like
max_tokens_to_sample
specific for each model.