mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-21 14:05:17 +02:00
feat: replaced with OPTIONS
This commit is contained in:
parent
3a1ebf19b7
commit
143ffb0c2c
39 changed files with 144 additions and 252 deletions
|
|
@ -1,25 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Time : 2023/8/20
|
||||
@Author : mashenquan
|
||||
@File : skill_metadata.py
|
||||
@Desc : Defines metadata for the `skill`.
|
||||
Depending on the context and specific circumstances, skills may have different effects.
|
||||
For example:
|
||||
Proprietor: "Skill of the proprietor entity."
|
||||
Holder: "Skill of the holder entity."
|
||||
Possessor: "Skill of the possessor entity."
|
||||
Controller: "Skill of the controller entity."
|
||||
Owner: "Skill of the owner entity."
|
||||
"""
|
||||
|
||||
|
||||
def skill_metadata(name, description, requisite):
|
||||
def decorator(func):
|
||||
func.skill_name = name
|
||||
func.skill_description = description
|
||||
func.skill_requisite = requisite
|
||||
return func
|
||||
|
||||
return decorator
|
||||
|
|
@ -6,16 +6,11 @@
|
|||
@File : text_to_embedding.py
|
||||
@Desc : Text-to-Embedding skill, which provides text-to-embedding functionality.
|
||||
"""
|
||||
import os
|
||||
|
||||
from metagpt.learn.skill_metadata import skill_metadata
|
||||
from metagpt.config import CONFIG
|
||||
from metagpt.tools.openai_text_to_embedding import oas3_openai_text_to_embedding
|
||||
from metagpt.utils.common import initialize_environment
|
||||
|
||||
|
||||
@skill_metadata(name="Text to Embedding",
|
||||
description="Convert the text into embeddings.",
|
||||
requisite="`OPENAI_API_KEY`")
|
||||
async def text_to_embedding(text, model="text-embedding-ada-002", openai_api_key="", **kwargs):
|
||||
"""Text to embedding
|
||||
|
||||
|
|
@ -24,7 +19,6 @@ async def text_to_embedding(text, model="text-embedding-ada-002", openai_api_key
|
|||
:param openai_api_key: OpenAI API key, For more details, checkout: `https://platform.openai.com/account/api-keys`
|
||||
:return: A json object of :class:`ResultEmbedding` class if successful, otherwise `{}`.
|
||||
"""
|
||||
initialize_environment()
|
||||
if os.environ.get("OPENAI_API_KEY") or openai_api_key:
|
||||
if CONFIG.OPENAI_API_KEY or openai_api_key:
|
||||
return await oas3_openai_text_to_embedding(text, model=model, openai_api_key=openai_api_key)
|
||||
raise EnvironmentError
|
||||
|
|
|
|||
|
|
@ -8,15 +8,11 @@
|
|||
"""
|
||||
import os
|
||||
|
||||
from metagpt.learn.skill_metadata import skill_metadata
|
||||
from metagpt.config import CONFIG
|
||||
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
|
||||
|
||||
|
||||
@skill_metadata(name="Text to image",
|
||||
description="Create a drawing based on the text.",
|
||||
requisite="`OPENAI_API_KEY` or `METAGPT_TEXT_TO_IMAGE_MODEL`")
|
||||
async def text_to_image(text, size_type: str = "512x512", openai_api_key="", model_url="", **kwargs):
|
||||
"""Text to image
|
||||
|
||||
|
|
@ -26,13 +22,12 @@ async def text_to_image(text, size_type: str = "512x512", openai_api_key="", mod
|
|||
:param model_url: MetaGPT model url
|
||||
:return: The image data is returned in Base64 encoding.
|
||||
"""
|
||||
initialize_environment()
|
||||
image_declaration = "data:image/png;base64,"
|
||||
if os.environ.get("METAGPT_TEXT_TO_IMAGE_MODEL_URL") or model_url:
|
||||
if CONFIG.METAGPT_TEXT_TO_IMAGE_MODEL_URL or model_url:
|
||||
data = await oas3_metagpt_text_to_image(text, size_type, model_url)
|
||||
return image_declaration + data if data else ""
|
||||
|
||||
if os.environ.get("OPENAI_API_KEY") or openai_api_key:
|
||||
if CONFIG.OPENAI_API_KEY or openai_api_key:
|
||||
data = await oas3_openai_text_to_image(text, size_type, openai_api_key)
|
||||
return image_declaration + data if data else ""
|
||||
|
||||
|
|
|
|||
|
|
@ -6,16 +6,14 @@
|
|||
@File : text_to_speech.py
|
||||
@Desc : Text-to-Speech skill, which provides text-to-speech functionality
|
||||
"""
|
||||
import os
|
||||
|
||||
from metagpt.learn.skill_metadata import skill_metadata
|
||||
|
||||
from metagpt.config import CONFIG
|
||||
|
||||
from metagpt.tools.azure_tts import oas3_azsure_tts
|
||||
from metagpt.utils.common import initialize_environment
|
||||
|
||||
|
||||
@skill_metadata(name="Text to speech",
|
||||
description="Text-to-speech",
|
||||
requisite="`AZURE_TTS_SUBSCRIPTION_KEY` and `AZURE_TTS_REGION`")
|
||||
|
||||
async def text_to_speech(text, lang="zh-CN", voice="zh-CN-XiaomoNeural", style="affectionate", role="Girl",
|
||||
subscription_key="", region="", **kwargs):
|
||||
"""Text to speech
|
||||
|
|
@ -31,9 +29,8 @@ async def text_to_speech(text, lang="zh-CN", voice="zh-CN-XiaomoNeural", style="
|
|||
:return: Returns the Base64-encoded .wav file data if successful, otherwise an empty string.
|
||||
|
||||
"""
|
||||
initialize_environment()
|
||||
audio_declaration = "data:audio/wav;base64,"
|
||||
if (os.environ.get("AZURE_TTS_SUBSCRIPTION_KEY") and os.environ.get("AZURE_TTS_REGION")) or \
|
||||
if (CONFIG.AZURE_TTS_SUBSCRIPTION_KEY and CONFIG.AZURE_TTS_REGION) or \
|
||||
(subscription_key and region):
|
||||
data = await oas3_azsure_tts(text, lang, voice, style, role, subscription_key, region)
|
||||
return audio_declaration + data if data else data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue