-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add /chats/stats to display usage estimate
- Loading branch information
Showing
4 changed files
with
39 additions
and
3 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
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
28 changes: 28 additions & 0 deletions
28
interweb-server/src/main/java/de/l3s/interweb/server/features/chat/ChatsStats.java
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,28 @@ | ||
package de.l3s.interweb.server.features.chat; | ||
|
||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import de.l3s.interweb.server.features.user.ApiKey; | ||
|
||
@RegisterForReflection | ||
public class ChatsStats { | ||
@JsonProperty("used_tokens") | ||
public Long usedTokens; | ||
@JsonProperty("estimated_cost") | ||
public Double estimatedCost; | ||
@JsonProperty("total_chats") | ||
public Long totalChats; | ||
|
||
public ChatsStats(Long usedTokens, Double estimatedCost, Long totalChats) { | ||
this.usedTokens = usedTokens; | ||
this.estimatedCost = estimatedCost; | ||
this.totalChats = totalChats; | ||
} | ||
|
||
public static Uni<ChatsStats> findByApikey(ApiKey apikey) { | ||
return Chat.find("select sum(usedTokens) as usedTokens, sum(estimatedCost) as estimatedCost, count(*) as totalChats from Chat where apikey.id = ?1", apikey.id).project(ChatsStats.class).singleResult(); | ||
} | ||
} |