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({
79
79
model : analyzerModel ,
80
80
} ,
81
81
embeddingModelName,
82
+ reqId,
82
83
} ) ;
83
84
await scrubbedMessageStore . insertScrubbedMessages ( {
84
85
messages : scrubbedMessages ,
@@ -149,14 +150,25 @@ export function makeAddMessageToConversationUpdateTrace({
149
150
}
150
151
151
152
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
+
152
166
braintrustLogger . updateSpan ( {
153
167
id : traceId ,
154
168
tags : tracingData . tags ,
155
169
scores : {
156
170
...getTracingScores ( tracingData , k ) ,
157
- ...( shouldJudge
158
- ? await getLlmAsAJudgeScores ( llmAsAJudge , tracingData )
159
- : undefined ) ,
171
+ ...( judgeScores ?? { } ) ,
160
172
} ,
161
173
metadata : {
162
174
authUser : maybeAuthUser ?? null ,
Original file line number Diff line number Diff line change
1
+ import { logRequest } from "../../utils" ;
1
2
import { extractTracingData } from "../extractTracingData" ;
2
3
import { analyzeMessage , MessageAnalysis } from "./analyzeMessage" ;
3
4
import { redactPii } from "./redactPii" ;
@@ -8,19 +9,32 @@ export async function makeScrubbedMessagesFromTracingData({
8
9
tracingData,
9
10
analysis,
10
11
embeddingModelName,
12
+ reqId,
11
13
} : {
12
14
tracingData : ReturnType < typeof extractTracingData > ;
13
15
analysis ?: {
14
16
model : LanguageModel ;
15
17
} ;
16
18
embeddingModelName : string ;
19
+ reqId : string ;
17
20
} ) : Promise < ScrubbedMessage < MessageAnalysis > [ ] > {
18
21
const { userMessage, assistantMessage } = tracingData ;
19
22
20
- // User message scrubbing
21
23
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
+ )
23
36
: undefined ;
37
+
24
38
const { redactedText : redactedUserContent , piiFound : userMessagePii } =
25
39
redactPii ( userMessage . content ) ;
26
40
Original file line number Diff line number Diff line change 1
1
import { Conversation , ConversationsService } from "mongodb-rag-core" ;
2
2
import { ObjectId } from "mongodb-rag-core/mongodb" ;
3
+ import { logRequest } from "../../utils" ;
3
4
4
5
export type UpdateTraceFuncParams = {
5
6
reqId : string ;
@@ -32,6 +33,14 @@ export async function updateTraceIfExists({
32
33
reqId,
33
34
traceId : assistantResponseMessageId . toHexString ( ) ,
34
35
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
+ } ) ;
35
44
} ) ;
36
45
}
37
46
}
You can’t perform that action at this time.
0 commit comments