@@ -195,9 +195,9 @@ class LLMObsTagger {
195
195
196
196
const documentObj = { text }
197
197
198
- validDocument = this . _tagConditional ( 'string' , name , 'Document name' , documentObj , 'name' ) && validDocument
199
- validDocument = this . _tagConditional ( 'string' , id , 'Document ID' , documentObj , 'id' ) && validDocument
200
- validDocument = this . _tagConditional ( 'number' , score , 'Document score' , documentObj , 'score' ) && validDocument
198
+ validDocument = this . _tagConditionalString ( name , 'Document name' , documentObj , 'name' ) && validDocument
199
+ validDocument = this . _tagConditionalString ( id , 'Document ID' , documentObj , 'id' ) && validDocument
200
+ validDocument = this . _tagConditionalNumber ( score , 'Document score' , documentObj , 'score' ) && validDocument
201
201
202
202
return validDocument ? documentObj : undefined
203
203
} ) . filter ( doc => ! ! doc )
@@ -235,7 +235,7 @@ class LLMObsTagger {
235
235
validMessage = false
236
236
}
237
237
238
- validMessage = this . _tagConditional ( 'string' , role , 'Message role' , messageObj , 'role' ) && validMessage
238
+ validMessage = this . _tagConditionalString ( role , 'Message role' , messageObj , 'role' ) && validMessage
239
239
240
240
if ( toolCalls ) {
241
241
if ( ! Array . isArray ( toolCalls ) ) {
@@ -253,10 +253,10 @@ class LLMObsTagger {
253
253
const { name, arguments : args , toolId, type } = toolCall
254
254
const toolCallObj = { }
255
255
256
- validTool = this . _tagConditional ( 'string' , name , 'Tool name' , toolCallObj , 'name' ) && validTool
257
- validTool = this . _tagConditional ( 'object' , args , 'Tool arguments' , toolCallObj , 'arguments' ) && validTool
258
- validTool = this . _tagConditional ( 'string' , toolId , 'Tool ID' , toolCallObj , 'tool_id' ) && validTool
259
- validTool = this . _tagConditional ( 'string' , type , 'Tool type' , toolCallObj , 'type' ) && validTool
256
+ validTool = this . _tagConditionalString ( name , 'Tool name' , toolCallObj , 'name' ) && validTool
257
+ validTool = this . _tagConditionalObject ( args , 'Tool arguments' , toolCallObj , 'arguments' ) && validTool
258
+ validTool = this . _tagConditionalString ( toolId , 'Tool ID' , toolCallObj , 'tool_id' ) && validTool
259
+ validTool = this . _tagConditionalString ( type , 'Tool type' , toolCallObj , 'type' ) && validTool
260
260
261
261
return validTool ? toolCallObj : undefined
262
262
} ) . filter ( toolCall => ! ! toolCall )
@@ -275,10 +275,30 @@ class LLMObsTagger {
275
275
}
276
276
}
277
277
278
- _tagConditional ( dataType , data , type , carrier , key ) {
278
+ _tagConditionalString ( data , type , carrier , key ) {
279
279
if ( ! data ) return true
280
- if ( typeof data !== dataType ) { // eslint-disable-line valid-typeof
281
- this . _handleFailure ( `"${ type } " must be of type "${ dataType } ".` )
280
+ if ( typeof data !== 'string' ) {
281
+ this . _handleFailure ( `"${ type } " must be a string.` )
282
+ return false
283
+ }
284
+ carrier [ key ] = data
285
+ return true
286
+ }
287
+
288
+ _tagConditionalNumber ( data , type , carrier , key ) {
289
+ if ( ! data ) return true
290
+ if ( typeof data !== 'number' ) {
291
+ this . _handleFailure ( `"${ type } " must be a number.` )
292
+ return false
293
+ }
294
+ carrier [ key ] = data
295
+ return true
296
+ }
297
+
298
+ _tagConditionalObject ( data , type , carrier , key ) {
299
+ if ( ! data ) return true
300
+ if ( typeof data !== 'object' ) {
301
+ this . _handleFailure ( `"${ type } " must be an object.` )
282
302
return false
283
303
}
284
304
carrier [ key ] = data
0 commit comments