Merge pull request #21 from iorisa/feature/skills

Feature/skills
This commit is contained in:
Justin-ZL 2023-09-02 22:03:35 +08:00 committed by GitHub
commit 14733f1974
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 34 deletions

View file

@ -7,11 +7,13 @@
@Desc : Skill YAML Configuration Loader.
"""
from pathlib import Path
from typing import List, Dict, Optional
from typing import Dict, List, Optional
import yaml
from pydantic import BaseModel, Field
from metagpt.config import CONFIG
class Example(BaseModel):
ask: str
@ -52,7 +54,7 @@ class SkillLoader:
def __init__(self, skill_yaml_file_name: Path = None):
if not skill_yaml_file_name:
skill_yaml_file_name = Path(__file__).parent.parent.parent / ".well-known/skills.yaml"
with open(str(skill_yaml_file_name), 'r') as file:
with open(str(skill_yaml_file_name), "r") as file:
skills = yaml.safe_load(file)
self._skills = SkillsDeclaration(**skills)
@ -62,8 +64,18 @@ class SkillLoader:
if not entity_skills:
return {}
agent_skills = CONFIG.agent_skills
if not agent_skills:
return {}
class AgentSkill(BaseModel):
name: str
names = [AgentSkill(**i).name for i in agent_skills]
description_to_name_mappings = {}
for s in entity_skills.skills:
if s.name not in names:
continue
description_to_name_mappings[s.description] = s.name
return description_to_name_mappings

View file

@ -33,7 +33,7 @@ async def text_to_image(text, size_type: str = "512x512", openai_api_key="", mod
raise openai.error.InvalidRequestError("缺少必要的参数")
s3 = S3()
url = await s3.cache(base64_data, BASE64_FORMAT)
url = await s3.cache(data=base64_data, file_ext=".png", format=BASE64_FORMAT)
if url:
return url
return f"[{text}]({url})"
return image_declaration + base64_data if base64_data else ""

View file

@ -22,7 +22,7 @@ async def text_to_speech(
role="Girl",
subscription_key="",
region="",
**kwargs
**kwargs,
):
"""Text to speech
For more details, check out:`https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support?tabs=tts`
@ -41,9 +41,9 @@ async def text_to_speech(
if (CONFIG.AZURE_TTS_SUBSCRIPTION_KEY and CONFIG.AZURE_TTS_REGION) or (subscription_key and region):
base64_data = await oas3_azsure_tts(text, lang, voice, style, role, subscription_key, region)
s3 = S3()
url = await s3.cache(base64_data, BASE64_FORMAT)
url = await s3.cache(data=base64_data, file_ext=".wav", format=BASE64_FORMAT)
if url:
return url
return f"[{text}]({url})"
return audio_declaration + base64_data if base64_data else base64_data
raise openai.error.InvalidRequestError("缺少必要的参数")