@@ -222,7 +222,7 @@ private static Value<?> buildToolCallEventObject(
222222 Map <String , Value <?>> result = new HashMap <>();
223223 FunctionAccess functionAccess = getFunctionAccess (call );
224224 if (functionAccess != null ) {
225- result .put ("id" , toValue (functionAccess .id ()));
225+ result .put ("id" , Value . of (functionAccess .id ()));
226226 result .put ("type" , Value .of ("function" )); // "function" is the only currently supported type
227227 result .put ("function" , buildFunctionEventObject (functionAccess , captureMessageContent ));
228228 }
@@ -232,18 +232,13 @@ private static Value<?> buildToolCallEventObject(
232232 private static Value <?> buildFunctionEventObject (
233233 FunctionAccess functionAccess , boolean captureMessageContent ) {
234234 Map <String , Value <?>> result = new HashMap <>();
235- result .put ("name" , toValue (functionAccess .name ()));
235+ result .put ("name" , Value . of (functionAccess .name ()));
236236 if (captureMessageContent ) {
237- result .put ("arguments" , toValue (functionAccess .arguments ()));
237+ result .put ("arguments" , Value . of (functionAccess .arguments ()));
238238 }
239239 return Value .of (result );
240240 }
241241
242- @ Nullable
243- private static Value <String > toValue (@ Nullable String string ) {
244- return string != null ? Value .of (string ) : null ;
245- }
246-
247242 @ Nullable
248243 private static FunctionAccess getFunctionAccess (ChatCompletionMessageToolCall call ) {
249244 if (V1FunctionAccess .isAvailable ()) {
@@ -257,26 +252,22 @@ private static FunctionAccess getFunctionAccess(ChatCompletionMessageToolCall ca
257252 }
258253
259254 private interface FunctionAccess {
260- @ Nullable
261255 String id ();
262256
263- @ Nullable
264257 String name ();
265258
266- @ Nullable
267259 String arguments ();
268260 }
269261
270- @ Nullable
271262 private static String invokeStringHandle (@ Nullable MethodHandle methodHandle , Object object ) {
272263 if (methodHandle == null ) {
273- return null ;
264+ return "" ;
274265 }
275266
276267 try {
277268 return (String ) methodHandle .invoke (object );
278269 } catch (Throwable ignore ) {
279- return null ;
270+ return "" ;
280271 }
281272 }
282273
@@ -345,19 +336,16 @@ static boolean isAvailable() {
345336 return idHandle != null ;
346337 }
347338
348- @ Nullable
349339 @ Override
350340 public String id () {
351341 return invokeStringHandle (idHandle , toolCall );
352342 }
353343
354- @ Nullable
355344 @ Override
356345 public String name () {
357346 return invokeStringHandle (nameHandle , function );
358347 }
359348
360- @ Nullable
361349 @ Override
362350 public String arguments () {
363351 return invokeStringHandle (argumentsHandle , function );
@@ -443,19 +431,16 @@ static boolean isAvailable() {
443431 return idHandle != null ;
444432 }
445433
446- @ Nullable
447434 @ Override
448435 public String id () {
449436 return invokeStringHandle (idHandle , functionToolCall );
450437 }
451438
452- @ Nullable
453439 @ Override
454440 public String name () {
455441 return invokeStringHandle (nameHandle , function );
456442 }
457443
458- @ Nullable
459444 @ Override
460445 public String arguments () {
461446 return invokeStringHandle (argumentsHandle , function );
0 commit comments