Skip to content

Commit

Permalink
feat(chat): integrate prompt_toolkit for advanced input handling and …
Browse files Browse the repository at this point in the history
…rich for output formatting

- Added prompt_toolkit PromptSession to handle multi-line input, history, and cursor movement.
- Integrated rich for rendering Markdown and colorized output.
- Adjusted input processing to pass user queries to the assistant via create_message.
- Ensured the output is displayed using rich's console.print for proper formatting.
- Included error handling for invalid commands and exceptions during execution.
  • Loading branch information
Estrada Irribarra, Rodrigo Andres committed Oct 23, 2024
1 parent c299820 commit e45694f
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion storycraftr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def load_openai_api_key():
from storycraftr.cmd.publish import publish
from storycraftr.cmd.chat import chat
from storycraftr.templates.tex import TEMPLATE_TEX
from storycraftr.agent.agents import create_or_get_assistant
from storycraftr.agent.agents import create_or_get_assistant, update_agent_files
from storycraftr.utils.core import load_book_config


def download_file(url, save_dir, filename):
Expand Down Expand Up @@ -257,7 +258,32 @@ def init(
console.print(f"[yellow]Project '{book_path}' is already initialized.[/yellow]")


@click.command()
@click.option(
"--book-path", type=click.Path(), help="Path to the book directory", required=False
)
def reload_files(book_path):
"""
Reloads the agent files for the given book path.
Args:
book_path (str): Path to the book project.
"""
book_path = book_path or os.getcwd()
if not load_book_config(book_path):
return
if is_initialized(book_path):
assistant = create_or_get_assistant(book_path)
update_agent_files(book_path, assistant)
console.print(
f"[green]Agent files reloaded successfully for project: {book_path}[/green]"
)
else:
project_not_initialized_error(book_path)


cli.add_command(init)
cli.add_command(reload_files)
cli.add_command(outline)
cli.add_command(worldbuilding)
cli.add_command(chapters)
Expand Down

0 comments on commit e45694f

Please sign in to comment.