Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

feat: merge fixbug/rfc135_merge_geekan_cli_etc_1445

莘权 马a9479843f657
diff --git a/config/config.yaml b/config/config.yaml
index 87637f0b5..496167e13 100644
--- a/config/config.yaml
+++ b/config/config.yaml
@@ -11,7 +11,7 @@ OPENAI_API_BASE: "https://api.openai.com/v1"
OPENAI_API_MODEL: "gpt-4-1106-preview"
MAX_TOKENS: 4096
RPM: 10
-#LLM_TYPE: OpenAI # Except for these three major models – OpenAI, MetaGPT LLM, and Azure – other large models can be distinguished based on the validity of the key.
+LLM_TYPE: OpenAI # Except for these three major models – OpenAI, MetaGPT LLM, and Azure – other large models can be distinguished based on the validity of the key.
#### if Spark
#SPARK_APPID : "YOUR_APPID"
diff --git a/metagpt/learn/text_to_image.py b/metagpt/learn/text_to_image.py
index 23c2bddad..24669312c 100644
--- a/metagpt/learn/text_to_image.py
+++ b/metagpt/learn/text_to_image.py
@@ -6,7 +6,6 @@
@File : text_to_image.py
@Desc : Text-to-Image skill, which provides text-to-image functionality.
"""
-import openai.error
from metagpt.config import CONFIG
from metagpt.const import BASE64_FORMAT
@@ -30,10 +29,10 @@ async def text_to_image(text, size_type: str = "512x512", openai_api_key="", mod
elif CONFIG.OPENAI_API_KEY or openai_api_key:
base64_data = await oas3_openai_text_to_image(text, size_type, openai_api_key)
else:
- raise openai.error.InvalidRequestError("缺少必要的参数")
+ raise ValueError("Missing necessary parameters.")
s3 = S3()
- url = await s3.cache(data=base64_data, file_ext=".png", format=BASE64_FORMAT)
+ url = await s3.cache(data=base64_data, file_ext=".png", format=BASE64_FORMAT) if s3.is_valid else ""
if url:
return f"![{text}]({url})"
return image_declaration + base64_data if base64_data else ""
diff --git a/metagpt/learn/text_to_speech.py b/metagpt/learn/text_to_speech.py
index 7c085c02f..972515599 100644
--- a/metagpt/learn/text_to_speech.py
+++ b/metagpt/learn/text_to_speech.py
@@ -49,7 +49,7 @@ async def text_to_speech(
audio_declaration = "data:audio/wav;base64,"
base64_data = await oas3_azsure_tts(text, lang, voice, style, role, subscription_key, region)
s3 = S3()
- url = await s3.cache(data=base64_data, file_ext=".wav", format=BASE64_FORMAT)
+ url = await s3.cache(data=base64_data, file_ext=".wav", format=BASE64_FORMAT) if s3.is_valid else ""
if url:
return f"[{text}]({url})"
return audio_declaration + base64_data if base64_data else base64_data
@@ -61,7 +61,7 @@ async def text_to_speech(
text=text, app_id=iflytek_app_id, api_key=iflytek_api_key, api_secret=iflytek_api_secret
)
s3 = S3()
- url = await s3.cache(data=base64_data, file_ext=".mp3", format=BASE64_FORMAT)
+ url = await s3.cache(data=base64_data, file_ext=".mp3", format=BASE64_FORMAT) if s3.is_valid else ""
if url:
return f"[{text}]({url})"
return audio_declaration + base64_data if base64_data else base64_data
diff --git a/metagpt/utils/s3.py b/metagpt/utils/s3.py
index 4c3533d5b..9accfcade 100644
--- a/metagpt/utils/s3.py
+++ b/metagpt/utils/s3.py
@@ -152,3 +152,19 @@ class S3:
logger.exception(f"{e}, stack:{traceback.format_exc()}")
pathname.unlink(missing_ok=True)
return None
+
+ @property
+ def is_valid(self):
+ is_invalid = (
+ not CONFIG.S3_ACCESS_KEY
+ or CONFIG.S3_ACCESS_KEY == "YOUR_S3_ACCESS_KEY"
+ or not CONFIG.S3_SECRET_KEY
+ or CONFIG.S3_SECRET_KEY == "YOUR_S3_SECRET_KEY"
+ or not CONFIG.S3_ENDPOINT_URL
+ or CONFIG.S3_ENDPOINT_URL == "YOUR_S3_ENDPOINT_URL"
+ or not CONFIG.S3_BUCKET
+ or CONFIG.S3_BUCKET == "YOUR_S3_BUCKET"
+ )
+ if is_invalid:
+ logger.info("S3 is invalid")
+ return not is_invalid
diff --git a/requirements.txt b/requirements.txt
index cf7d8d519..d2a4e5bb4 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -56,3 +56,4 @@ zhipuai==1.0.7
socksio~=1.0.0
gitignore-parser==0.1.9
connexion[swagger-ui]
+websockets~=12.0
\ No newline at end of file
diff --git a/tests/conftest.py b/tests/conftest.py
index 375b9ff7f..47e05e20e 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -13,7 +13,7 @@ from unittest.mock import Mock
import pytest
-from metagpt.config import CONFIG
+from metagpt.config import CONFIG, Config
from metagpt.const import DEFAULT_WORKSPACE_ROOT
from metagpt.logs import logger
from metagpt.provider.openai_api import OpenAIGPTAPI as GPTAPI
diff --git a/tests/metagpt/learn/test_text_to_image.py b/tests/metagpt/learn/test_text_to_image.py
index 982a39b13..a6cbc45bf 100644
--- a/tests/metagpt/learn/test_text_to_image.py
+++ b/tests/metagpt/learn/test_text_to_image.py
@@ -6,15 +6,17 @@
@File : test_text_to_image.py
@Desc : Unit tests.
"""
-import asyncio
+
import base64
+import pytest
from pydantic import BaseModel
from metagpt.learn.text_to_image import text_to_image
-async def mock_text_to_image():
+async def test():
class Input(BaseModel):
input: str
size_type: str
@@ -36,11 +38,5 @@ async def mock_text_to_image():
assert base64.b64decode(data, validate=True)
-def test_suite():
- loop = asyncio.get_event_loop()
- task = loop.create_task(mock_text_to_image())
- loop.run_until_complete(task)
-
-
if __name__ == "__main__":
- test_suite()
+ pytest.main([__file__, "-s"])
diff --git a/tests/metagpt/test_environment.py b/tests/metagpt/test_environment.py
index 933d74b97..fd731cf9e 100644
--- a/tests/metagpt/test_environment.py
+++ b/tests/metagpt/test_environment.py
@@ -11,6 +11,7 @@
import pytest
from metagpt.actions import UserRequirement
+from metagpt.config import CONFIG
from metagpt.environment import Environment
from metagpt.logs import logger
from metagpt.roles import Architect, ProductManager, Role
@@ -41,6 +42,10 @@ def test_get_roles(env: Environment):
@pytest.mark.asyncio
async def test_publish_and_process_message(env: Environment):
+ if CONFIG.git_repo:
+ CONFIG.git_repo.delete_repository()
+ CONFIG.git_repo = None
+
product_manager = ProductManager(name="Alice", profile="Product Manager", goal="做AI Native产品", constraints="资源有限")
architect = Architect(
name="Bob", profile="Architect", goal="设计一个可用、高效、较低成本的系统,包括数据结构与接口", constraints="资源有限,需要节省成本"