Skip to content

Commit

Permalink
small nits
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelneale committed Sep 4, 2024
1 parent 7028fee commit 72ada47
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions src/goose/cli/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
"Tell goose how to run tests so it can verify any changes. eg 'please run make test to verify any changes'",
"Tell goose if you have any developer docs like CONTRIBUTING.md so it can learn how to build and help you.",
"Goose likes to know what programming language you are working in to get started.",
"You can ask goose to confirm commands with you if you like.",
"Try this: 'In this golang project, I want you to add open telemetry to help me get started with it. run the `just test` command to check things work.'",
"If you are working in a git repo, you can stage and commit changes (or ask goose to) as you go to not loose any work.",
"You can ask goose to confirm commands with you before running them.",
"Try this: 'In this golang project, I want you to add open telemetry to get started. run the `just test` command to check things work.'",
"If you're working in a git repo, you can stage and commit changes (or ask goose to) as you go to not lose any work.",
"You can ask goose to try almost any task, it likes to write and execute scripts as well as help you sort out your environment.",
"Tell goose what directories you want to work in (this can be your main directory, but you can tell it to look elsewhere it needs to)",
"Tell goose which directories to work in (this can be the main directory, but you can specify others if needed.)",
"With the screen toolkit, goose can look at your screen and help you make visual changes.",
"You can run more than one goose at a time (in different terminals or IDEs).",
"Ask goose to write a unit test for some code and check it works.",
"Ask goose to add some new feature or function by telling it to look at similar existing functionality.",
"You can use goose to analyse data as well, it can write scripts and evaluate them against your data.",
"Ask goose to recommend a tool to use, and it can offer to install it as well.",
"Ask goose to add a new feature or function by checking similar existing functionality.",
"You can use goose to analyze data; it can write and evaluate scripts against your data.",
"Ask goose to recommend a tool to use, and it can offer to install it as well.",
"Start by asking goose to run your tests for you and it will report back.",
"If you have broken tests, ask goose to help you either fix the tests or the broken code (tell it how to run the tests first)"
"If you have broken tests, ask goose to help you fix either the tests or the broken code (tell it how to run the tests first)"
]


Expand Down Expand Up @@ -144,7 +144,6 @@ def __init__(

self.prompt_session = GoosePromptSession.create_prompt_session()


def setup_plan(self, plan: dict) -> None:
if len(self.exchange.messages):
raise ValueError("The plan can only be set on an empty session.")
Expand Down Expand Up @@ -182,21 +181,19 @@ def run(self) -> None:
print(traceback.format_exc())
if self.exchange.messages:
self.exchange.messages.pop()
print(
"\n[red]The error above was an exception we were not able to handle.\n\n[/]"
print("\n[red]The error above was an exception we were not able to handle.\n\n[/]"
+ "These errors are often related to connection or authentication\n"
+ "We've removed your most recent input"
+ " - [yellow]depending on the error you may be able to continue[/]"
)

+ " - [yellow]depending on the error you may be able to continue[/]")
print() # Print a newline for separation.
user_input = self.prompt_session.get_user_input()
message = Message.user(text=user_input.text) if user_input.to_continue() else None

self.save_session()

def reply(self) -> None:
"""Reply to the last user message, calling tools as needed
"""
Reply to the last user message, calling tools as needed
Args:
text (str): The text input from the user.
Expand All @@ -220,7 +217,7 @@ def reply(self) -> None:
print(Markdown(response.text))

def interrupt_reply(self) -> None:
"""Recover from an interruption at an arbitrary state"""
"Recover from an interruption at an arbitrary state"
# Default recovery message if no user message is pending.
recovery = "We interrupted before the next processing started."
if self.exchange.messages and self.exchange.messages[-1].role == "user":
Expand All @@ -234,17 +231,17 @@ def interrupt_reply(self) -> None:
and self.exchange.messages[-1].tool_use
):
content = []
# Append tool results as errors if interrupted.
# Append tool results/errors if interrupted.
for tool_use in self.exchange.messages[-1].tool_use:
content.append(
ToolResult(
tool_use_id=tool_use.id,
output="Interrupted by the user to make a correction",
output="Interrupted by the user to correct",
is_error=True,
)
)
self.exchange.add(Message(role="user", content=content))
recovery = f"We interrupted the existing call to {tool_use.name}. How would you like to proceed?"
recovery = f"We interrupted the call to {tool_use.name}. How to proceed?"
self.exchange.add(Message.assistant(recovery))
# Print the recovery message with markup for visibility.
print(f"[yellow]{recovery}[/]")
Expand All @@ -257,7 +254,6 @@ def save_session(self) -> None:
"""Save the current session to a file in JSON format."""
if self.name is None:
self.generate_session_name()

try:
if self.session_file_path.exists():
if not confirm(f"Session {self.name} exists in {self.session_file_path}, overwrite?"):
Expand All @@ -269,14 +265,13 @@ def save_session(self) -> None:
raise RuntimeError(f"Failed to save session due to I/O error: {e}")

def load_session(self) -> List[Message]:
"""Load a session from a JSON file."""
"Load a session from a JSON file."
return read_from_file(self.session_file_path)

def generate_session_name(self) -> None:
user_entered_session_name = self.prompt_session.get_save_session_name()
self.name = user_entered_session_name if user_entered_session_name else droid()
print(f"Saving to [bold cyan]{self.session_file_path}[/bold cyan]")

user_entered = self.prompt_session.get_save_session_name()
self.name = user_entered if user_entered else droid()
print(f"Saving to [bold cyan]{self.session_file_path}[bold cyan]")

if __name__ == "__main__":
session = Session()
session = Session()

0 comments on commit 72ada47

Please sign in to comment.