feat: general slugify method
ref: N25B-429
This commit is contained in:
@@ -361,6 +361,10 @@ class AgentSpeakGenerator:
|
||||
def _(self, goal: Goal, achieved: bool = False) -> AstExpression:
|
||||
return AstLiteral(f"{'achieved_' if achieved else ''}{self._slugify_str(goal.name)}")
|
||||
|
||||
@_astify.register
|
||||
def _(self, trigger: Trigger) -> AstExpression:
|
||||
return AstLiteral(self.slugify(trigger))
|
||||
|
||||
@_astify.register
|
||||
def _(self, sa: SpeechAction) -> AstExpression:
|
||||
return AstLiteral("say", [AstString(sa.text)])
|
||||
@@ -374,6 +378,26 @@ class AgentSpeakGenerator:
|
||||
def _(self, la: LLMAction) -> AstExpression:
|
||||
return AstLiteral("reply_with_goal", [AstString(la.goal)])
|
||||
|
||||
@staticmethod
|
||||
@singledispatchmethod
|
||||
def slugify(element: ProgramElement) -> str:
|
||||
raise NotImplementedError(f"Cannot convert element {element} to a slug.")
|
||||
|
||||
@staticmethod
|
||||
@slugify.register
|
||||
def _(sb: SemanticBelief) -> str:
|
||||
return f"semantic_{AgentSpeakGenerator._slugify_str(sb.name)}"
|
||||
|
||||
@staticmethod
|
||||
@slugify.register
|
||||
def _(g: Goal) -> str:
|
||||
return AgentSpeakGenerator._slugify_str(g.name)
|
||||
|
||||
@staticmethod
|
||||
@slugify.register
|
||||
def _(t: Trigger):
|
||||
return f"trigger_{AgentSpeakGenerator._slugify_str(t.name)}"
|
||||
|
||||
@staticmethod
|
||||
def _slugify_str(text: str) -> str:
|
||||
return slugify(text, separator="_", stopwords=["a", "an", "the", "we", "you", "I"])
|
||||
|
||||
@@ -177,7 +177,7 @@ class TextBeliefExtractorAgent(BaseAgent):
|
||||
|
||||
@staticmethod
|
||||
def _create_belief_schema(belief: SemanticBelief) -> tuple[str, dict]:
|
||||
return AgentSpeakGenerator.get_semantic_belief_slug(belief), {
|
||||
return AgentSpeakGenerator.slugify(belief), {
|
||||
"type": ["boolean", "null"],
|
||||
"description": belief.description,
|
||||
}
|
||||
@@ -207,10 +207,7 @@ class TextBeliefExtractorAgent(BaseAgent):
|
||||
@staticmethod
|
||||
def _format_beliefs(beliefs: list[SemanticBelief]):
|
||||
return "\n".join(
|
||||
[
|
||||
f"- {AgentSpeakGenerator.get_semantic_belief_slug(belief)}: {belief.description}"
|
||||
for belief in beliefs
|
||||
]
|
||||
[f"- {AgentSpeakGenerator.slugify(belief)}: {belief.description}" for belief in beliefs]
|
||||
)
|
||||
|
||||
async def _infer_beliefs(
|
||||
|
||||
Reference in New Issue
Block a user