Skip to content

Commit

Permalink
feat: adds interactive chat for copilot analysis as well
Browse files Browse the repository at this point in the history
  • Loading branch information
1x-eng committed Nov 5, 2024
1 parent 4a1398e commit 0bbc761
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 7 deletions.
9 changes: 9 additions & 0 deletions pkg/llm/assistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,12 @@ func (a *Assistant) StartSuggestionChat(suggestions []string, lastAnalysis strin
lastAnalysis,
)
}

func (a *Assistant) StartAnalysisChat(analysis string) *SuggestionChat {
return NewSuggestionChat(
a,
a.context,
[]string{}, // No suggestions needed for analysis chat
analysis, // Use the analysis as the last analysis
)
}
33 changes: 29 additions & 4 deletions pkg/llm/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func (sc *SuggestionChat) Chat(userInput string) (string, error) {
Content: userInput,
})

systemPrompt := `You are an advanced task optimization assistant engaged in a discussion about specific task suggestions. Your core responsibilities:
var systemPrompt string
if len(sc.suggestions) > 0 {
systemPrompt = `You are an advanced task optimization assistant engaged in a discussion about specific task suggestions. Your core responsibilities:
CONTEXT AWARENESS:
- Maintain strict relevance to the session context and current suggestions
Expand All @@ -42,14 +44,33 @@ SUGGESTION CLARIFICATION:
- Break down complex tasks into clear, achievable steps
- Highlight dependencies and prerequisites
- Explain the reasoning behind each suggestion
- Focus on practical implementation details
- Focus on practical implementation details`
} else {
systemPrompt = `You are an advanced performance analysis assistant engaged in a discussion about the session analysis. Your core responsibilities:
ANALYSIS CLARIFICATION:
- Provide detailed explanations of analysis points
- Explain the reasoning behind observations
- Offer concrete examples and evidence
- Address user questions and concerns
- Maintain focus on performance optimization
FEEDBACK PROCESSING:
- Accept and process user feedback
- Adjust analysis based on new information
- Provide alternative perspectives when needed
- Help users understand performance patterns
- Guide towards actionable improvements`
}

systemPrompt += `
RESPONSE GUIDELINES:
1. If question is relevant:
- Provide clear, structured response
- Include specific steps or clarifications
- Include specific details and clarifications
- Reference context when applicable
- Maintain focus on task completion
- Maintain focus on improvement
2. If question seems off-topic:
- Politely flag the digression
Expand All @@ -72,11 +93,15 @@ Current Session Context:
"""
%s
"""
`

if len(sc.suggestions) > 0 {
systemPrompt += `
Current Suggestions Under Discussion:
"""
%s
"""`
}

messages := []Message{
{
Expand Down
90 changes: 87 additions & 3 deletions pkg/pomodoro/pom.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,24 @@ func (p *TomatickMemento) runTomatickMementoCycle() {
formattedAnalysis := presenter.Present(analysis)
fmt.Println(formattedAnalysis)

// Keep prompting until user is ready
p.lastAnalysis = analysis

if analysis != "" {
prompt := &survey.Confirm{
Message: p.theme.Styles.Break.Render("Would you like to discuss this analysis with your copilot?"),
Default: true,
}
var discussAnalysis bool
survey.AskOne(prompt, &discussAnalysis)

if discussAnalysis {
assistant := llm.NewAssistant(p.llmClient, p.sessionContext)
analysisChat := assistant.StartAnalysisChat(analysis)
p.handleAnalysisChat(analysisChat)
}
}

// Keep prompting until user is ready - taking a break is important to avoid burnout
for {
prompt := &survey.Confirm{
Message: p.theme.Styles.Break.Render("Ready for your break?"),
Expand All @@ -213,8 +230,6 @@ func (p *TomatickMemento) runTomatickMementoCycle() {
fmt.Println(p.theme.Styles.Break.Render("\nTake your time to review the analysis. Press Y when ready to continue."))
}
}

p.lastAnalysis = analysis
}

cycleSummary := markdown.FormatCycleSummary(completedTasks, reflections)
Expand Down Expand Up @@ -698,3 +713,72 @@ func (p *TomatickMemento) handleSuggestionChat() {
fmt.Println(p.theme.Styles.ChatDivider.Render(strings.Repeat("─", 50)))
}
}

func (p *TomatickMemento) handleAnalysisChat(chat *llm.SuggestionChat) {
chatBorder := strings.Repeat(p.theme.Emoji.ChatDivider, 50)
fmt.Println(p.theme.Styles.ChatBorder.Render(chatBorder))
fmt.Println(p.theme.Styles.ChatHeader.Render(
fmt.Sprintf("%s Analysis Discussion %s",
p.theme.Emoji.ChatStart,
p.theme.Emoji.Brain)))
fmt.Println(p.theme.Styles.ChatBorder.Render(chatBorder))

fmt.Println(p.theme.Styles.SystemInstruction.Render("\nAsk questions or discuss the analysis (type 'exit' to end chat)"))

scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Printf("%s", p.theme.Styles.ChatPrompt.PaddingTop(0).PaddingBottom(0).Render(p.theme.Emoji.UserInput+" "))

if !scanner.Scan() {
break
}

input := strings.TrimSpace(scanner.Text())
if input == "" {
continue
}

if input == "exit" {
fmt.Println(p.theme.Styles.ChatBorder.Render(chatBorder))
fmt.Println(p.theme.Styles.ChatHeader.Render(
fmt.Sprintf("%s Chat session ended %s",
p.theme.Emoji.ChatEnd,
p.theme.Emoji.Success)))
fmt.Println(p.theme.Styles.ChatBorder.Render(chatBorder))
break
}

spinner := ui.NewSpinner(p.theme.Styles.Spinner.
Foreground(lipgloss.Color("#818CF8")).
Bold(true))
done := make(chan bool)

go func() {
for {
select {
case <-done:
return
default:
fmt.Printf("\r%s Analyzing...", spinner.Next())
time.Sleep(100 * time.Millisecond)
}
}
}()

response, err := chat.Chat(input)
done <- true
fmt.Print("\r\033[K")

if err != nil {
fmt.Println(p.theme.Styles.ErrorText.Render(
fmt.Sprintf("%s Error: %v", p.theme.Emoji.Error, err)))
continue
}

fmt.Println(p.theme.Styles.ChatDivider.Render(strings.Repeat("─", 50)))
fmt.Printf("%s %s\n",
p.theme.Emoji.AIResponse,
p.theme.Styles.AIMessage.Render(response))
fmt.Println(p.theme.Styles.ChatDivider.Render(strings.Repeat("─", 50)))
}
}

0 comments on commit 0bbc761

Please sign in to comment.