Skip to content

Commit

Permalink
fix(agents): Use ogf behavior file
Browse files Browse the repository at this point in the history
  • Loading branch information
Estrada Irribarra, Rodrigo Andres committed Oct 14, 2024
1 parent e41c9a9 commit 4671d8e
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions storycraftr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def project_not_initialized_error(book_name):
console.print(f"[bold red]✖[/bold red] Project '[bold]{book_name}[/bold]' is not initialized. "
f"Run '[bold]storycraftr init {book_name}[/bold]' first.", style="bold red")

# Function to create the folder structure and config file
def init_structure(book_name, primary_language, alternate_languages, default_author, genre):
def init_structure(book_name, primary_language, alternate_languages, default_author, genre, behavior_content):
# Show initialization start
console.print(f"[bold blue]Initializing book structure: {book_name}[/bold blue]")

Expand Down Expand Up @@ -81,11 +80,24 @@ def init_structure(book_name, primary_language, alternate_languages, default_aut

# Log configuration file creation
console.print(f"[green]Configuration file created:[/green] {config_file}", style="green")

# Create 'behaviors' folder inside the root book_name directory
behaviors_dir = os.path.join(book_name, 'behaviors')
os.makedirs(behaviors_dir, exist_ok=True)

# Create the default.txt file inside the 'behaviors' folder with the behavior content
behavior_file = os.path.join(behaviors_dir, 'default.txt')
with open(behavior_file, 'w') as f:
f.write(behavior_content)

# Log behavior file creation
console.print(f"[green]Behavior file created:[/green] {behavior_file}", style="green")

# Confirm completion
console.print(f"[bold green]✔[/bold green] Project '[bold]{book_name}[/bold]' initialized successfully.", style="bold green")



# Function to load the configuration file
def load_config(book_name):
config_file = os.path.join(book_name, 'storycraftr.json')
Expand All @@ -109,11 +121,20 @@ def cli():
@click.option("--alternate-languages", default="", help="Comma-separated list of alternate languages (e.g., 'es,fr').")
@click.option("--author", default="Author Name", help="The default author of the book.")
@click.option("--genre", default="fantasy", help="The genre of the book (default: 'fantasy').")
def init(book_name, primary_language, alternate_languages, author, genre):
"""Initialize the book structure with relevant configuration."""
@click.option("--behavior", help="Behavior content, either as a string or a path to a file.")
def init(book_name, primary_language, alternate_languages, author, genre, behavior):
"""Initialize the book structure with relevant configuration and behavior content."""
if not is_initialized(book_name):
alternate_languages_list = [lang.strip() for lang in alternate_languages.split(',')] if alternate_languages else []
init_structure(book_name, primary_language, alternate_languages_list, author, genre)

# Verificamos si el contenido de behavior es un archivo o un string directo
if os.path.isfile(behavior):
with open(behavior, 'r') as f:
behavior_content = f.read()
else:
behavior_content = behavior # Si no es un archivo, asumimos que es un string

init_structure(book_name, primary_language, alternate_languages_list, author, genre, behavior_content)
else:
console.print(f"[bold yellow]⚠[/bold yellow] Project '[bold]{book_name}[/bold]' is already initialized.", style="yellow")

Expand Down

0 comments on commit 4671d8e

Please sign in to comment.