mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Track session context usage
This commit is contained in:
5 files changed
+136
-8
No files matched your search
@@ -160,6 +160,19 @@ export function useAIChat({
|
||||
}
|
||||
}, [sessionId, sessionManager]);
|
||||
|
||||
useSessionSubscription('contextUsageUpdated', (updatedSessionId: string, _inputTokens: number) => {
|
||||
if (updatedSessionId === sessionId) {
|
||||
const session = sessionManager.getSession(sessionId);
|
||||
if (session) {
|
||||
setSessionState({
|
||||
...session,
|
||||
messages: [...session.messages],
|
||||
streamingMessage: session.streamingMessage ? { ...session.streamingMessage } : undefined
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [sessionId, sessionManager]);
|
||||
|
||||
|
||||
|
||||
// Derived state
|
||||
@@ -167,6 +180,7 @@ export function useAIChat({
|
||||
const streamingMessage: StreamingMessage | undefined = sessionState?.streamingMessage;
|
||||
const isLoading = sessionState?.isLoading || false;
|
||||
const totalCost = sessionState?.totalCost || 0;
|
||||
const lastInputTokens = sessionState?.lastInputTokens || 0;
|
||||
|
||||
// Actions
|
||||
const sendMessage = useCallback(async (content: string, providerModel: string) => {
|
||||
@@ -217,6 +231,7 @@ export function useAIChat({
|
||||
streamingMessage,
|
||||
isLoading,
|
||||
totalCost,
|
||||
lastInputTokens,
|
||||
sendMessage,
|
||||
startGeneration,
|
||||
stopGeneration,
|
||||
|
||||
@@ -10,7 +10,7 @@ interface ProviderModel {
|
||||
provider: string;
|
||||
fullId: string; // provider/model format
|
||||
/** Maximum size of context window, if available */
|
||||
context_length?: number;
|
||||
contextLength?: number;
|
||||
/** Pricing information, if available */
|
||||
pricing?: {
|
||||
/** Input/prompt pricing per token */
|
||||
@@ -68,7 +68,7 @@ export function useProviderModels(): ModelFetchResult {
|
||||
};
|
||||
|
||||
if ('context_length' in model && typeof model.context_length === 'number') {
|
||||
providerModel.context_length = model.context_length;
|
||||
providerModel.contextLength = model.context_length;
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
Reference in new issue
Block a user