3838import com .microsoft .semantickernel .aiservices .openai .OpenAiService ;
3939import com .microsoft .semantickernel .aiservices .openai .chatcompletion .responseformat .ChatCompletionsJsonSchemaResponseFormat ;
4040import com .microsoft .semantickernel .aiservices .openai .implementation .OpenAIRequestSettings ;
41+ import com .microsoft .semantickernel .contents .FunctionCallContent ;
4142import com .microsoft .semantickernel .contextvariables .ContextVariable ;
4243import com .microsoft .semantickernel .contextvariables .ContextVariableTypes ;
4344import com .microsoft .semantickernel .exceptions .AIException ;
@@ -468,7 +469,6 @@ private Mono<ChatMessages> internalChatMessageContentsAsync(
468469 .doOnTerminate (span ::close );
469470 })
470471 .flatMap (completions -> {
471-
472472 List <ChatResponseMessage > responseMessages = completions
473473 .getChoices ()
474474 .stream ()
@@ -488,6 +488,7 @@ private Mono<ChatMessages> internalChatMessageContentsAsync(
488488 completions );
489489 return Mono .just (messages .addChatMessage (chatMessageContents ));
490490 }
491+
491492 // Or if there are no tool calls to be done
492493 ChatResponseMessage response = responseMessages .get (0 );
493494 List <ChatCompletionsToolCall > toolCalls = response .getToolCalls ();
@@ -633,21 +634,21 @@ private Mono<FunctionResult<String>> invokeFunctionTool(
633634 ContextVariableTypes contextVariableTypes ) {
634635
635636 try {
636- OpenAIFunctionToolCall openAIFunctionToolCall = extractOpenAIFunctionToolCall (toolCall );
637- String pluginName = openAIFunctionToolCall .getPluginName ();
637+ FunctionCallContent functionCallContent = extractFunctionCallContent (toolCall );
638+ String pluginName = functionCallContent .getPluginName ();
638639 if (pluginName == null || pluginName .isEmpty ()) {
639640 return Mono .error (
640641 new SKException ("Plugin name is required for function tool call" ));
641642 }
642643
643644 KernelFunction <?> function = kernel .getFunction (
644645 pluginName ,
645- openAIFunctionToolCall .getFunctionName ());
646+ functionCallContent .getFunctionName ());
646647
647648 PreToolCallEvent hookResult = executeHook (invocationContext , kernel ,
648649 new PreToolCallEvent (
649- openAIFunctionToolCall .getFunctionName (),
650- openAIFunctionToolCall .getArguments (),
650+ functionCallContent .getFunctionName (),
651+ functionCallContent .getArguments (),
651652 function ,
652653 contextVariableTypes ));
653654
@@ -686,7 +687,7 @@ private static <T extends KernelHookEvent> T executeHook(
686687 }
687688
688689 @ SuppressWarnings ("StringSplitter" )
689- private OpenAIFunctionToolCall extractOpenAIFunctionToolCall (
690+ private FunctionCallContent extractFunctionCallContent (
690691 ChatCompletionsFunctionToolCall toolCall )
691692 throws JsonProcessingException {
692693
@@ -712,10 +713,10 @@ private OpenAIFunctionToolCall extractOpenAIFunctionToolCall(
712713 }
713714 });
714715
715- return new OpenAIFunctionToolCall (
716- toolCall .getId (),
717- pluginName ,
716+ return new FunctionCallContent (
718717 fnName ,
718+ pluginName ,
719+ toolCall .getId (),
719720 arguments );
720721 }
721722
@@ -744,7 +745,7 @@ private List<OpenAIChatMessageContent<?>> getChatMessageContentsAsync(
744745 null ,
745746 null ,
746747 completionMetadata ,
747- formOpenAiToolCalls (response ));
748+ formFunctionCallContents (response ));
748749 } catch (SKCheckedException e ) {
749750 LOGGER .warn ("Failed to form chat message content" , e );
750751 return null ;
@@ -784,7 +785,7 @@ private List<ChatMessageContent<?>> toOpenAIChatMessageContent(
784785 null );
785786 } else if (message instanceof ChatRequestAssistantMessage ) {
786787 try {
787- List <OpenAIFunctionToolCall > calls = getToolCalls (
788+ List <FunctionCallContent > calls = getFunctionCallContents (
788789 ((ChatRequestAssistantMessage ) message ).getToolCalls ());
789790 return new OpenAIChatMessageContent <>(
790791 AuthorRole .ASSISTANT ,
@@ -823,7 +824,7 @@ private List<ChatMessageContent<?>> toOpenAIChatMessageContent(
823824 }
824825
825826 @ Nullable
826- private List <OpenAIFunctionToolCall > getToolCalls (
827+ private List <FunctionCallContent > getFunctionCallContents (
827828 @ Nullable List <ChatCompletionsToolCall > toolCalls ) throws SKCheckedException {
828829 if (toolCalls == null || toolCalls .isEmpty ()) {
829830 return null ;
@@ -835,7 +836,7 @@ private List<OpenAIFunctionToolCall> getToolCalls(
835836 .map (call -> {
836837 if (call instanceof ChatCompletionsFunctionToolCall ) {
837838 try {
838- return extractOpenAIFunctionToolCall (
839+ return extractFunctionCallContent (
839840 (ChatCompletionsFunctionToolCall ) call );
840841 } catch (JsonProcessingException e ) {
841842 throw SKException .build ("Failed to parse tool arguments" , e );
@@ -852,7 +853,7 @@ private List<OpenAIFunctionToolCall> getToolCalls(
852853 }
853854
854855 @ Nullable
855- private List <OpenAIFunctionToolCall > formOpenAiToolCalls (
856+ private List <FunctionCallContent > formFunctionCallContents (
856857 ChatResponseMessage response ) throws SKCheckedException {
857858 if (response .getToolCalls () == null || response .getToolCalls ().isEmpty ()) {
858859 return null ;
@@ -864,7 +865,7 @@ private List<OpenAIFunctionToolCall> formOpenAiToolCalls(
864865 .map (call -> {
865866 if (call instanceof ChatCompletionsFunctionToolCall ) {
866867 try {
867- return extractOpenAIFunctionToolCall (
868+ return extractFunctionCallContent (
868869 (ChatCompletionsFunctionToolCall ) call );
869870 } catch (JsonProcessingException e ) {
870871 throw SKException .build ("Failed to parse tool arguments" , e );
@@ -1251,10 +1252,7 @@ private static ChatRequestAssistantMessage formAssistantMessage(
12511252 // TODO: handle tools other than function calls
12521253 ChatRequestAssistantMessage asstMessage = new ChatRequestAssistantMessage (content );
12531254
1254- List <OpenAIFunctionToolCall > toolCalls = null ;
1255- if (message instanceof OpenAIChatMessageContent ) {
1256- toolCalls = ((OpenAIChatMessageContent <?>) message ).getToolCall ();
1257- }
1255+ List <FunctionCallContent > toolCalls = FunctionCallContent .getFunctionCalls (message );
12581256
12591257 if (toolCalls != null ) {
12601258 asstMessage .setToolCalls (
0 commit comments