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 add Amazon Bedrock support #1231
Conversation
PR Description updated to latest commit (4c77d6c)
|
PR Review
✨ Review tool usage guide:Overview: The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
See the review usage page for a comprehensive guide on using this tool. |
PR Code Suggestions
✨ Improve tool usage guide:Overview:
See the improve usage page for a comprehensive guide on using this tool. |
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #1231 +/- ##
===========================================
- Coverage 70.22% 33.64% -36.59%
===========================================
Files 316 320 +4
Lines 18860 19070 +210
===========================================
- Hits 13245 6416 -6829
- Misses 5615 12654 +7039 ☔ View full report in Codecov by Sentry. |
fix naming
metagpt/configs/llm_config.py
Outdated
@@ -32,6 +32,7 @@ class LLMType(Enum): | |||
MISTRAL = "mistral" | |||
YI = "yi" # lingyiwanwu | |||
OPENROUTER = "openrouter" | |||
AMAZON_BEDROCK = "amazon_bedrock" |
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.
If BEDROCK is distinguishable, no need to use AMAZON_BEDROCK, but you can comment it with "amazon bedrock"
content = message["content"] | ||
prompt += GENERAL_TEMPLATE.format(role=role, content=content) | ||
|
||
if role != "assistant": |
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.
role will have a NameError if messages is empty
metagpt/provider/bedrock/utils.py
Outdated
|
||
|
||
def get_max_tokens(model_id) -> int: | ||
return (NOT_SUUPORT_STREAM_MODELS | SUPPORT_STREAM_MODELS)[model_id] |
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.
.get(model_id, default_val) to avoid KeyError
metagpt/provider/bedrock_api.py
Outdated
messages, self._const_kwargs) | ||
response_body = self.invoke_model(request_body) | ||
completions = self.__provider.get_choice_text(response_body) | ||
return completions |
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.
completion return response structure not text from get_choice_text. see acompletion_text in BaseLLM
metagpt/provider/bedrock_api.py
Outdated
response = self.__client.invoke_model_with_response_stream( | ||
modelId=self.config.model, body=request_body) | ||
usage = self._get_usage(response) | ||
self._update_costs(usage) |
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.
Here doesn't have the price of each 1k tokens for model, so _update_costs
will fail. Don't you notice this in your log?
metagpt/provider/bedrock_api.py
Outdated
if self.config.model in NOT_SUUPORT_STREAM_MODELS: | ||
logger.warning( | ||
f"model {self.config.model} doesn't support streaming output!") | ||
return self.completion(messages) |
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.
notice here, completion return object not str, see comment like before.
lgtm |
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.
LGTM
User description
Features
#1174
config
test result
completion test