mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-02 20:32:38 +02:00
feat: update text_to_image skill
This commit is contained in:
parent
20568a3d72
commit
3715a69e3f
4 changed files with 23 additions and 8 deletions
|
|
@ -6,8 +6,9 @@
|
|||
@File : text_to_embedding.py
|
||||
@Desc : Text-to-Embedding skill, which provides text-to-embedding functionality.
|
||||
"""
|
||||
import os
|
||||
|
||||
from metagpt.tools.openai_text_2_embedding import oas3_openai_text_2_embedding
|
||||
from metagpt.tools.openai_text_to_embedding import oas3_openai_text_to_embedding
|
||||
from metagpt.utils.common import initialize_environment
|
||||
|
||||
|
||||
|
|
@ -20,4 +21,6 @@ def text_to_embedding(text, model="text-embedding-ada-002", openai_api_key=""):
|
|||
:return: A json object of :class:`ResultEmbedding` class if successful, otherwise `{}`.
|
||||
"""
|
||||
initialize_environment()
|
||||
return oas3_openai_text_2_embedding(text, model=model, openai_api_key=openai_api_key)
|
||||
if os.environ.get("OPENAI_API_KEY") or openai_api_key:
|
||||
return oas3_openai_text_to_embedding(text, model=model, openai_api_key=openai_api_key)
|
||||
raise EnvironmentError
|
||||
|
|
|
|||
|
|
@ -6,18 +6,25 @@
|
|||
@File : text_to_image.py
|
||||
@Desc : Text-to-Image skill, which provides text-to-image functionality.
|
||||
"""
|
||||
import os
|
||||
|
||||
from metagpt.tools.openai_text_2_image import oas3_openai_text_2_image
|
||||
from metagpt.tools.metagpt_text_to_image import oas3_metagpt_text_to_image
|
||||
from metagpt.tools.openai_text_to_image import oas3_openai_text_to_image
|
||||
from metagpt.utils.common import initialize_environment
|
||||
|
||||
|
||||
def text_to_image(text, size_type: str = "1024x1024", openai_api_key=""):
|
||||
def text_to_image(text, size_type: str = "512x512", openai_api_key="", model_url=""):
|
||||
"""Text to image
|
||||
|
||||
:param text: The text used for image conversion.
|
||||
:param openai_api_key: OpenAI API key, For more details, checkout: `https://platform.openai.com/account/api-keys`
|
||||
:param size_type: One of ['256x256', '512x512', '1024x1024']
|
||||
:param size_type: If using OPENAI, the available size options are ['256x256', '512x512', '1024x1024'], while for MetaGPT, the options are ['512x512', '512x768'].
|
||||
:param model_url: MetaGPT model url
|
||||
:return: The image data is returned in Base64 encoding.
|
||||
"""
|
||||
initialize_environment()
|
||||
return oas3_openai_text_2_image(text, size_type, openai_api_key)
|
||||
if os.environ.get("METAGPT_TEXT_TO_IMAGE_MODEL") or model_url:
|
||||
return oas3_metagpt_text_to_image(text, size_type, model_url)
|
||||
if os.environ.get("OPENAI_API_KEY") or openai_api_key:
|
||||
return oas3_openai_text_to_image(text, size_type, openai_api_key)
|
||||
raise EnvironmentError
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
@File : text_to_speech.py
|
||||
@Desc : Text-to-Speech skill, which provides text-to-speech functionality
|
||||
"""
|
||||
import os
|
||||
|
||||
from metagpt.tools.azure_tts import oas3_azsure_tts
|
||||
from metagpt.utils.common import initialize_environment
|
||||
|
|
@ -26,4 +27,8 @@ def text_to_speech(text, lang="zh-CN", voice="zh-CN-XiaomoNeural", style="affect
|
|||
|
||||
"""
|
||||
initialize_environment()
|
||||
return oas3_azsure_tts(text, lang, voice, style, role, subscription_key, region)
|
||||
if (os.environ.get("AZURE_TTS_SUBSCRIPTION_KEY") and os.environ.get("AZURE_TTS_REGION")) or \
|
||||
(subscription_key and region):
|
||||
return oas3_azsure_tts(text, lang, voice, style, role, subscription_key, region)
|
||||
|
||||
raise EnvironmentError
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue