Files
LangBot/plugins/misc/EssentialCommands/components/commands/func.py
T

44 lines
1.4 KiB
Python

# Auto generated by LangBot Plugin SDK.
# Please refer to https://langbot.app/docs/en/plugin/dev/tutor.html for more details.
from __future__ import annotations
from typing import Any, AsyncGenerator
from langbot_plugin.api.definition.components.command.command import Command, Subcommand
from langbot_plugin.api.entities.builtin.command.context import ExecuteContext, CommandReturn
from i18n import get_text
class Func(Command):
async def initialize(self):
await super().initialize()
@self.subcommand(
name="",
help="Show all registered LLM tools",
usage="func",
)
async def _(self: Func, context: ExecuteContext) -> AsyncGenerator[CommandReturn, None]:
language = self.plugin.get_language()
tools = await self.plugin.list_tools()
tool_list_str = ''
for tool in tools:
tool_manifest = tool['manifest']
name = tool_manifest['metadata']['name']
description = tool_manifest['metadata']['description'][language]
prompt = tool_manifest['spec']['llm_prompt']
tool_list_str += get_text(language, "func.tool_item", name=name, description=description, prompt=prompt) + "\n"
title = get_text(language, "func.title")
output = f"{title}\n\n{tool_list_str}"
yield CommandReturn(
text=output
)