Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7ce823a

Browse files
committed
feat(llm): add token usage tracking with event system
- Add TokenUsageEvent data class and TokenUsageListener interface- Make Usage data class serializable for event transmission- Standardize topic naming convention across message bus topics- Include session tracking and notification helper for token usage events
1 parentafbe257 commit7ce823a

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
packagecc.unitmesh.devti.llm2
2+
3+
importcc.unitmesh.devti.llms.custom.Usage
4+
importcom.intellij.util.messages.Topic
5+
importkotlinx.serialization.Serializable
6+
7+
/**
8+
* Token usage event data that will be sent when SSE stream finishes
9+
*/
10+
@Serializable
11+
data classTokenUsageEvent(
12+
valusage:Usage,
13+
valmodel:String? =null,
14+
valsessionId:String? =null,
15+
valtimestamp:Long =System.currentTimeMillis()
16+
)
17+
18+
/**
19+
* Listener interface for token usage events
20+
*/
21+
interfaceTokenUsageListener {
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+
funonTokenUsage(event:TokenUsageEvent)
28+
29+
companionobject {
30+
valTOPIC=Topic.create("autodev.llm.token.usage",TokenUsageListener::class.java)
31+
32+
/**
33+
* Notify all subscribers about token usage
34+
*/
35+
funnotify(event:TokenUsageEvent) {
36+
com.intellij.openapi.application.ApplicationManager.getApplication().messageBus
37+
.syncPublisher(TOPIC)
38+
.onTokenUsage(event)
39+
}
40+
}
41+
}

‎core/src/main/kotlin/cc/unitmesh/devti/llms/custom/OpenAIDto.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonAlias
44
importcom.fasterxml.jackson.annotation.JsonInclude
55
importcom.fasterxml.jackson.annotation.JsonProperty
66
importcom.fasterxml.jackson.databind.JsonNode
7+
importkotlinx.serialization.Serializable
78

89
data classChatFunctionCall(
910
valname:String? =null,
@@ -27,6 +28,7 @@ data class ChatCompletionChoice(
2728
valfinishReason:String? =null,
2829
)
2930

31+
@Serializable
3032
data classUsage(
3133
@JsonProperty("prompt_tokens")
3234
valpromptTokens:Long =0,

‎core/src/main/kotlin/cc/unitmesh/devti/mcp/ui/McpConfigService.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface SketchConfigListener {
1919
funonSelectedToolsChanged(tools:Map<String,Set<Tool>>)
2020

2121
companionobject {
22-
valTOPIC=Topic.create("SketchConfigChanged",SketchConfigListener::class.java)
22+
valTOPIC=Topic.create("autodev.sketch.configChanged",SketchConfigListener::class.java)
2323
}
2424
}
2525

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp