Skip to content
Merged
19 changes: 17 additions & 2 deletions src/nat/cli/commands/workflow/templates/config.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ general:
front_end:
_type: console

functions:
current_datetime:
_type: current_datetime
{{python_safe_workflow_name}}_echo:
_type: {{python_safe_workflow_name}}_echo
prefix: "Hello:"

llms:
nim_llm:
_type: nim
model_name: meta/llama-3.1-70b-instruct
temperature: 0.0

workflow:
_type: {{workflow_name}}
parameter: default_value
_type: react_agent
llm_name: nim_llm
tool_names: [current_datetime, {{python_safe_workflow_name}}_echo]
parse_agent_response_max_retries: 3
4 changes: 2 additions & 2 deletions src/nat/cli/commands/workflow/templates/register.py.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# flake8: noqa

# Import any tools which need to be automatically registered here
from {{package_name}} import {{workflow_name}}_function
# Import the generated workflow function to trigger registration
from {{package_name}} import {{ python_safe_workflow_name }}_function
34 changes: 11 additions & 23 deletions src/nat/cli/commands/workflow/templates/workflow.py.j2
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
import logging

from pydantic import Field

from nat.builder.builder import Builder
from nat.builder.function_info import FunctionInfo
from nat.builder.framework_enum import LLMFrameworkEnum
from nat.cli.register_workflow import register_function
from nat.data_models.function import FunctionBaseConfig
from pydantic import Field

logger = logging.getLogger(__name__)

class {{ workflow_class_name }}EchoConfig(FunctionBaseConfig, name="{{ python_safe_workflow_name }}_echo"):
prefix: str = Field(default="Echo:", description="Prefix to add before the echoed text.")

class {{ workflow_class_name }}(FunctionBaseConfig, name="{{ workflow_name }}"):
"""
{{workflow_description}}
"""
# Add your custom configuration parameters here
parameter: str = Field(default="default_value", description="Notional description for this parameter")

@register_function(config_type={{ workflow_class_name }}EchoConfig, framework_wrappers=[LLMFrameworkEnum.LANGCHAIN])
async def register_{{ python_safe_workflow_name }}_echo(config: {{ workflow_class_name }}EchoConfig, builder: Builder):

@register_function(config_type={{ workflow_class_name }})
async def {{ python_safe_workflow_name }}_function(
config: {{ workflow_class_name }}, builder: Builder
):
# Implement your function logic here
async def _response_fn(input_message: str) -> str:
# Process the input_message and generate output
output_message = f"Hello from {{ workflow_name }} workflow! You said: {input_message}"
return output_message
async def _echo(text: str) -> str:
return f"{config.prefix} {text}"

try:
yield FunctionInfo.create(single_fn=_response_fn)
except GeneratorExit:
logger.warning("Function exited early!")
finally:
logger.info("Cleaning up {{ workflow_name }} workflow.")
yield FunctionInfo.from_fn(
_echo,
description="This is a function that takes an input and echos back with a pre-defined prefix.")
2 changes: 1 addition & 1 deletion src/nat/cli/commands/workflow/workflow_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def create_command(workflow_name: str, install: bool, workflow_dir: str, descrip
files_to_render = {
'pyproject.toml.j2': new_workflow_dir / 'pyproject.toml',
'register.py.j2': base_dir / 'register.py',
'workflow.py.j2': base_dir / f'{workflow_name}_function.py',
'workflow.py.j2': base_dir / f'{package_name}_function.py',
'__init__.py.j2': base_dir / '__init__.py',
'config.yml.j2': configs_dir / 'config.yml',
}
Expand Down