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.
Add conversation class and json parsing for llm responses
- Loading branch information
Showing
4 changed files
with
74 additions
and
18 deletions.
There are no files selected for viewing
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
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/com/github/fmueller/jarvis/conversation/Conversation.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,29 @@ | ||
package com.github.fmueller.jarvis.conversation | ||
|
||
import java.beans.PropertyChangeListener | ||
import java.beans.PropertyChangeSupport | ||
import java.time.LocalDateTime | ||
|
||
enum class Role { | ||
ASSISTANT, USER | ||
} | ||
|
||
data class Message(val role: Role, val content: String, val createdAt: LocalDateTime = LocalDateTime.now()) | ||
|
||
class Conversation { | ||
|
||
private val messages = mutableListOf<Message>() | ||
private val propertyChangeSupport = PropertyChangeSupport(this) | ||
|
||
fun addMessage(message: Message) { | ||
val oldMessages = ArrayList(messages) | ||
messages.add(message) | ||
propertyChangeSupport.firePropertyChange("message", oldMessages, ArrayList(messages)) | ||
} | ||
|
||
fun getMessages() = messages.toList() | ||
|
||
fun addPropertyChangeListener(listener: PropertyChangeListener) { | ||
propertyChangeSupport.addPropertyChangeListener(listener) | ||
} | ||
} |
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
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