|
| 1 | +# |
| 2 | +# This file is part of TEN Framework, an open source project. |
| 3 | +# Licensed under the Apache License, Version 2.0. |
| 4 | +# See the LICENSE file for more information. |
| 5 | +# |
| 6 | +from ten import ( |
| 7 | + TenEnv, |
| 8 | + AsyncTenEnv, |
| 9 | +) |
| 10 | +from ten_ai_base import ( |
| 11 | + AsyncLLMToolBaseExtension, LLMToolMetadata, LLMToolResult, BaseConfig |
| 12 | +) |
| 13 | +from dataclasses import dataclass |
| 14 | + |
| 15 | + |
| 16 | +@dataclass |
| 17 | +class {{class_name_prefix}}Config(BaseConfig): |
| 18 | + # TODO: add extra config fields here |
| 19 | + pass |
| 20 | + |
| 21 | + |
| 22 | +class {{class_name_prefix}}Extension(AsyncLLMToolBaseExtension): |
| 23 | + async def on_start(self, ten_env: AsyncTenEnv) -> None: |
| 24 | + await super().on_start(ten_env) |
| 25 | + |
| 26 | + # initialize configuration |
| 27 | + self.config = {{class_name_prefix}}Config.create(ten_env=ten_env) |
| 28 | + ten_env.log_info(f"config: {self.config}") |
| 29 | + |
| 30 | + """Implement this method to construct and start your resources.""" |
| 31 | + ten_env.log_debug("TODO: on_start") |
| 32 | + |
| 33 | + async def on_stop(self, ten_env: AsyncTenEnv) -> None: |
| 34 | + await super().on_stop(ten_env) |
| 35 | + |
| 36 | + """Implement this method to stop and destruct your resources.""" |
| 37 | + ten_env.log_debug("TODO: on_stop") |
| 38 | + |
| 39 | + def get_tool_metadata(self, ten_env: TenEnv) -> list[LLMToolMetadata]: |
| 40 | + ten_env.log_debug("TODO: get_tool_metadata") |
| 41 | + return [] |
| 42 | + |
| 43 | + async def run_tool(self, ten_env: AsyncTenEnv, name: str, args: dict) -> LLMToolResult: |
| 44 | + ten_env.log_debug(f"TODO: run_tool {name} {args}") |
0 commit comments