feat: Implement a goose run command (#121)

This commit is contained in:
Bradley Axen
2024-10-08 10:31:47 -07:00
committed by GitHub
parent f3aab127e5
commit 0d1808d005
2 changed files with 41 additions and 0 deletions
+16
View File
@@ -171,6 +171,22 @@ def session_resume(name: Optional[str], profile: str, log_level: str) -> None:
session.run()
@goose_cli.command(name="run")
@click.argument("message_file", required=False, type=click.Path(exists=True))
@click.option("--profile")
@click.option("--log-level", type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]), default="INFO")
def run(message_file: Optional[str], profile: str, log_level: str) -> None:
"""Run a single-pass session with a message from a markdown input file"""
if message_file:
with open(message_file, "r") as f:
initial_message = f.read()
else:
initial_message = click.get_text_stream("stdin").read()
session = Session(profile=profile, log_level=log_level)
session.single_pass(initial_message=initial_message)
@session.command(name="list")
def session_list() -> None:
"""List goose sessions"""
+25
View File
@@ -121,6 +121,31 @@ class Session:
return Message.user(text=user_input.text)
return self.exchange.messages.pop()
def single_pass(self, initial_message: str) -> None:
"""
Handles a single input message and processes a reply
without entering a loop for additional inputs.
Args:
initial_message (str): The initial user message to process.
"""
profile = self.profile_name or "default"
print(f"[dim]starting session | name:[cyan]{self.name}[/] profile:[cyan]{profile}[/]")
print(f"[dim]saving to {self.session_file_path}")
print()
# Process initial message
message = Message.user(initial_message)
self.exchange.add(message)
self.reply() # Process the user message
save_latest_session(self.session_file_path, self.exchange.messages)
print() # Print a newline for separation.
print(f"[dim]ended run | name:[cyan]{self.name}[/] profile:[cyan]{profile}[/]")
print(f"[dim]to resume: [magenta]goose session resume {self.name} --profile {profile}[/][/]")
def run(self) -> None:
"""
Runs the main loop to handle user inputs and responses.