Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions auto_dev/commands/scaffold.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
"""

import sys
import enum
from pathlib import Path

import yaml
import rich_click as click
from web3 import Web3
from jinja2 import Environment, FileSystemLoader
from aea.configurations.constants import DEFAULT_AEA_CONFIG_FILE, PROTOCOL_LANGUAGE_PYTHON, SUPPORTED_PROTOCOL_LANGUAGES
from aea.configurations.constants import (
DEFAULT_AEA_CONFIG_FILE,
PROTOCOL_LANGUAGE_PYTHON,
SUPPORTED_PROTOCOL_LANGUAGES,
)
from aea.configurations.data_types import PublicId

from auto_dev.base import build_cli
Expand All @@ -25,6 +30,7 @@
from auto_dev.cli_executor import CommandExecutor
from auto_dev.handlers.base import HandlerTypes, HandlerScaffolder
from auto_dev.dao.scaffolder import DAOScaffolder
from auto_dev.workflow_manager import Task
from auto_dev.contracts.contract import DEFAULT_NULL_ADDRESS
from auto_dev.handler.scaffolder import HandlerScaffoldBuilder
from auto_dev.dialogues.scaffolder import DialogueTypes, DialogueScaffolder
Expand All @@ -33,7 +39,13 @@
from auto_dev.connections.scaffolder import ConnectionScaffolder
from auto_dev.contracts.block_explorer import BlockExplorer
from auto_dev.contracts.contract_scafolder import ContractScaffolder
from auto_dev.workflow_manager import Task
from auto_dev.services.mech.create_mech_tool import main as create_mech_tool


class ScaffoldType(enum.Enum):
"""Enum representing different types of scaffolds."""
MECH = "mech"
OTHER_TYPES = "other_types"


cli = build_cli()
Expand Down Expand Up @@ -103,6 +115,37 @@ def _process_from_file(ctx, yaml_dict, network, read_functions, write_functions,
)


@scaffold.command()
@click.option(
"--type",
type=click.Choice([e.value for e in ScaffoldType]),
required=True,
help="Specify the type of scaffold to create",
)
@click.argument("api_file", type=str)
@click.argument("tool_name", type=str)
@click.argument("author_name", type=str)
@click.argument("gpt_key", type=str)
@click.pass_context
def custom(type, api_file, tool_name, author_name, gpt_key):
"""Scaffold a custom tool, such as a Mech tool."""

if type == "mech":
if not api_file or not tool_name or not author_name or not gpt_key:
msg = "For --type mech, you must provide api_file, tool_name, author_name, and gpt_key."
raise click.ClickException(msg)

click.echo(f"Creating Mech tool '{tool_name}' by {author_name}...")

# Run the Mech tool creator script
create_mech_tool(api_file=api_file, tool_name=tool_name, author_name=author_name, gpt_key=gpt_key)

click.echo(f"Mech tool '{tool_name}' successfully scaffolded!")

else:
click.echo(f"Scaffolding for type '{type}' is not implemented yet.")


@scaffold.command()
@click.argument("public_id", type=PublicId.from_str, default=None, required=False)
@click.option("--address", default=DEFAULT_NULL_ADDRESS, required=False, help="The address of the contract.")
Expand Down
1 change: 1 addition & 0 deletions auto_dev/services/mech/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Initialisation."""
1 change: 1 addition & 0 deletions auto_dev/services/mech/constants/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Initialisation."""
30 changes: 30 additions & 0 deletions auto_dev/services/mech/constants/prompts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Module containing prompt-related constants for Mech services."""

COMMENTS = """
1. The main() function should only be used for testing purposes. Do NOT push this.
2. Once main() works as expected run 'autonomy packages lock && autonomy push-all'
3. Add to API_KEY list in .example.env and adhere to the current structure.
4. Next, add all new models to FILE_HASH_TO_TOOLS and use the new hash from packages/packages.json for your tool.
Check this PR for reference. https://github.com/valory-xyz/mech/pull/228/files
"""

INIT_CONTENT = """#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2024 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------
"""
Loading