Skip to content

Commit

Permalink
fix: promptContext crash #1420 (#1422)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikbry authored Dec 16, 2024
1 parent c42caf1 commit 30c62c3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
14 changes: 8 additions & 6 deletions webapp/features/Threads/Prompt/PromptContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ function PromptProvider({
);
if (text && text.length > 0) {
const response = await tokenize(activeService, text);
updateUsage({
conversationId: selectedConversation?.id,
text,
tokenCount: response?.tokens.length || 0,
activeService,
});
if (response) {
updateUsage({
conversationId: selectedConversation?.id,
text,
tokenCount: response?.tokens.length || 0,
activeService,
});
}
} else {
updateUsage({
conversationId: selectedConversation?.id,
Expand Down
20 changes: 11 additions & 9 deletions webapp/utils/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,24 @@ import { CommandManager } from '../commands/types';
import { invokeTauri } from '../backend/tauri';
import { mapKeys } from '../data';
import { /* toCamelCase, */ toCamelCase, toSnakeCase } from '../string';
// import logger from '../logger';
import logger from '../logger';

export const tokenize = async (
activeService: AIImplService,
text: string,
): Promise<LlmTokenizeResponse | undefined> => {
const { provider, model } = activeService;
let response: LlmTokenizeResponse;
let response: LlmTokenizeResponse | undefined;
if (model && provider) {
response = await invokeTauri<LlmTokenizeResponse>('llm_call_tokenize', {
model: model.name,
provider: mapKeys(provider, toSnakeCase),
text,
});
} else {
return undefined;
try {
response = await invokeTauri<LlmTokenizeResponse>('llm_call_tokenize', {
model: model.name,
provider: mapKeys(provider, toSnakeCase),
text,
});
} catch (e) {
logger.error('tokenizer: ', e);
}
}
return response;
};
Expand Down

0 comments on commit 30c62c3

Please sign in to comment.