feat: +skill config

This commit is contained in:
莘权 马 2023-09-02 19:17:35 +08:00
parent c5e16330a2
commit 2148e4e4f4

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