generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/github/fmueller/jarvis/commands/ChatCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.github.fmueller.jarvis.commands | ||
|
||
import com.github.fmueller.jarvis.ai.OllamaService | ||
import com.github.fmueller.jarvis.conversation.Conversation | ||
import com.github.fmueller.jarvis.conversation.Message | ||
import com.github.fmueller.jarvis.conversation.Role | ||
|
||
class ChatCommand(private val ollamaService: OllamaService) : SlashCommand { | ||
|
||
override suspend fun run(conversation: Conversation): Conversation { | ||
val response = ollamaService.chat(conversation.messages).trim() | ||
conversation.addMessage(Message(Role.ASSISTANT, response)) | ||
return conversation | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/github/fmueller/jarvis/commands/HelpCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.fmueller.jarvis.commands | ||
|
||
import com.github.fmueller.jarvis.conversation.Conversation | ||
import com.github.fmueller.jarvis.conversation.Message | ||
import com.github.fmueller.jarvis.conversation.Role | ||
|
||
class HelpCommand : SlashCommand { | ||
|
||
override suspend fun run(conversation: Conversation): Conversation { | ||
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." | ||
) | ||
) | ||
return conversation | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/github/fmueller/jarvis/commands/SlashCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.github.fmueller.jarvis.commands | ||
|
||
import com.github.fmueller.jarvis.conversation.Conversation | ||
|
||
interface SlashCommand { | ||
|
||
suspend fun run(conversation: Conversation): Conversation | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/github/fmueller/jarvis/commands/SlashCommandParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.github.fmueller.jarvis.commands | ||
|
||
import com.github.fmueller.jarvis.ai.OllamaService | ||
|
||
class SlashCommandParser(private val ollamaService: OllamaService) { | ||
|
||
fun parse(message: String): SlashCommand { | ||
val trimmedMessage = message.trim().lowercase() | ||
if (trimmedMessage == "/help" || trimmedMessage == "/?") { | ||
return HelpCommand() | ||
} | ||
|
||
return ChatCommand(ollamaService) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters