This repository was archived by the owner on Sep 29, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +40
-5
lines changed
chatbot-server-mongodb-public/src/tracing
mongodb-chatbot-server/src/routes/conversations Expand file tree Collapse file tree 3 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ export function makeAddMessageToConversationUpdateTrace({
7979 model : analyzerModel ,
8080 } ,
8181 embeddingModelName,
82+ reqId,
8283 } ) ;
8384 await scrubbedMessageStore . insertScrubbedMessages ( {
8485 messages : scrubbedMessages ,
@@ -149,14 +150,25 @@ export function makeAddMessageToConversationUpdateTrace({
149150 }
150151
151152 try {
153+ const judgeScores = shouldJudge
154+ ? await getLlmAsAJudgeScores ( llmAsAJudge , tracingData ) . catch (
155+ ( error ) => {
156+ logRequest ( {
157+ reqId,
158+ message : `Error getting LLM as a judge scores in addMessageToConversationUpdateTrace: ${ error } ` ,
159+ type : "error" ,
160+ } ) ;
161+ return undefined ;
162+ }
163+ )
164+ : undefined ;
165+
152166 braintrustLogger . updateSpan ( {
153167 id : traceId ,
154168 tags : tracingData . tags ,
155169 scores : {
156170 ...getTracingScores ( tracingData , k ) ,
157- ...( shouldJudge
158- ? await getLlmAsAJudgeScores ( llmAsAJudge , tracingData )
159- : undefined ) ,
171+ ...( judgeScores ?? { } ) ,
160172 } ,
161173 metadata : {
162174 authUser : maybeAuthUser ?? null ,
Original file line number Diff line number Diff line change 1+ import { logRequest } from "../../utils" ;
12import { extractTracingData } from "../extractTracingData" ;
23import { analyzeMessage , MessageAnalysis } from "./analyzeMessage" ;
34import { redactPii } from "./redactPii" ;
@@ -8,19 +9,32 @@ export async function makeScrubbedMessagesFromTracingData({
89 tracingData,
910 analysis,
1011 embeddingModelName,
12+ reqId,
1113} : {
1214 tracingData : ReturnType < typeof extractTracingData > ;
1315 analysis ?: {
1416 model : LanguageModel ;
1517 } ;
1618 embeddingModelName : string ;
19+ reqId : string ;
1720} ) : Promise < ScrubbedMessage < MessageAnalysis > [ ] > {
1821 const { userMessage, assistantMessage } = tracingData ;
1922
20- // User message scrubbing
2123 const userAnalysis = analysis
22- ? await analyzeMessage ( userMessage . content , analysis . model )
24+ ? await analyzeMessage ( userMessage . content , analysis . model ) . catch (
25+ ( error ) => {
26+ logRequest ( {
27+ reqId,
28+ message : `Error analyzing scrubbed user message in tracing: ${ JSON . stringify (
29+ error
30+ ) } `,
31+ type : "error" ,
32+ } ) ;
33+ return undefined ;
34+ }
35+ )
2336 : undefined ;
37+
2438 const { redactedText : redactedUserContent , piiFound : userMessagePii } =
2539 redactPii ( userMessage . content ) ;
2640
Original file line number Diff line number Diff line change 11import { Conversation , ConversationsService } from "mongodb-rag-core" ;
22import { ObjectId } from "mongodb-rag-core/mongodb" ;
3+ import { logRequest } from "../../utils" ;
34
45export type UpdateTraceFuncParams = {
56 reqId : string ;
@@ -32,6 +33,14 @@ export async function updateTraceIfExists({
3233 reqId,
3334 traceId : assistantResponseMessageId . toHexString ( ) ,
3435 conversation : updatedConversationForTrace ,
36+ } ) . catch ( ( error ) => {
37+ logRequest ( {
38+ reqId,
39+ type : "error" ,
40+ message : `Failed to update trace with Error: ${ JSON . stringify (
41+ error
42+ ) } `,
43+ } ) ;
3544 } ) ;
3645 }
3746 }
You can’t perform that action at this time.
0 commit comments