|
7 | 7 |
|
8 | 8 | import textwrap
|
9 | 9 | from datetime import datetime
|
10 |
| -from typing import Any, List |
| 10 | +from typing import Any, List, Optional |
11 | 11 |
|
12 | 12 | from llama_models.llama3.api.datatypes import (
|
13 | 13 | BuiltinTool,
|
@@ -215,14 +215,33 @@ def data_examples(self) -> List[List[ToolDefinition]]:
|
215 | 215 |
|
216 | 216 |
|
217 | 217 | class PythonListCustomToolGenerator(PromptTemplateGeneratorBase): # noqa: N801
|
218 |
| - def gen(self, custom_tools: List[ToolDefinition]) -> PromptTemplate: |
| 218 | + DEFAULT_PROMPT = textwrap.dedent( |
| 219 | + """ |
| 220 | + You are an expert in composing functions. You are given a question and a set of possible functions. |
| 221 | + Based on the question, you will need to make one or more function/tool calls to achieve the purpose. |
| 222 | + If none of the function can be used, point it out. If the given question lacks the parameters required by the function, |
| 223 | + also point it out. You should only return the function call in tools call sections. |
| 224 | +
|
| 225 | + {{ function_description }} |
| 226 | + """.strip( |
| 227 | + "\n" |
| 228 | + ) |
| 229 | + ) |
| 230 | + |
| 231 | + def gen( |
| 232 | + self, custom_tools: List[ToolDefinition], system_prompt: Optional[str] = None |
| 233 | + ) -> PromptTemplate: |
| 234 | + system_prompt = system_prompt or self.DEFAULT_PROMPT |
| 235 | + return PromptTemplate( |
| 236 | + system_prompt, |
| 237 | + {"function_description": self._gen_function_description(custom_tools)}, |
| 238 | + ) |
| 239 | + |
| 240 | + def _gen_function_description( |
| 241 | + self, custom_tools: List[ToolDefinition] |
| 242 | + ) -> PromptTemplate: |
219 | 243 | template_str = textwrap.dedent(
|
220 | 244 | """
|
221 |
| - You are an expert in composing functions. You are given a question and a set of possible functions. |
222 |
| - Based on the question, you will need to make one or more function/tool calls to achieve the purpose. |
223 |
| - If none of the function can be used, point it out. If the given question lacks the parameters required by the function, |
224 |
| - also point it out. You should only return the function call in tools call sections. |
225 |
| -
|
226 | 245 | If you decide to invoke any of the function(s), you MUST put it in the format of [func_name1(params_name1=params_value1, params_name2=params_value2...), func_name2(params)]
|
227 | 246 | You SHOULD NOT include any other text in the response.
|
228 | 247 |
|
@@ -263,7 +282,7 @@ def gen(self, custom_tools: List[ToolDefinition]) -> PromptTemplate:
|
263 | 282 | return PromptTemplate(
|
264 | 283 | template_str.strip("\n"),
|
265 | 284 | {"tools": [t.model_dump() for t in custom_tools]},
|
266 |
| - ) |
| 285 | + ).render() |
267 | 286 |
|
268 | 287 | def data_examples(self) -> List[List[ToolDefinition]]:
|
269 | 288 | return [
|
|
0 commit comments