mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-29 15:59:42 +02:00
fixbug: config.yaml
feat: +tests
This commit is contained in:
parent
25de7f9a74
commit
6a16900953
8 changed files with 78 additions and 28 deletions
|
|
@ -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():
|
||||
@pytest.mark.asyncio
|
||||
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"])
|
||||
|
|
|
|||
|
|
@ -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"])
|
||||
|
|
|
|||
30
tests/metagpt/tools/test_hello.py
Normal file
30
tests/metagpt/tools/test_hello.py
Normal file
|
|
@ -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
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
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"])
|
||||
Loading…
Add table
Add a link
Reference in a new issue