From cc92d8fb4afdbed517cf6616373b4a3100cf0ed5 Mon Sep 17 00:00:00 2001 From: zhanglei Date: Mon, 15 Jan 2024 14:11:41 +0800 Subject: [PATCH 1/2] add:openai text to speech --- metagpt/provider/openai_api.py | 4 ++++ tests/metagpt/provider/test_openai.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.py index 3f3a4e1a7..3a9aca870 100644 --- a/metagpt/provider/openai_api.py +++ b/metagpt/provider/openai_api.py @@ -235,3 +235,7 @@ class OpenAILLM(BaseLLM): async def amoderation(self, content: Union[str, list[str]]): """Moderate content.""" return await self.aclient.moderations.create(input=content) + + async def atext_to_speech(self, **kwargs): + """text to speech""" + return await self.aclient.audio.speech.create(**kwargs) diff --git a/tests/metagpt/provider/test_openai.py b/tests/metagpt/provider/test_openai.py index ca9e918da..cb0d0d636 100644 --- a/tests/metagpt/provider/test_openai.py +++ b/tests/metagpt/provider/test_openai.py @@ -42,6 +42,18 @@ async def test_aask_code_message(): assert len(rsp["code"]) > 0 +@pytest.mark.asyncio +async def test_text_to_speech(): + llm = LLM() + resp = await llm.atext_to_speech( + model="tts-1", + voice="alloy", + input="人生说起来长,但知道一个岁月回头看,许多事件仅是仓促的。一段一段拼凑一起,合成了人生。苦难当头时,当下不免觉得是折磨;回头看,也不够是一段短短的人生旅程。", + ) + assert 200 == resp.response.status_code + + + class TestOpenAI: def test_make_client_kwargs_without_proxy(self): instance = OpenAILLM(mock_llm_config) From ca63880753f7d6ea560c36ee24e17d721a9a81ba Mon Sep 17 00:00:00 2001 From: zhanglei Date: Mon, 15 Jan 2024 14:18:35 +0800 Subject: [PATCH 2/2] add: openai's text to speech --- tests/metagpt/provider/test_openai.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/metagpt/provider/test_openai.py b/tests/metagpt/provider/test_openai.py index cb0d0d636..bf19a77b8 100644 --- a/tests/metagpt/provider/test_openai.py +++ b/tests/metagpt/provider/test_openai.py @@ -53,7 +53,6 @@ async def test_text_to_speech(): assert 200 == resp.response.status_code - class TestOpenAI: def test_make_client_kwargs_without_proxy(self): instance = OpenAILLM(mock_llm_config)