Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tool to agenstack.json #21

Merged
merged 1 commit into from
Oct 17, 2024
Merged
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
12 changes: 10 additions & 2 deletions agentstack/generation/tool_generation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import sys
from typing import Optional

from .gen_utils import insert_code_after_tag
from ..utils import snake_to_camel, open_json_file, get_framework
from ..utils import open_json_file, get_framework, term_color
import os
import shutil
import fileinput
Expand All @@ -24,7 +25,14 @@ def add_tool(tool_name: str, path: Optional[str] = None):
insert_code_after_tag(f'{path}/.env', '# Tools', [tool_data['env']], next_line=True) # Add env var
insert_code_after_tag(f'{path}/.env.example', '# Tools', [tool_data['env']], next_line=True) # Add env var

print(f'\033[92m🔨 Tool {tool_name} added to agentstack project successfully\033[0m')
agentstack_json = open_json_file(f'{path}/agentstack.json')
if not agentstack_json.get('tools'):
agentstack_json['tools'] = []
agentstack_json['tools'].append(tool_name)
with open(f'{path}/agentstack.json', 'w') as f:
json.dump(agentstack_json, f, indent=4)

print(term_color(f'🔨 Tool {tool_name} added to agentstack project successfully', 'green'))


def add_tool_to_tools_init(tool_data: dict, path: Optional[str] = None):
Expand Down
12 changes: 6 additions & 6 deletions agentstack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def get_framework(path: Optional[str] = None) -> str:
file_path = 'agentstack.json'
if path is not None:
file_path = path + '/' + file_path
with open(file_path, 'r') as f:
data = json.load(f)
framework = data.get('framework')

if framework.lower() not in ['crewai', 'autogen', 'litellm']:
print("\033[31magentstack.json contains an invalid framework\033[0m")
agentstack_data = open_json_file(file_path)
framework = agentstack_data.get('framework')

return framework
if framework.lower() not in ['crewai', 'autogen', 'litellm']:
print(term_color("agentstack.json contains an invalid framework", "red"))

return framework
except FileNotFoundError:
print("\033[31mFile agentstack.json does not exist. Are you in the right directory?\033[0m")
sys.exit(1)
Expand Down
Loading