File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
core/src/main/kotlin/cc/unitmesh/devti Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change
1
+ package cc.unitmesh.devti.llm2
2
+
3
+ import cc.unitmesh.devti.llms.custom.Usage
4
+ import com.intellij.util.messages.Topic
5
+ import kotlinx.serialization.Serializable
6
+
7
+ /* *
8
+ * Token usage event data that will be sent when SSE stream finishes
9
+ */
10
+ @Serializable
11
+ data class TokenUsageEvent (
12
+ val usage : Usage ,
13
+ val model : String? = null ,
14
+ val sessionId : String? = null ,
15
+ val timestamp : Long = System .currentTimeMillis()
16
+ )
17
+
18
+ /* *
19
+ * Listener interface for token usage events
20
+ */
21
+ interface TokenUsageListener {
22
+ /* *
23
+ * Called when token usage data is available from LLM response
24
+ *
25
+ * @param event The token usage event containing usage statistics
26
+ */
27
+ fun onTokenUsage (event : TokenUsageEvent )
28
+
29
+ companion object {
30
+ val TOPIC = Topic .create(" autodev.llm.token.usage" , TokenUsageListener ::class .java)
31
+
32
+ /* *
33
+ * Notify all subscribers about token usage
34
+ */
35
+ fun notify (event : TokenUsageEvent ) {
36
+ com.intellij.openapi.application.ApplicationManager .getApplication().messageBus
37
+ .syncPublisher(TOPIC )
38
+ .onTokenUsage(event)
39
+ }
40
+ }
41
+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonAlias
4
4
import com.fasterxml.jackson.annotation.JsonInclude
5
5
import com.fasterxml.jackson.annotation.JsonProperty
6
6
import com.fasterxml.jackson.databind.JsonNode
7
+ import kotlinx.serialization.Serializable
7
8
8
9
data class ChatFunctionCall (
9
10
val name : String? = null ,
@@ -27,6 +28,7 @@ data class ChatCompletionChoice(
27
28
val finishReason : String? = null ,
28
29
)
29
30
31
+ @Serializable
30
32
data class Usage (
31
33
@JsonProperty(" prompt_tokens" )
32
34
val promptTokens : Long = 0 ,
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ interface SketchConfigListener {
19
19
fun onSelectedToolsChanged (tools : Map <String , Set <Tool >>)
20
20
21
21
companion object {
22
- val TOPIC = Topic .create(" SketchConfigChanged " , SketchConfigListener ::class .java)
22
+ val TOPIC = Topic .create(" autodev.sketch.configChanged " , SketchConfigListener ::class .java)
23
23
}
24
24
}
25
25
You can’t perform that action at this time.
0 commit comments