fixbug: config.yaml

feat: +tests
This commit is contained in:
莘权 马 2023-12-26 10:03:56 +08:00
parent 25de7f9a74
commit 6a16900953
8 changed files with 78 additions and 28 deletions

View file

@ -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}`.

View file

@ -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)

View file

@ -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)

5
requirements-test.txt Normal file
View file

@ -0,0 +1,5 @@
# For unit test
-r requirements.txt
connexion[uvicorn]~=3.0.5
azure-cognitiveservices-speech~=1.31.0

View file

@ -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
playwright==1.40.0

View file

@ -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"])

View file

@ -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"])

View 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"])