diff --git a/CHANGELOG.md b/CHANGELOG.md index 8859c23f..93186239 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.3.1 + +- Upgrade to azure-ai-openai 1.0.0-beta.12 + # 1.3.0 - Added support for Json Schema to Open AI Chat Completions diff --git a/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/BinaryDataUtils.java b/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/BinaryDataUtils.java new file mode 100644 index 00000000..9a3189a7 --- /dev/null +++ b/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/BinaryDataUtils.java @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft. All rights reserved. +package com.microsoft.semantickernel.aiservices.openai.chatcompletion; + +import com.azure.core.util.BinaryData; +import javax.annotation.Nullable; + +public class BinaryDataUtils { + + @Nullable + public static String toString(@Nullable BinaryData b) { + if (b == null) { + return null; + } + return b.toString(); + } +} diff --git a/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatCompletion.java b/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatCompletion.java index 919ff995..6d822687 100644 --- a/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatCompletion.java +++ b/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatCompletion.java @@ -6,6 +6,7 @@ import com.azure.ai.openai.models.ChatCompletions; import com.azure.ai.openai.models.ChatCompletionsFunctionToolCall; import com.azure.ai.openai.models.ChatCompletionsFunctionToolDefinition; +import com.azure.ai.openai.models.ChatCompletionsFunctionToolDefinitionFunction; import com.azure.ai.openai.models.ChatCompletionsJsonResponseFormat; import com.azure.ai.openai.models.ChatCompletionsNamedToolSelection; import com.azure.ai.openai.models.ChatCompletionsOptions; @@ -26,6 +27,7 @@ import com.azure.ai.openai.models.ChatResponseMessage; import com.azure.ai.openai.models.CompletionsUsage; import com.azure.ai.openai.models.FunctionCall; +import com.azure.ai.openai.models.FunctionDefinition; import com.azure.json.JsonOptions; import com.azure.json.implementation.DefaultJsonReader; import com.fasterxml.jackson.core.JsonProcessingException; @@ -734,7 +736,8 @@ private List> toOpenAIChatMessageContent( if (message instanceof ChatRequestUserMessage) { return new OpenAIChatMessageContent<>( AuthorRole.USER, - ((ChatRequestUserMessage) message).getContent().toString(), + BinaryDataUtils + .toString(((ChatRequestUserMessage) message).getContent()), null, null, null, @@ -743,7 +746,8 @@ private List> toOpenAIChatMessageContent( } else if (message instanceof ChatRequestSystemMessage) { return new OpenAIChatMessageContent<>( AuthorRole.SYSTEM, - ((ChatRequestSystemMessage) message).getContent(), + BinaryDataUtils + .toString(((ChatRequestSystemMessage) message).getContent()), null, null, null, @@ -755,7 +759,8 @@ private List> toOpenAIChatMessageContent( ((ChatRequestAssistantMessage) message).getToolCalls()); return new OpenAIChatMessageContent<>( AuthorRole.ASSISTANT, - ((ChatRequestAssistantMessage) message).getContent(), + BinaryDataUtils + .toString(((ChatRequestAssistantMessage) message).getContent()), null, null, null, @@ -767,7 +772,8 @@ private List> toOpenAIChatMessageContent( } else if (message instanceof ChatRequestToolMessage) { return new OpenAIChatMessageContent<>( AuthorRole.TOOL, - ((ChatRequestToolMessage) message).getContent(), + BinaryDataUtils + .toString(((ChatRequestToolMessage) message).getContent()), null, null, null, @@ -966,10 +972,14 @@ private static void configureToolCallBehaviorOptions( List toolDefinitions = new ArrayList<>(); + FunctionDefinition function = OpenAIFunction.toFunctionDefinition( + toolChoice.getMetadata(), + toolChoice.getPluginName()); + toolDefinitions.add(new ChatCompletionsFunctionToolDefinition( - OpenAIFunction.toFunctionDefinition( - toolChoice.getMetadata(), - toolChoice.getPluginName()))); + new ChatCompletionsFunctionToolDefinitionFunction(function.getName()) + .setDescription(function.getDescription()) + .setParameters(function.getParameters()))); options.setTools(toolDefinitions); try { @@ -1003,7 +1013,10 @@ private static void configureToolCallBehaviorOptions( function.getName()); }) .map(OpenAIFunction::getFunctionDefinition) - .map(ChatCompletionsFunctionToolDefinition::new) + .map(it -> new ChatCompletionsFunctionToolDefinitionFunction(it.getName()) + .setDescription(it.getDescription()) + .setParameters(it.getParameters())) + .map(it -> new ChatCompletionsFunctionToolDefinition(it)) .collect(Collectors.toList()); if (toolDefinitions.isEmpty()) { diff --git a/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAiXMLPromptParser.java b/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAiXMLPromptParser.java index 4088f72f..4f5fd99c 100644 --- a/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAiXMLPromptParser.java +++ b/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAiXMLPromptParser.java @@ -118,19 +118,23 @@ public static ChatRequestMessage unescapeRequest(ChatRequestMessage message) { if (message instanceof ChatRequestUserMessage) { ChatRequestUserMessage chatRequestMessage = (ChatRequestUserMessage) message; String content = StringEscapeUtils.unescapeXml( - chatRequestMessage.getContent().toString()); + BinaryDataUtils.toString(chatRequestMessage.getContent())); return new ChatRequestUserMessage(content) .setName(chatRequestMessage.getName()); } else if (message instanceof ChatRequestSystemMessage) { ChatRequestSystemMessage chatRequestMessage = (ChatRequestSystemMessage) message; - String content = StringEscapeUtils.unescapeXml(chatRequestMessage.getContent()); + String content = StringEscapeUtils + .unescapeXml( + BinaryDataUtils.toString(chatRequestMessage.getContent())); return new ChatRequestSystemMessage(content) .setName(chatRequestMessage.getName()); } else if (message instanceof ChatRequestAssistantMessage) { ChatRequestAssistantMessage chatRequestMessage = (ChatRequestAssistantMessage) message; - String content = StringEscapeUtils.unescapeXml(chatRequestMessage.getContent()); + String content = StringEscapeUtils + .unescapeXml( + BinaryDataUtils.toString(chatRequestMessage.getContent())); return new ChatRequestAssistantMessage(content) .setToolCalls(chatRequestMessage.getToolCalls()) @@ -145,7 +149,9 @@ public static ChatRequestMessage unescapeRequest(ChatRequestMessage message) { content); } else if (message instanceof ChatRequestToolMessage) { ChatRequestToolMessage chatRequestMessage = (ChatRequestToolMessage) message; - String content = StringEscapeUtils.unescapeXml(chatRequestMessage.getContent()); + String content = StringEscapeUtils + .unescapeXml( + BinaryDataUtils.toString(chatRequestMessage.getContent())); return new ChatRequestToolMessage( content, diff --git a/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/RenderingTest.java b/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/RenderingTest.java index 4c24eb92..3f09b50b 100644 --- a/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/RenderingTest.java +++ b/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/RenderingTest.java @@ -240,10 +240,10 @@ public void canHandleIterableReturnFromFunction() { .block(); String requestBody = wm.getAllServeEvents().get(0).getRequest().getBodyAsString(); - Assertions.assertTrue(requestBody.contains("{\"content\":\"[]")); - Assertions.assertTrue(requestBody.contains("{\"content\":\"[1, 2, 3]")); - Assertions.assertTrue(requestBody.contains("{\"content\":\"[4, 5, 6]")); - Assertions.assertTrue(requestBody.contains("{\"content\":\"[7, 8, 9]")); + Assertions.assertTrue(requestBody.contains("\"content\":\"[]")); + Assertions.assertTrue(requestBody.contains("\"content\":\"[1, 2, 3]")); + Assertions.assertTrue(requestBody.contains("\"content\":\"[4, 5, 6]")); + Assertions.assertTrue(requestBody.contains("\"content\":\"[7, 8, 9]")); } private Kernel buildTextKernel() { diff --git a/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/ToolCallBehaviourTest.java b/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/ToolCallBehaviourTest.java index 4f96f782..09f88df0 100644 --- a/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/ToolCallBehaviourTest.java +++ b/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/ToolCallBehaviourTest.java @@ -282,7 +282,7 @@ private ChatCompletionService getChatCompletionService() { public static MappingBuilder buildTextResponse(String bodyMatcher, String responseBody) { return post(urlEqualTo( - "//openai/deployments/gpt-35-turbo-2/completions?api-version=2024-07-01-preview")) + "//openai/deployments/gpt-35-turbo-2/completions?api-version=2024-08-01-preview")) .withRequestBody(new ContainsPattern(bodyMatcher)) .willReturn( aResponse() @@ -293,7 +293,7 @@ public static MappingBuilder buildTextResponse(String bodyMatcher, String respon public static MappingBuilder buildResponse(String bodyMatcher, String responseBody) { return post(urlEqualTo( - "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2024-07-01-preview")) + "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2024-08-01-preview")) .withRequestBody(new ContainsPattern(bodyMatcher)) .willReturn( aResponse() diff --git a/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-12b6744e-443f-4fe7-82e2-55cc41195ff1.json b/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-12b6744e-443f-4fe7-82e2-55cc41195ff1.json index 9697bca8..cdc9cbd0 100644 --- a/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-12b6744e-443f-4fe7-82e2-55cc41195ff1.json +++ b/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-12b6744e-443f-4fe7-82e2-55cc41195ff1.json @@ -2,7 +2,7 @@ "priority": 1, "request": { "method": "POST", - "url": "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2024-07-01-preview", + "url": "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2024-08-01-preview", "bodyPatterns": [ { "contains": "That is all" diff --git a/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-71b07779-49a8-44e5-a60b-ee5b0a3ad697.json b/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-71b07779-49a8-44e5-a60b-ee5b0a3ad697.json index c99d0145..0d71a457 100644 --- a/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-71b07779-49a8-44e5-a60b-ee5b0a3ad697.json +++ b/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-71b07779-49a8-44e5-a60b-ee5b0a3ad697.json @@ -1,7 +1,7 @@ { "request": { "method": "POST", - "url": "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2024-07-01-preview" + "url": "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2024-08-01-preview" }, "response": { "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253061,\"model\":\"gpt-35-turbo\",\"prompt_filter_results\":[{\"prompt_index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}}}],\"choices\":[{\"finish_reason\":\"stop\",\"index\":0,\"message\":{\"role\":\"assistant\",\"content\":\"1979b4ce-5463-4cfb-8ec8-1d05c4b44ccf\"},\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}}}],\"usage\":{\"prompt_tokens\":17,\"completion_tokens\":67,\"total_tokens\":84}}", diff --git a/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-0c8046c5-74ad-4836-8aa9-09da60f367a2.json b/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-0c8046c5-74ad-4836-8aa9-09da60f367a2.json index d55d6bae..53becbdf 100644 --- a/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-0c8046c5-74ad-4836-8aa9-09da60f367a2.json +++ b/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-0c8046c5-74ad-4836-8aa9-09da60f367a2.json @@ -1,7 +1,7 @@ { "request": { "method": "POST", - "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2024-07-01-preview" + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2024-08-01-preview" }, "response": { "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253039,\"model\":\"gpt-35-turbo\",\"prompt_filter_results\":[{\"prompt_index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}}}],\"choices\":[{\"finish_reason\":\"stop\",\"index\":0,\"message\":{\"role\":\"assistant\",\"content\":\"ac9817bc-7e1a-48e4-b06c-0ff7618b88c6\"},\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}}}],\"usage\":{\"prompt_tokens\":26,\"completion_tokens\":131,\"total_tokens\":157}}", diff --git a/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-0215b128-4822-4368-ac3d-2f580a221f00.json b/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-0215b128-4822-4368-ac3d-2f580a221f00.json index 15adeb40..7ac0518d 100644 --- a/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-0215b128-4822-4368-ac3d-2f580a221f00.json +++ b/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-0215b128-4822-4368-ac3d-2f580a221f00.json @@ -1,7 +1,7 @@ { "request": { "method": "POST", - "url": "//openai/deployments/text-davinci-003/completions?api-version=2024-07-01-preview" + "url": "//openai/deployments/text-davinci-003/completions?api-version=2024-08-01-preview" }, "response": { "body": "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707253062,\"model\":\"text-davinci-003\",\"prompt_filter_results\":[{\"prompt_index\":0,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}}}],\"choices\":[{\"text\":\"7949e981-c632-422f-9b76-335a2379cd83\",\"index\":0,\"finish_reason\":\"stop\",\"logprobs\":null,\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}}}],\"usage\":{\"prompt_tokens\":10,\"completion_tokens\":26,\"total_tokens\":36}}", diff --git a/pom.xml b/pom.xml index 87a03ac9..f4119f47 100644 --- a/pom.xml +++ b/pom.xml @@ -14,8 +14,7 @@ Parent pom for the Semantic Kernel Project - - 1.0.0-beta.11 + 1.0.0-beta.12 10.18.2 0.10.21 false diff --git a/semantickernel-bom/pom.xml b/semantickernel-bom/pom.xml index 922338b5..c1aba267 100644 --- a/semantickernel-bom/pom.xml +++ b/semantickernel-bom/pom.xml @@ -115,8 +115,7 @@ com.azure azure-ai-openai - - 1.0.0-beta.11 + 1.0.0-beta.12 com.azure