Skip to content

Commit

Permalink
Tj202/pr add qol (#39)
Browse files Browse the repository at this point in the history
* Adding notice

* Removed wrong notice

* Removing autogen message from jinja templates

* Adding notice

* Added docstring

* Created tools/prompts now open in vim

* Added option to set EDITOR, VISUAL in env

* In windows, file will open in notepad

---------

Co-authored-by: Thejas N U <[email protected]>
  • Loading branch information
TJ202 and ThejasNU authored Jan 23, 2025
1 parent 258ec43 commit f535ce3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
18 changes: 18 additions & 0 deletions libs/agentc_cli/agentc_cli/cmds/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@
import datetime
import jinja2
import logging
import os
import pathlib
import platform
import subprocess
import typing

from ..models.context import Context
from agentc_core.record.descriptor import RecordKind

logger = logging.getLogger(__name__)

if os.environ.get("EDITOR"):
default_editor = os.environ.get("EDITOR")
elif os.environ.get("VISUAL"):
default_editor = os.environ.get("VISUAL")
elif platform.system() == "Windows":
default_editor = "notepad"
else:
default_editor = "vi"


def _get_name_and_description() -> tuple[str, str]:
name = click.prompt("Name", type=str)
Expand Down Expand Up @@ -37,6 +49,7 @@ def add_jinja_prompt(output: pathlib.Path, template_env: jinja2.Environment):
with output_file.open("w") as fp:
fp.write(rendered)
click.secho(f"Jinja prompt written to: {output_file}", fg="green")
subprocess.run([default_editor, f"{output_file}"])


def add_raw_prompt(output: pathlib.Path, template_env: jinja2.Environment):
Expand All @@ -56,6 +69,7 @@ def add_raw_prompt(output: pathlib.Path, template_env: jinja2.Environment):
with output_file.open("w") as fp:
fp.write(rendered)
click.secho(f"Raw prompt written to: {output_file}", fg="green")
subprocess.run([default_editor, f"{output_file}"])


def add_http_request(output: pathlib.Path, template_env: jinja2.Environment):
Expand All @@ -82,6 +96,7 @@ def add_http_request(output: pathlib.Path, template_env: jinja2.Environment):
with output_file.open("w") as fp:
fp.write(rendered)
click.secho(f"HTML request tool written to: {output_file}", fg="green")
subprocess.run([default_editor, f"{output_file}"])


def add_python_function(output: pathlib.Path, template_env: jinja2.Environment):
Expand All @@ -99,6 +114,7 @@ def add_python_function(output: pathlib.Path, template_env: jinja2.Environment):
with output_file.open("w") as fp:
fp.write(rendered)
click.secho(f"Python (function) tool written to: {output_file}", fg="green")
subprocess.run([default_editor, f"{output_file}"])


def add_semantic_search(output: pathlib.Path, template_env: jinja2.Environment):
Expand Down Expand Up @@ -133,6 +149,7 @@ def add_semantic_search(output: pathlib.Path, template_env: jinja2.Environment):
with output_file.open("w") as fp:
fp.write(rendered)
click.secho(f"Semantic search tool written to: {output_file}", fg="green")
subprocess.run([default_editor, f"{output_file}"])


def add_sqlpp_query(output: pathlib.Path, template_env: jinja2.Environment):
Expand All @@ -150,6 +167,7 @@ def add_sqlpp_query(output: pathlib.Path, template_env: jinja2.Environment):
with output_file.open("w") as fp:
fp.write(rendered)
click.secho(f"SQL++ query tool written to: {output_file}", fg="green")
subprocess.run([default_editor, f"{output_file}"])


def cmd_add(
Expand Down
2 changes: 1 addition & 1 deletion libs/agentc_cli/agentc_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def click_main(ctx, catalog, activity, verbose, interactive):
)
@click.pass_context
def add(ctx, output: pathlib.Path, record_kind: RecordKind):
"""Interactively create a new tool or prompt and save it to the filesystem (output)."""
"""Interactively create a new tool or prompt and save it to the filesystem (output). You MUST edit the generated file as per your requirements!"""
ctx_obj: Context = ctx.obj
if not ctx_obj.interactive:
click.secho(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
""" This file has been generated automatically by AGENT_CATALOG at {{ time }} as a http_request tool. """
from __future__ import annotations

import requests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
""" This file has been generated automatically by AGENT_CATALOG at {{ time }} as a semantic_search tool. """
from __future__ import annotations

import couchbase.auth
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
""" This file has been generated automatically by AGENT_CATALOG at {{ time }} as a sqlpp_query tool. """
from __future__ import annotations

import couchbase.auth
Expand Down

0 comments on commit f535ce3

Please sign in to comment.