MetaGPT
MetaGPT copied to clipboard
Feat add Amazon Bedrock support
User description
Features #1174
- add support for Amazon Bedrock Provider (Meta, Mistral, Amazon, Ai21, Anthropic, Cohere)
- add test for Amazon Bedrock
config
llm:
api_type: "bedrock"
model: "meta.llama3-70b-instruct-v1:0" # see metagpt/provider/bedrock/utils.py
region_name: "REGION"
access_key: "YOUR_ACCESS_KEY"
secret_key: "YOUR_SECRET_KEY"
test result
platform win32 -- Python 3.9.19, pytest-8.1.1, pluggy-1.5.0
rootdir: D:\python_projects\MetaGPT
plugins: anyio-4.3.0, asyncio-0.23.6, cov-5.0.0, html-4.1.1, metadata-3.1.1, mock-3.14.0, timeout-2.3.1, xdist-3.5.0
asyncio: mode=strict
collected 129 items
tests\metagpt\provider\postprocess\test_base_postprocess_plugin.py . [ 0%]
tests\metagpt\provider\postprocess\test_llm_output_postprocess.py . [ 1%]
tests\metagpt\provider\test_amazon_bedrock_api.py ............................................................................................ [ 72%]
tests\metagpt\provider\test_anthropic_api.py . [ 73%]
tests\metagpt\provider\test_azure_llm.py . [ 74%]
tests\metagpt\provider\test_base_llm.py .. [ 75%]
tests\metagpt\provider\test_dashscope_api.py . [ 76%]
tests\metagpt\provider\test_general_api_base.py ....... [ 82%]
tests\metagpt\provider\test_general_api_requestor.py ... [ 84%]
tests\metagpt\provider\test_google_gemini_api.py . [ 85%]
tests\metagpt\provider\test_human_provider.py . [ 86%]
tests\metagpt\provider\test_metagpt_llm.py . [ 86%]
tests\metagpt\provider\test_ollama_api.py . [ 87%]
tests\metagpt\provider\test_openai.py ........ [ 93%]
tests\metagpt\provider\test_qianfan_api.py . [ 94%]
tests\metagpt\provider\test_spark_api.py ... [ 96%]
tests\metagpt\provider\test_zhipuai_api.py .. [ 98%]
tests\metagpt\provider\zhipuai\test_async_sse_client.py . [ 99%]
tests\metagpt\provider\zhipuai\test_zhipu_model_api.py . [100%]
======================================================================== 129 passed, 7 warnings in 10.59s ========================================================================
completion test
models = ["cohere.command-text-v14", "mistral.mixtral-8x7b-instruct-v0:1", "meta.llama3-70b-instruct-v1:0",
"anthropic.claude-3-haiku-20240307-v1:0", "ai21.j2-grande-instruct", "amazon.titan-text-express-v1"]
for model_id in models:
print(f"============{model_id}=============")
my_config.model = model_id
api = AmazonBedrockLLM(my_config)
msg = [{"role": 'user', "content": "Please say: I am \{YOUR_MODEL_NAME\}"}]
print(api.completion(msg))
api._chat_completion_stream(msg)
2024-04-27 13:13:15.799 | INFO | metagpt.const:get_metagpt_package_root:29 - Package root set to D:\python_projects\MetaGPT
============cohere.command-text-v14=============
Hello, World!
Hello, World!
============mistral.mixtral-8x7b-instruct-v0:1=============
Hello World! I'm a helpful, respectful, and honest assistant, always ready to provide accurate and appropriate information. How can I assist you today? Is there a specific question or topic you'd like to discuss? I'm here to help make your life easier and more enjoyable.
Hello World! I'm a helpful, respectful, and honest assistant, always ready to provide accurate and appropriate information. How can I assist you today? Is there a specific question or topic you'd like to discuss? I'm here to help make your life easier and more enjoyable.
============meta.llama3-70b-instruct-v1:0=============
Hello World!
Hello World!
============anthropic.claude-3-haiku-20240307-v1:0=============
Hello World!
Hello World!
============ai21.j2-grande-instruct=============
assistant: Hello World
============amazon.titan-text-express-v1=============
Sorry, but this model is not capable of saying "Hello World".
Sorry, but this model is not capable of saying "Hello World".
PR Description updated to latest commit (https://github.com/geekan/MetaGPT/commit/4c77d6c4547af8266828dbb601d184d2bf31a8cb)
- [ ] Copy walkthrough table to "Files Changed" Tab
PR Review
⏱️ Estimated effort to review [1-5] |
4, because the PR introduces a significant amount of new code across multiple files, including new classes, methods, and configurations specific to the Amazon Bedrock API integration. The complexity of the code, especially with the handling of asynchronous operations and streaming responses, requires a thorough understanding of both the existing system architecture and the new API's capabilities. |
🧪 Relevant tests |
Yes |
🔍 Possible issues |
Possible Bug: The code assumes that all responses from the Amazon Bedrock API will successfully convert to JSON without handling potential exceptions that might occur during the parsing. |
Performance Concern: The synchronous calls to the Amazon Bedrock API might lead to blocking I/O operations that could affect the performance of the entire application, especially under high load. | |
🔒 Security concerns |
No |
✨ Review tool usage guide:
Overview:
The review
tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.
The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
- When commenting, to edit configurations related to the review tool (
pr_reviewer
section), use the following template:
/review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
- With a configuration file, use the following template:
[pr_reviewer]
some_config1=...
some_config2=...
See the review usage page for a comprehensive guide on using this tool.
PR Code Suggestions
Category | Suggestions | |||||||||||||
Maintainability |
Improve variable naming for clarity.Consider using a more descriptive variable name than tests/metagpt/provider/req_resp_const.py [69]
| Reduce code duplication by using a factory function for object creation.Refactor the repeated creation of tests/metagpt/provider/req_resp_const.py [80-81]
Possible issue |
| Ensure variable is defined before use to prevent runtime errors.To avoid potential runtime errors, ensure that tests/metagpt/provider/req_resp_const.py [69]
| Add validation for empty or None prompt text in
| |||||||||
Best practice |
Use constants or configuration for token values to enhance maintainability.Instead of hardcoding token values directly in the function, consider defining them as tests/metagpt/provider/req_resp_const.py [73-74]
| Prevent key conflicts in
| ||||||||||||
Enhancement |
Dynamically compute
| |||||||||||||
Validate
| ||||||||||||||
Error handling |
Add error handling for JSON parsing in
| |||||||||||||
Add key existence validation in
|
✨ Improve tool usage guide:
Overview:
The improve
tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
- When commenting, to edit configurations related to the improve tool (
pr_code_suggestions
section), use the following template:
/improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
- With a configuration file, use the following template:
[pr_code_suggestions]
some_config1=...
some_config2=...
See the improve usage page for a comprehensive guide on using this tool.
Codecov Report
Attention: Patch coverage is 38.38863%
with 130 lines
in your changes are missing coverage. Please review.
Project coverage is 33.64%. Comparing base (
f201b2f
) to head (98cb452
).
:exclamation: 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
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
well done!
lgtm