Skip to content

Commit

Permalink
feat: Add new conversation command
Browse files Browse the repository at this point in the history
  • Loading branch information
fmueller committed Jun 2, 2024
1 parent fd83da1 commit eddce12
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ class HelpCommand : SlashCommand {
conversation.addMessage(
Message(
Role.ASSISTANT,
"I'm Jarvis, your personal coding assistant. You can ask me anything. To make me work properly," +
" please install and run Ollama locally."
"""
I'm Jarvis, your personal coding assistant. You can ask me anything. To make me work properly, please install and run Ollama locally.
Available commands:
- ```/help``` or ```/?``` - Shows this help message
- ```/new``` - Starts a new conversation
""".trimIndent()
)
)
return conversation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.fmueller.jarvis.commands

import com.github.fmueller.jarvis.conversation.Conversation

class NewConversationCommand : SlashCommand {

// as long as we don't have multiple conversations
// we can just clear the messages
override suspend fun run(conversation: Conversation): Conversation {
conversation.clearMessages()
return conversation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class SlashCommandParser(private val ollamaService: OllamaService) {
return HelpCommand()
}

if (trimmedMessage == "/new") {
return NewConversationCommand()
}

return ChatCommand(ollamaService)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class Conversation(ollamaService: OllamaService) {
propertyChangeSupport.firePropertyChange("messages", oldMessages, ArrayList(_messages))
}

fun clearMessages() {
val oldMessages = ArrayList(_messages)
_messages.clear()
_messages.add(Message(Role.ASSISTANT, "Hello! How can I help you?"))
propertyChangeSupport.firePropertyChange("messages", oldMessages, ArrayList(_messages))
}

fun addPropertyChangeListener(listener: PropertyChangeListener) {
propertyChangeSupport.addPropertyChangeListener(listener)
}
Expand Down

0 comments on commit eddce12

Please sign in to comment.