Skip to content

Minor refactor, simplified how "interactive" mode works #48

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

phillmv
Copy link
Member

@phillmv phillmv commented May 22, 2025

What?

This PR:

  • Cleans up how the initialPrompt var was used to be more straightforward, instead of resetting the variable to an empty string and using that as a kind of way of tracking state.
  • Tidies up the "chat for loop" so it just calls a function
  • Most significantly afaict "singleShot" actually just meant "active the chat interface" so I renamed it to interactiveMode.

Why?

I'm using this extension to teach myself some LLM-oriented workflows. I'm writing little shell scripts to have an AI companion in my CLI, and trying to figure out how to get the LLM to do most of the heavy lifting. I am thinking of proposing & then implementing some additional features to this extension (i.e. I think I might want to be able to pipe context in and have an interactive mode).

Ahead of those proposals, and to flex a little with LLMs, I decided to do some light refactoring. I like to keep my PRs small and bite-sized, so apologies if I create a few of these just tidying things up.

@Copilot Copilot AI review requested due to automatic review settings May 22, 2025 02:13
@phillmv phillmv requested a review from a team as a code owner May 22, 2025 02:13
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR streamlines the interactive chat flow by replacing the singleShot flag with a clearer interactiveMode boolean, refactors the prompt loop into a ChatWithUser helper, and updates tests to match the new behavior.

  • Renamed and inverted singleShot logic to interactiveMode
  • Extracted inline chat prompt loop into ChatWithUser
  • Updated tests to expect two messages instead of three

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
cmd/run/run_test.go Adjusted test assertions to expect 2 messages after initial-prompt refactoring
cmd/run/run.go Introduced interactiveMode, simplified prompt/file templating logic, and added ChatWithUser
Comments suppressed due to low confidence (2)

cmd/run/run.go:295

  • [nitpick] The variable pf is ambiguous; consider renaming it to promptFile or promptConfig for clarity.
if pf == nil {

cmd/run/run.go:576

  • The new ChatWithUser helper contains its own I/O and command parsing logic but lacks direct unit tests; consider adding tests to validate prompt handling and command responses.
func (h *runCommandHandler) ChatWithUser(conversation Conversation, mp ModelParameters) (Conversation, error) {

@@ -139,7 +139,7 @@ messages:
_, err = runCmd.ExecuteC()
require.NoError(t, err)

require.Equal(t, 3, len(capturedReq.Messages))
require.Equal(t, 2, len(capturedReq.Messages))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most sus change in the whole PR, but I think it's because I fixed a bug. I checked out the version in the main branch, with 3 messages, and added some code to print the Messages out. This is what I got back:

=== RUN   TestRun/--file_pre-loads_YAML_from_file
Message 1:
  Content: You are a text summarizer.
  Role: system
Message 2:
  Content: Hello there!
  Role: user
Message 3:
  Content:
  Role: user

i.e. the third and final message was simply empty. So, I sheepishly just decremented this number.

Copy link
Member

@cheshire137 cheshire137 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! I'd be interested in @sgoedecke or another Models reviewer looking this over, as my Go skills are fair to middling. Thank you for working on the extension!


func (h *runCommandHandler) ChatWithUser(conversation Conversation, mp ModelParameters) (Conversation, error) {
fmt.Printf(">>> ")
reader := bufio.NewReader(os.Stdin)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bufio

image of bufo the frog

@phillmv
Copy link
Member Author

phillmv commented May 22, 2025

Thanks! I'll avoid merging til @sgoedecke has had a chance to have a looksee 😄.

Co-authored-by: Sarah Vessels <cheshire137@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy