Skip to content

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

fixbug: config.yaml

莘权 马6a1690095364
diff --git a/config/config.yaml b/config/config.yaml
index 711110f97..5025a4977 100644
--- a/config/config.yaml
+++ b/config/config.yaml
@@ -121,7 +121,6 @@ TIMEOUT: 60 # Timeout for llm invocation
# PROMPT_FORMAT: json #json or markdown
-<<<<<<< HEAD
### Agent configurations
# RAISE_NOT_CONFIG_ERROR: true # "true" if the LLM key is not configured, throw a NotConfiguredException, else "false".
# WORKSPACE_PATH_WITH_UID: false # "true" if using `{workspace}/{uid}` as the workspace path; "false" use `{workspace}`.
diff --git a/metagpt/tools/azure_tts.py b/metagpt/tools/azure_tts.py
index 8fdb10c13..d3e67c269 100644
--- a/metagpt/tools/azure_tts.py
+++ b/metagpt/tools/azure_tts.py
@@ -6,7 +6,6 @@
@File : azure_tts.py
@Modified by: mashenquan, 2023/8/17. Azure TTS OAS3 api, which provides text-to-speech functionality
"""
-import asyncio
import base64
from pathlib import Path
from uuid import uuid4
@@ -14,7 +13,7 @@ from uuid import uuid4
import aiofiles
from azure.cognitiveservices.speech import AudioConfig, SpeechConfig, SpeechSynthesizer
-from metagpt.config import CONFIG, Config
+from metagpt.config import CONFIG
from metagpt.logs import logger
@@ -103,11 +102,3 @@ async def oas3_azsure_tts(text, lang="", voice="", style="", role="", subscripti
return ""
return base64_string
-
-
-if __name__ == "__main__":
- Config()
- loop = asyncio.new_event_loop()
- v = loop.create_task(oas3_azsure_tts("测试,test"))
- loop.run_until_complete(v)
- print(v)
diff --git a/metagpt/tools/hello.py b/metagpt/tools/hello.py
index 8a21e1b4e..52d2d11c1 100644
--- a/metagpt/tools/hello.py
+++ b/metagpt/tools/hello.py
@@ -12,6 +12,7 @@
-H 'Content-Type: application/json' \
-d '{}'
"""
+from pathlib import Path
import connexion
@@ -22,6 +23,7 @@ async def post_greeting(name: str) -> str:
if __name__ == "__main__":
- app = connexion.AioHttpApp(__name__, specification_dir="../../.well-known/")
+ specification_dir = Path(__file__).parent.parent.parent / ".well-known"
+ app = connexion.AsyncApp(__name__, specification_dir=str(specification_dir))
app.add_api("openapi.yaml", arguments={"title": "Hello World Example"})
app.run(port=8080)
diff --git a/requirements-test.txt b/requirements-test.txt
new file mode 100644
index 000000000..39ba608b7
--- /dev/null
+++ b/requirements-test.txt
@@ -0,0 +1,5 @@
+# For unit test
+-r requirements.txt
+
+connexion[uvicorn]~=3.0.5
+azure-cognitiveservices-speech~=1.31.0
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 5cb01ab99..f2566fb15 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -40,12 +40,12 @@ typing_extensions==4.7.0
libcst==1.0.1
qdrant-client==1.4.0
pytest-mock==3.11.1
-# open-interpreter==0.1.7; python_version>"3.9"
+# open-interpreter==0.1.7; python_version>"3.9" # Conflict with openai 1.x
ta==0.10.2
semantic-kernel==0.4.0.dev0
wrapt==1.15.0
#aiohttp_jinja2
-#azure-cognitiveservices-speech~=1.31.0
+# azure-cognitiveservices-speech~=1.31.0 # Used by metagpt/tools/azure_tts.py
#aioboto3~=11.3.0
#redis==4.3.5
websocket-client==1.6.2
@@ -54,8 +54,8 @@ gitpython==3.1.40
zhipuai==1.0.7
socksio~=1.0.0
gitignore-parser==0.1.9
-# connexion[swagger-ui]
+# connexion[uvicorn]~=3.0.5 # Used by metagpt/tools/hello.py
websockets~=12.0
networkx~=3.2.1
google-generativeai==0.3.1
-playwright==1.40.0
\ No newline at end of file
+playwright==1.40.0
diff --git a/tests/metagpt/tools/test_azure_tts.py b/tests/metagpt/tools/test_azure_tts.py
index b7f94a19c..38fef557e 100644
--- a/tests/metagpt/tools/test_azure_tts.py
+++ b/tests/metagpt/tools/test_azure_tts.py
@@ -7,13 +7,20 @@
@Modified By: mashenquan, 2023-8-9, add more text formatting options
@Modified By: mashenquan, 2023-8-17, move to `tools` folder.
"""
-import asyncio
+
+import pytest
+from azure.cognitiveservices.speech import ResultReason
from metagpt.config import CONFIG
from metagpt.tools.azure_tts import AzureTTS
-def test_azure_tts():
+async def test_azure_tts():
+ # Prerequisites
+ assert CONFIG.AZURE_TTS_SUBSCRIPTION_KEY and CONFIG.AZURE_TTS_SUBSCRIPTION_KEY != "YOUR_API_KEY"
+ assert CONFIG.AZURE_TTS_REGION
+
azure_tts = AzureTTS(subscription_key="", region="")
text = """
女儿看见父亲走了进来,问道:
@@ -25,20 +32,19 @@ def test_azure_tts():
“Writing a binary file in Python is similar to writing a regular text file, but you'll work with bytes instead of strings.”
</mstts:express-as>
"""
- path = CONFIG.workspace / "tts"
+ path = CONFIG.workspace_path / "tts"
path.mkdir(exist_ok=True, parents=True)
filename = path / "girl.wav"
- loop = asyncio.new_event_loop()
- v = loop.create_task(
- azure_tts.synthesize_speech(lang="zh-CN", voice="zh-CN-XiaomoNeural", text=text, output_file=str(filename))
+ filename.unlink(missing_ok=True)
+ result = await azure_tts.synthesize_speech(
+ lang="zh-CN", voice="zh-CN-XiaomoNeural", text=text, output_file=str(filename)
)
- result = loop.run_until_complete(v)
-
print(result)
-
- # 运行需要先配置 SUBSCRIPTION_KEY
- # TODO: 这里如果要检验,还要额外加上对应的asr,才能确保前后生成是接近一致的,但现在还没有
+ assert result
+ assert result.audio_data
+ assert result.reason == ResultReason.SynthesizingAudioCompleted
+ assert filename.exists()
if __name__ == "__main__":
- test_azure_tts()
+ pytest.main([__file__, "-s"])
diff --git a/tests/metagpt/tools/test_code_interpreter.py b/tests/metagpt/tools/test_code_interpreter.py
index 03d4ce8df..b8380967c 100644
--- a/tests/metagpt/tools/test_code_interpreter.py
+++ b/tests/metagpt/tools/test_code_interpreter.py
@@ -1,3 +1,13 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@Time :
+@Author :
+@File : test_code_interpreter.py
+@Warning : open-interpreter 0.1.17 requires openai<0.29.0,>=0.28.0, but you have openai 1.6.0 which is incompatible.
+ open-interpreter 0.1.17 requires tiktoken<0.5.0,>=0.4.0, but you have tiktoken 0.5.2 which is incompatible.
+"""
+
from pathlib import Path
import pandas as pd
@@ -23,6 +33,9 @@ class CreateStockIndicators(Action):
@pytest.mark.asyncio
async def test_actions():
+ # Prerequisites
+ # Conflict with openai 1.x
+
# 计算指标
indicators = ["Simple Moving Average", "BollingerBands"]
stocker = CreateStockIndicators()
@@ -41,3 +54,7 @@ async def test_actions():
f"使用seaborn对{df_path}中与股票布林带有关的数据列的Date, Close, SMA, BB_upper(布林带上界), BB_lower(布林带下界)进行可视化, 可视化图片保存在{figure_path}中。不需要任何指标计算,把Date列转换为日期类型。要求图片优美,BB_upper, BB_lower之间使用合适的颜色填充。"
)
assert Path(figure_path).is_file()
+
+
+if __name__ == "__main__":
+ pytest.main([__file__, "-s"])
diff --git a/tests/metagpt/tools/test_hello.py b/tests/metagpt/tools/test_hello.py
new file mode 100644
index 000000000..037dcd1b7
--- /dev/null
+++ b/tests/metagpt/tools/test_hello.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@Time : 2023/12/26
+@Author : mashenquan
+@File : test_hello.py
+"""
+import subprocess
+from pathlib import Path
+
+import pytest
+import requests
+
+
+async def test_hello():
+ script_pathname = Path(__file__).resolve()
+ process = subprocess.Popen(["python", str(script_pathname)])
+
+ url = "http://localhost:8080/openapi/greeting/dave"
+ headers = {"accept": "text/plain", "Content-Type": "application/json"}
+ data = {}
+ response = requests.post(url, headers=headers, json=data)
+ assert response.text == "Hello dave\n"
+
+ process.terminate()
+
+
+if __name__ == "__main__":
+ pytest.main([__file__, "-s"])