Skip to content

Commit

Permalink
fix: prevent sending too many trace url
Browse files Browse the repository at this point in the history
  • Loading branch information
634750802 committed May 27, 2024
1 parent dbdfd8d commit 0252769
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/core/services/chating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type Chat, type ChatMessage, createChatMessage, createChatMessageRetrie
import { AppIndexBaseService } from '@/core/services/base';
import { AppChatStream, type AppChatStreamSource, AppChatStreamState } from '@/lib/ai/AppChatStream';
import { AUTH_FORBIDDEN_ERROR, getErrorMessage } from '@/lib/errors';
import {LangfuseTraceClient} from "langfuse";
import { LangfuseTraceClient } from 'langfuse';
import { notFound } from 'next/navigation';

export type ChatOptions = {
Expand Down Expand Up @@ -63,11 +63,11 @@ export abstract class AppChatService extends AppIndexBaseService {
}

if (message.role !== 'assistant') {
throw new Error('Can only regenerate assistant messages.')
throw new Error('Can only regenerate assistant messages.');
}

await deleteChatMessages(chat.id, message.ordinal, 'REGENERATE');
})
});
}

private async getSessionInfo (sessionId: string, userId: string) {
Expand Down
3 changes: 0 additions & 3 deletions src/core/services/llamaindex/chating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ export class LlamaindexChatService extends AppChatService {

yield {
status: AppChatStreamState.KG_RETRIEVING,
traceURL: trace?.getTraceUrl(),
sources: Array.from(allSources.values()),
statusMessage: 'Start knowledge graph searching ...',
content: '',
Expand Down Expand Up @@ -194,7 +193,6 @@ export class LlamaindexChatService extends AppChatService {

yield {
status: AppChatStreamState.KG_RETRIEVING,
traceURL: trace?.getTraceUrl(),
sources: Array.from(allSources.values()),
statusMessage: 'Knowledge graph retrieving completed.',
content: '',
Expand Down Expand Up @@ -341,7 +339,6 @@ export class LlamaindexChatService extends AppChatService {
status: AppChatStreamState.GENERATING,
statusMessage: `Generating using ${llmConfig.provider}:${llmConfig.options?.model ?? 'default'}`,
sources: Array.from(allSources.values()),
traceURL: trace?.getTraceUrl(),
retrieveId: undefined,
};
}),
Expand Down
12 changes: 7 additions & 5 deletions src/lib/ai/AppChatStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ export class AppChatStreamController {
}

setTraceURL (traceURL: string | undefined) {
this.encodeMessageAnnotation({
ts: Date.now(),
traceURL,
messageId: this.messageId,
});
if (traceURL) {
this.encodeMessageAnnotation({
ts: Date.now(),
traceURL,
messageId: this.messageId,
});
}
}

private encodeText (text: string) {
Expand Down

0 comments on commit 0252769

Please sign in to comment.