Skip to content

Commit 79b736c

Browse files
committed
also display consumption in middle of the tool-calling process
1 parent 9b9b887 commit 79b736c

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

frontend/src/views/Chat.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export default {
160160
},
161161
] as LLMMessageContentPart[],
162162
outputStreamRole: Role.Bot,
163+
runningAskingConsumption: {} as HistoryEntryConsumption,
163164
error: null as { title: string; message: string } | null,
164165
userScroll: false,
165166
minimized: false,
@@ -201,7 +202,9 @@ export default {
201202
return result
202203
},
203204
totalChatConsumption(): HistoryEntryConsumption | null {
204-
let result = {} as HistoryEntryConsumption
205+
let result = {
206+
...this.runningAskingConsumption
207+
} as HistoryEntryConsumption
205208
206209
for (let msg of this.chatHistory) {
207210
if(msg.Consumption === undefined){
@@ -298,6 +301,7 @@ export default {
298301
this.progress = true
299302
this.error = null
300303
this.userScroll = false
304+
this.runningAskingConsumption = {}
301305
302306
const setInput = () => {
303307
this.pushHistory({
@@ -353,6 +357,7 @@ export default {
353357
} finally {
354358
this.progress = false
355359
this.outputStream[0].Content = ''
360+
this.runningAskingConsumption = {}
356361
}
357362
},
358363
async onSubmit(input: ChatInputType) {
@@ -393,6 +398,9 @@ export default {
393398
EventsOn('llm:message:update', (message: LLMMessage) => {
394399
this.updateHistoryMessage(message)
395400
})
401+
EventsOn('llm:consumption:update', (consumption: HistoryEntryConsumption) => {
402+
this.runningAskingConsumption = consumption
403+
})
396404
EventsOn('system:restart', () => {
397405
// backend requested a restart
398406
// so we have to save the current state and restart the app

internal/controller/llm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ func (c *Controller) LLMAsk(args LLMAskArgs) (result LLMAskResult, err error) {
225225
}
226226

227227
consumption.Add(c.aiModel.ConsumptionOf(resp))
228+
RuntimeEventsEmit(c.ctx, EventNameLLMConsumptionUpdate, consumption.Summary())
228229

229230
tcMessage, err := c.handleToolCall(resp)
230231
if err != nil {

internal/controller/llm_tool.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import (
1515
)
1616

1717
const (
18-
EventNameLLMMessageAdd = "llm:message:add"
19-
EventNameLLMMessageUpdate = "llm:message:update"
18+
EventNameLLMMessageAdd = "llm:message:add"
19+
EventNameLLMMessageUpdate = "llm:message:update"
20+
EventNameLLMConsumptionUpdate = "llm:consumption:update"
2021
)
2122

2223
func (c *Controller) handleToolCall(resp *llms.ContentResponse) (result LLMMessages, err error) {

0 commit comments

Comments
 (0)