mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-05 13:52:38 +02:00
use config
This commit is contained in:
parent
e743ef1a12
commit
2e4ceb70b9
14 changed files with 64 additions and 76 deletions
|
|
@ -9,34 +9,43 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.config2 import config
|
||||
from metagpt.learn.text_to_speech import text_to_speech
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_text_to_speech():
|
||||
# Prerequisites
|
||||
assert CONFIG.IFLYTEK_APP_ID
|
||||
assert CONFIG.IFLYTEK_API_KEY
|
||||
assert CONFIG.IFLYTEK_API_SECRET
|
||||
assert CONFIG.AZURE_TTS_SUBSCRIPTION_KEY and CONFIG.AZURE_TTS_SUBSCRIPTION_KEY != "YOUR_API_KEY"
|
||||
assert CONFIG.AZURE_TTS_REGION
|
||||
assert config.IFLYTEK_APP_ID
|
||||
assert config.IFLYTEK_API_KEY
|
||||
assert config.IFLYTEK_API_SECRET
|
||||
assert config.AZURE_TTS_SUBSCRIPTION_KEY and config.AZURE_TTS_SUBSCRIPTION_KEY != "YOUR_API_KEY"
|
||||
assert config.AZURE_TTS_REGION
|
||||
|
||||
i = config.copy()
|
||||
# test azure
|
||||
data = await text_to_speech("panda emoji")
|
||||
data = await text_to_speech(
|
||||
"panda emoji",
|
||||
subscription_key=i.AZURE_TTS_SUBSCRIPTION_KEY,
|
||||
region=i.AZURE_TTS_REGION,
|
||||
iflytek_api_key=i.IFLYTEK_API_KEY,
|
||||
iflytek_api_secret=i.IFLYTEK_API_SECRET,
|
||||
iflytek_app_id=i.IFLYTEK_APP_ID,
|
||||
)
|
||||
assert "base64" in data or "http" in data
|
||||
|
||||
# test iflytek
|
||||
## Mock session env
|
||||
old_options = CONFIG.options.copy()
|
||||
new_options = old_options.copy()
|
||||
new_options["AZURE_TTS_SUBSCRIPTION_KEY"] = ""
|
||||
CONFIG.set_context(new_options)
|
||||
try:
|
||||
data = await text_to_speech("panda emoji")
|
||||
assert "base64" in data or "http" in data
|
||||
finally:
|
||||
CONFIG.set_context(old_options)
|
||||
i.AZURE_TTS_SUBSCRIPTION_KEY = ""
|
||||
data = await text_to_speech(
|
||||
"panda emoji",
|
||||
subscription_key=i.AZURE_TTS_SUBSCRIPTION_KEY,
|
||||
region=i.AZURE_TTS_REGION,
|
||||
iflytek_api_key=i.IFLYTEK_API_KEY,
|
||||
iflytek_api_secret=i.IFLYTEK_API_SECRET,
|
||||
iflytek_app_id=i.IFLYTEK_APP_ID,
|
||||
)
|
||||
assert "base64" in data or "http" in data
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
import pytest
|
||||
from azure.cognitiveservices.speech import ResultReason
|
||||
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.config2 import config
|
||||
from metagpt.tools.azure_tts import AzureTTS
|
||||
|
||||
|
|
@ -19,8 +18,8 @@ from metagpt.tools.azure_tts import AzureTTS
|
|||
@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
|
||||
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 = """
|
||||
|
|
|
|||
|
|
@ -7,22 +7,22 @@
|
|||
"""
|
||||
import pytest
|
||||
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.config2 import config
|
||||
from metagpt.tools.iflytek_tts import oas3_iflytek_tts
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_tts():
|
||||
# Prerequisites
|
||||
assert CONFIG.IFLYTEK_APP_ID
|
||||
assert CONFIG.IFLYTEK_API_KEY
|
||||
assert CONFIG.IFLYTEK_API_SECRET
|
||||
assert config.IFLYTEK_APP_ID
|
||||
assert config.IFLYTEK_API_KEY
|
||||
assert config.IFLYTEK_API_SECRET
|
||||
|
||||
result = await oas3_iflytek_tts(
|
||||
text="你好,hello",
|
||||
app_id=CONFIG.IFLYTEK_APP_ID,
|
||||
api_key=CONFIG.IFLYTEK_API_KEY,
|
||||
api_secret=CONFIG.IFLYTEK_API_SECRET,
|
||||
app_id=config.IFLYTEK_APP_ID,
|
||||
api_key=config.IFLYTEK_API_KEY,
|
||||
api_secret=config.IFLYTEK_API_SECRET,
|
||||
)
|
||||
assert result
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.config2 import config
|
||||
from metagpt.tools import web_browser_engine_playwright
|
||||
from metagpt.utils.parse_html import WebPage
|
||||
|
||||
|
|
@ -20,11 +20,11 @@ from metagpt.utils.parse_html import WebPage
|
|||
ids=["chromium-normal", "firefox-normal", "webkit-normal"],
|
||||
)
|
||||
async def test_scrape_web_page(browser_type, use_proxy, kwagrs, url, urls, proxy, capfd):
|
||||
global_proxy = CONFIG.global_proxy
|
||||
global_proxy = config.proxy
|
||||
try:
|
||||
if use_proxy:
|
||||
server, proxy = await proxy
|
||||
CONFIG.global_proxy = proxy
|
||||
config.proxy = proxy
|
||||
browser = web_browser_engine_playwright.PlaywrightWrapper(browser_type=browser_type, **kwagrs)
|
||||
result = await browser.run(url)
|
||||
assert isinstance(result, WebPage)
|
||||
|
|
@ -39,7 +39,7 @@ async def test_scrape_web_page(browser_type, use_proxy, kwagrs, url, urls, proxy
|
|||
server.close()
|
||||
assert "Proxy:" in capfd.readouterr().out
|
||||
finally:
|
||||
CONFIG.global_proxy = global_proxy
|
||||
config.proxy = global_proxy
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.config2 import config
|
||||
from metagpt.tools import web_browser_engine_selenium
|
||||
from metagpt.utils.parse_html import WebPage
|
||||
|
||||
|
|
@ -23,11 +23,11 @@ async def test_scrape_web_page(browser_type, use_proxy, url, urls, proxy, capfd)
|
|||
# Prerequisites
|
||||
# firefox, chrome, Microsoft Edge
|
||||
|
||||
global_proxy = CONFIG.global_proxy
|
||||
global_proxy = config.proxy
|
||||
try:
|
||||
if use_proxy:
|
||||
server, proxy = await proxy
|
||||
CONFIG.global_proxy = proxy
|
||||
config.proxy = proxy
|
||||
browser = web_browser_engine_selenium.SeleniumWrapper(browser_type=browser_type)
|
||||
result = await browser.run(url)
|
||||
assert isinstance(result, WebPage)
|
||||
|
|
@ -42,7 +42,7 @@ async def test_scrape_web_page(browser_type, use_proxy, url, urls, proxy, capfd)
|
|||
server.close()
|
||||
assert "Proxy:" in capfd.readouterr().out
|
||||
finally:
|
||||
CONFIG.global_proxy = global_proxy
|
||||
config.proxy = global_proxy
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.context import CONTEXT
|
||||
from metagpt.utils.common import check_cmd_exists
|
||||
from metagpt.utils.mermaid import MMC1, mermaid_to_file
|
||||
|
|
@ -22,9 +21,8 @@ async def test_mermaid(engine):
|
|||
# playwright prerequisites: playwright install --with-deps chromium
|
||||
assert check_cmd_exists("npm") == 0
|
||||
|
||||
CONFIG.mermaid_engine = engine
|
||||
save_to = CONTEXT.git_repo.workdir / f"{CONFIG.mermaid_engine}/1"
|
||||
await mermaid_to_file(MMC1, save_to)
|
||||
save_to = CONTEXT.git_repo.workdir / f"{engine}/1"
|
||||
await mermaid_to_file(engine, MMC1, save_to)
|
||||
|
||||
# ink does not support pdf
|
||||
if engine == "ink":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue