From f5cca08b91ce2c723f815a81dc872e8e0302ae52 Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Thu, 22 Feb 2024 13:35:25 +0000 Subject: [PATCH] Java: Convert PromptTemplateConfig and ChatMessageContent to immutable (#5067) ### Motivation and Context ### Description ### Contribution Checklist - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone :smile: --------- Co-authored-by: GitHub --- .../openai/OpenAIRequestSettings.java | 1 + .../chatcompletion/OpenAIChatCompletion.java | 3 +- .../chatcompletion/OpenAIChatResponse.java | 1 + .../openai/chatcompletion/OpenAIFunction.java | 49 ++- .../openai/chatcompletion/ParsedPrompt.java | 1 + .../chatcompletion/XMLPromptParser.java | 1 + .../OpenAITextGenerationService.java | 1 + java/api-test/integration-tests/pom.xml | 3 +- .../syntaxexamples/WireMockUtil.java | 45 --- .../Example01NativeFunctionsTest.java | 3 +- .../Example03_ArgumentsTest.java | 4 +- ...xample05_InlineFunctionDefinitionTest.java | 4 +- .../semantickernel/tests/KernelHooksTest.java | 103 ++++++ .../semantickernel/tests/WireMockUtil.java | 125 +++++++ .../WiremockExamplesIT.java | 3 +- .../WiremockRecord.java | 3 +- .../src/test/resources/log4j2.xml | 2 +- ...-45379a29-d6d3-4613-a885-b30ccaaa6db0.json | 42 +-- ...-686c6f9b-7c66-41af-8b9b-86e44fcdb2b1.json | 42 +-- ...-71b07779-49a8-44e5-a60b-ee5b0a3ad697.json | 46 +-- ...-c9edbe4a-e60b-4796-bd01-11bafa211bab.json | 48 +-- ...-093a64da-80ba-49bf-a4fd-625224d60b3a.json | 42 +-- ...-0c8046c5-74ad-4836-8aa9-09da60f367a2.json | 42 +-- ...-252c54f4-1111-467b-b028-7687e4ed5021.json | 48 +-- ...-270f9641-5867-4ca4-a738-d3b1d18faefb.json | 46 +-- ...-364efff1-b5dd-4796-8c01-936b19045de2.json | 48 +-- ...-36d8c189-3b93-4a19-b92f-8effb670f75a.json | 42 +-- ...-3708b848-8dbe-4c2d-a057-04abcee675c0.json | 42 +-- ...-4939b782-4212-435b-8d7d-c3454fe0200c.json | 42 +-- ...-5d78a6d8-abca-488a-8752-599051a3e352.json | 48 +-- ...-604be5a5-3e55-44ee-a85f-9d9e63b1763a.json | 48 +-- ...-70facef2-7e60-49d5-8009-b38915a1b355.json | 42 +-- ...-779728d0-3cfa-4374-aa56-7038de43449e.json | 46 +-- ...-79f4220d-21e6-43e2-8a2e-6a281fcbfea9.json | 42 +-- ...-8ccdcbb2-4a82-47c4-a3da-93041481ce06.json | 42 +-- ...-bcdbf876-8b4c-4de1-99b4-deaad761fdbe.json | 42 +-- ...-c71f3ff7-70f7-4966-a752-811bf1c01382.json | 46 +-- ...-ca797b35-ef23-4628-9c6f-b1ea00ba5e3e.json | 42 +-- ...-daf144e4-182b-4100-91f2-49b6115a1026.json | 46 +-- ...-dc3d7bb6-815c-44fc-a15f-a6f9ce7eb012.json | 42 +-- ...-f0070b1d-f4eb-4691-9d72-a0b935a227eb.json | 42 +-- ...-0215b128-4822-4368-ac3d-2f580a221f00.json | 48 +-- ...-1296bcee-1e54-43b1-b4b3-4642dd8bd0a0.json | 46 +-- ...-350fea53-3d73-4d59-b603-dba32fdc5af9.json | 42 +-- ...-3ce79fbf-90ee-4575-aeb4-6f7d545d1db6.json | 42 +-- ...-3d48b3d9-5263-4d35-97dc-6db5b0335989.json | 42 +-- ...-544c72c2-de8a-407d-a319-b7c04a8c237e.json | 42 +-- ...-7441c9cd-22ef-41a0-8c0b-f050326ca99c.json | 48 +-- ...-7718fb6b-1cae-4420-8e34-126c14d00539.json | 42 +-- ...-857195c1-97b9-4118-8c05-d25d0020f8e2.json | 42 +-- ...-85f3675c-e404-4138-96c2-e49d4521e4f6.json | 42 +-- ...-990e9efb-2d61-424d-bbf6-a68e2d25552f.json | 42 +-- ...-a29ad1f1-2423-4dbf-a127-fd2c93998fcd.json | 42 +-- ...-fb3fd96e-de60-4e75-b551-493819766937.json | 42 +-- java/api-test/pom.xml | 3 +- .../connectors/web/bing/BingConnector.java | 1 + .../plugins/web/SearchUrlPlugin.java | 1 + java/pom.xml | 7 +- java/samples/pom.xml | 7 +- java/samples/sample-code/pom.xml | 3 +- .../plugins/ConversationSummaryPlugin.java | 47 +-- .../plugins/PromptFunctionConstants.java | 1 + .../Example01_NativeFunctions.java | 1 + .../syntaxexamples/Example03_Arguments.java | 34 +- .../Example05_InlineFunctionDefinition.java | 2 +- .../Example06_TemplateLanguage.java | 31 +- .../Example07_BingAndGooglePlugins.java | 14 +- .../Example08_RetryHandler.java | 5 +- .../Example09_FunctionTypes.java | 121 ++++--- ...mple10_DescribeAllPluginsAndFunctions.java | 41 +-- .../Example11_WebSearchQueries.java | 3 +- .../Example13_ConversationSummaryPlugin.java | 5 +- .../syntaxexamples/Example17_ChatGPT.java | 1 + .../syntaxexamples/Example26_AADAuth.java | 3 +- ...Example27_PromptFunctionsUsingChatGPT.java | 5 +- .../Example30_ChatWithPrompts.java | 7 +- .../syntaxexamples/Example33_Chat.java | 1 + .../Example41_HttpClientUsage.java | 1 + .../Example42_KernelBuilder.java | 3 +- .../Example43_GetModelResult.java | 7 +- .../Example44_MultiChatCompletion.java | 5 +- .../syntaxexamples/Example49_LogitBias.java | 5 +- .../syntaxexamples/Example55_TextChunker.java | 1 + ...eMethodFunctionsWithMultipleArguments.java | 5 +- .../syntaxexamples/Example57_KernelHooks.java | 13 +- .../Example58_ConfigureExecutionSettings.java | 9 +- .../Example59_OpenAIFunctionCalling.java | 64 ++-- .../Example60_AdvancedMethodFunctions.java | 3 +- .../Example61_MultipleLLMs.java | 16 +- .../Example62_CustomAIServiceSelector.java | 7 +- .../Example63_ChatCompletionPrompts.java | 6 +- .../Example64_MultiplePromptTemplates.java | 5 +- .../Example67_KernelStreaming.java | 1 + .../Example69_MutableKernelPlugin.java | 20 +- .../samples/syntaxexamples/RunAll.java | 12 +- .../java/KernelFunctionYaml_Example.java | 93 +++++ .../syntaxexamples/java/GenerateStory.yaml | 17 + .../java/GenerateStoryHandlebars.yaml | 23 ++ java/semantickernel-api/pom.xml | 9 +- .../com/microsoft/semantickernel/Kernel.java | 80 +++-- .../KernelPluginCollection.java | 27 +- .../semantickernel/builders/Buildable.java | 5 +- .../connectors/WebSearchEngineConnector.java | 26 +- .../contextvariables/CaseInsensitiveMap.java | 2 + .../contextvariables/ContextVariable.java | 192 ++++++----- .../contextvariables/ContextVariableType.java | 3 +- .../ContextVariableTypeConverter.java | 168 +++++---- .../ContextVariableTypes.java | 50 +-- ...nVariableContextVariableTypeConverter.java | 9 +- ...rVariableContextVariableTypeConverter.java | 12 +- ...yVariableContextVariableTypeConverter.java | 15 +- ...tionUsageContextVariableTypeConverter.java | 7 +- .../DateTimeContextVariableTypeConverter.java | 10 +- .../InstantContextVariableTypeConverter.java | 10 +- ...rVariableContextVariableTypeConverter.java | 16 +- ...gVariableContextVariableTypeConverter.java | 9 +- ...tVariableContextVariableTypeConverter.java | 30 ++ ...dVariableContextVariableTypeConverter.java | 9 +- .../exceptions/AIException.java | 61 +++- .../exceptions/ConfigurationException.java | 38 ++- .../exceptions/SKCheckedException.java | 8 +- .../exceptions/SKException.java | 20 +- .../hooks/FunctionInvokedEvent.java | 10 +- .../hooks/FunctionInvokingEvent.java | 13 +- .../semantickernel/hooks/KernelHook.java | 33 +- .../semantickernel/hooks/KernelHookEvent.java | 1 + .../semantickernel/hooks/KernelHooks.java | 1 + .../hooks/PreChatCompletionEvent.java | 3 + .../hooks/PromptRenderedEvent.java | 9 +- .../hooks/PromptRenderingEvent.java | 6 +- .../EmbeddedResourceLoader.java | 42 +-- .../implementation/ServiceLoadUtil.java | 13 +- .../semantickernel/implementation/Todo.java | 1 + .../semantickernel/implementation/Verify.java | 6 +- .../tokenizer/CodeTokenizer.java | 113 +++---- .../tokenizer/DefaultPromptTemplate.java | 62 +++- .../tokenizer/TemplateTokenizer.java | 86 +++-- .../tokenizer/blocks/CodeBlock.java | 8 +- .../tokenizer/blocks/CodeRendering.java | 4 +- .../tokenizer/blocks/FunctionIdBlock.java | 17 +- .../tokenizer/blocks/NamedArgBlock.java | 67 ++-- .../tokenizer/blocks/TextBlock.java | 8 +- .../tokenizer/blocks/TextRendering.java | 1 + .../tokenizer/blocks/ValBlock.java | 12 +- .../tokenizer/blocks/VarBlock.java | 2 +- .../orchestration/FunctionInvocation.java | 305 +++++++++-------- .../orchestration/FunctionResult.java | 10 +- .../orchestration/FunctionResultMetadata.java | 17 +- .../orchestration/InvocationContext.java | 99 +++--- .../PromptExecutionSettings.java | 181 +++++----- .../orchestration/ToolCallBehavior.java | 62 ++-- .../semantickernel/plugin/KernelPlugin.java | 16 +- .../plugin/KernelPluginFactory.java | 48 +-- .../plugin/KernelReturnParameterMetadata.java | 4 +- .../semantickernel/plugin/Plugin.java | 4 +- .../AggregatorPromptTemplateFactory.java | 6 +- .../HandlebarsPromptTemplateFactory.java | 5 +- .../semanticfunctions/InputConfig.java | 16 +- .../semanticfunctions/InputParameter.java | 11 +- .../semanticfunctions/InputVariable.java | 15 +- .../semanticfunctions/KernelFunction.java | 98 +++--- .../KernelFunctionArguments.java | 27 +- .../KernelFunctionFactory.java | 0 .../KernelFunctionFromMethod.java | 134 ++++++-- .../KernelFunctionFromPrompt.java | 129 +------ .../KernelFunctionMetadata.java | 14 +- .../semanticfunctions/KernelFunctionYaml.java | 30 +- .../KernelParameterMetadata.java | 21 +- .../KernelPromptTemplateFactory.java | 14 +- .../semanticfunctions/MethodDetails.java | 6 + .../semanticfunctions/OutputVariable.java | 8 +- .../semanticfunctions/PromptTemplate.java | 10 +- .../PromptTemplateConfig.java | 319 +++++++++++------- .../PromptTemplateFactory.java | 33 +- .../annotations/DefineKernelFunction.java | 37 +- .../annotations/KernelFunctionParameter.java | 37 +- .../annotations/SKSample.java | 7 +- .../services/AIServiceCollection.java | 1 + .../services/AIServiceSelection.java | 9 +- .../services/AIServiceSelector.java | 12 +- .../services/AIServiceSupplier.java | 7 - .../services/BaseAIServiceSelector.java | 24 +- .../services/KernelContent.java | 15 +- .../services/NamedServiceProvider.java | 6 +- .../services/OrderedAIServiceSelector.java | 67 ++-- .../services/ServiceNotFoundException.java | 2 + .../services/StreamingKernelContent.java | 16 +- .../services/TextAIService.java | 29 +- .../services/chatcompletion/AuthorRole.java | 14 +- .../chatcompletion/ChatCompletionService.java | 42 +-- .../services/chatcompletion/ChatHistory.java | 12 +- .../chatcompletion/ChatMessageContent.java | 49 +-- .../StreamingChatMessageContent.java | 99 ------ .../textcompletion/StreamingTextContent.java | 1 + .../services/textcompletion/TextContent.java | 11 +- .../textcompletion/TextGenerationService.java | 27 +- .../handlebars/HandlebarsPromptTemplate.java | 19 +- .../semantickernel/TemplateException.java | 6 + .../semantickernel/text/TextChunker.java | 28 +- .../ContextVariableTypeConverterTest.java | 69 ++++ ...iableContextVariableTypeConverterTest.java | 1 + java/semantickernel-bom/pom.xml | 3 +- 202 files changed, 3551 insertions(+), 2707 deletions(-) delete mode 100644 java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/WireMockUtil.java rename java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/{syntaxexamples => tests}/Example01NativeFunctionsTest.java (90%) rename java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/{syntaxexamples => tests}/Example03_ArgumentsTest.java (96%) rename java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/{syntaxexamples => tests}/Example05_InlineFunctionDefinitionTest.java (98%) create mode 100644 java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/KernelHooksTest.java create mode 100644 java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/WireMockUtil.java rename java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/{syntaxexamples => tests}/WiremockExamplesIT.java (98%) rename java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/{syntaxexamples => tests}/WiremockRecord.java (97%) create mode 100644 java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/java/KernelFunctionYaml_Example.java create mode 100644 java/samples/sample-code/src/main/resources/com/microsoft/semantickernel/samples/syntaxexamples/java/GenerateStory.yaml create mode 100644 java/samples/sample-code/src/main/resources/com/microsoft/semantickernel/samples/syntaxexamples/java/GenerateStoryHandlebars.yaml create mode 100644 java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/TextContentVariableContextVariableTypeConverter.java delete mode 100644 java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionFactory.java delete mode 100644 java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSupplier.java delete mode 100644 java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/StreamingChatMessageContent.java create mode 100644 java/semantickernel-api/src/test/java/com/microsoft/semantickernel/contextvariables/converters/ContextVariableTypeConverterTest.java diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/OpenAIRequestSettings.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/OpenAIRequestSettings.java index 5be4ff9640..6a1aabf917 100644 --- a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/OpenAIRequestSettings.java +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/OpenAIRequestSettings.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.aiservices.openai; import com.azure.core.http.HttpHeaderName; diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatCompletion.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatCompletion.java index 493416b1d6..2f06787e9d 100644 --- a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatCompletion.java +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatCompletion.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.aiservices.openai.chatcompletion; import com.azure.ai.openai.OpenAIAsyncClient; @@ -110,7 +111,7 @@ public class OpenAIChatCompletion implements ChatCompletionService { if (kernel != null) { kernel.getPlugins() .forEach(plugin -> plugin.getFunctions().forEach((name, function) -> functions - .add(new OpenAIFunction(function.getMetadata(), plugin.getName())))); + .add(OpenAIFunction.build(function.getMetadata(), plugin.getName())))); } // Create copy to avoid reactor exceptions when updating request messages internally diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatResponse.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatResponse.java index aed49c5e42..3e1df267a5 100644 --- a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatResponse.java +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatResponse.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.aiservices.openai.chatcompletion; import java.util.List; diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIFunction.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIFunction.java index bdb88ae31d..c81f0c1c71 100644 --- a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIFunction.java +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIFunction.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.aiservices.openai.chatcompletion; import com.azure.ai.openai.models.FunctionDefinition; @@ -9,20 +10,32 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionMetadata; import com.microsoft.semantickernel.semanticfunctions.KernelParameterMetadata; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.annotation.Nonnull; import javax.annotation.Nullable; class OpenAIFunction { + private final String pluginName; private final String name; private final FunctionDefinition functionDefinition; - public OpenAIFunction(KernelFunctionMetadata metadata, String pluginName) { - this.name = metadata.getName(); + protected OpenAIFunction( + @Nonnull String name, + @Nonnull String pluginName, + @Nonnull FunctionDefinition functionDefinition) { + this.name = name; this.pluginName = pluginName; - this.functionDefinition = toFunctionDefinition(metadata, pluginName); + this.functionDefinition = functionDefinition; + } + + public static OpenAIFunction build(KernelFunctionMetadata metadata, String pluginName) { + String name = metadata.getName(); + FunctionDefinition functionDefinition = toFunctionDefinition(metadata, pluginName); + return new OpenAIFunction(name, pluginName, functionDefinition); } public String getName() { @@ -38,7 +51,8 @@ class OpenAIFunction { } /** - * Gets the separator used between the plugin name and the function name, if a plugin name is present. + * Gets the separator used between the plugin name and the function name, if a plugin name is + * present. * * @return The separator used between the plugin name and the function name. */ @@ -58,7 +72,8 @@ class OpenAIFunction { } /** - * Converts a KernelFunctionMetadata representation to the SDK's FunctionDefinition representation. + * Converts a KernelFunctionMetadata representation to the SDK's FunctionDefinition + * representation. * * @return A FunctionDefinition containing all the function information. */ @@ -97,6 +112,7 @@ class OpenAIFunction { } private static class OpenAIFunctionParameter { + @JsonProperty("type") private String type; @JsonProperty("required") @@ -104,17 +120,32 @@ class OpenAIFunction { @JsonProperty("properties") private Map properties; - public OpenAIFunctionParameter(String type, List required, + public OpenAIFunctionParameter( + String type, + List required, Map properties) { this.type = type; - this.required = required; - this.properties = properties; + this.required = Collections.unmodifiableList(required); + this.properties = Collections.unmodifiableMap(properties); + } + + public String getType() { + return type; + } + + public List getRequired() { + return required; + } + + public Map getProperties() { + return properties; } } private static String getSchemaForFunctionParameter(@Nullable String description) { - if (description == null) + if (description == null) { return "{\"type\":\"string\"}"; + } return String.format("{\"type\":\"string\", \"description\":\"%s\"}", description); } } diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/ParsedPrompt.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/ParsedPrompt.java index e93e83cf3b..7f49573eea 100644 --- a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/ParsedPrompt.java +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/ParsedPrompt.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.aiservices.openai.chatcompletion; import com.azure.ai.openai.models.ChatRequestMessage; diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/XMLPromptParser.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/XMLPromptParser.java index a0eaf08fc1..81af20222f 100644 --- a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/XMLPromptParser.java +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/XMLPromptParser.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.aiservices.openai.chatcompletion; import com.azure.ai.openai.models.ChatRequestMessage; diff --git a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/textcompletion/OpenAITextGenerationService.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/textcompletion/OpenAITextGenerationService.java index 569cdf73c1..2f09faf0a7 100644 --- a/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/textcompletion/OpenAITextGenerationService.java +++ b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/textcompletion/OpenAITextGenerationService.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.aiservices.openai.textcompletion; import com.azure.ai.openai.OpenAIAsyncClient; diff --git a/java/api-test/integration-tests/pom.xml b/java/api-test/integration-tests/pom.xml index 381e68e863..ce789b6331 100644 --- a/java/api-test/integration-tests/pom.xml +++ b/java/api-test/integration-tests/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 diff --git a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/WireMockUtil.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/WireMockUtil.java deleted file mode 100644 index 89fa87c67a..0000000000 --- a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/WireMockUtil.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.microsoft.semantickernel.syntaxexamples; - -import com.github.tomakehurst.wiremock.client.WireMock; -import com.github.tomakehurst.wiremock.matching.RegexPattern; -import com.github.tomakehurst.wiremock.matching.UrlPathPattern; - -public class WireMockUtil { - - public static void mockCompletionResponse( - String regexMatcher, - String response) { - String body = """ - { - "id": "1", - "object": "text_completion", - "created": 1589478378, - "model": "text-davinci-003", - "system_fingerprint": "fp_44709d6fb", - "choices": [ - { - "text": "%s", - "index": 0, - "logprobs": null, - "finish_reason": "length" - } - ], - "usage": { - "prompt_tokens": 1, - "completion_tokens": 2, - "total_tokens": 3 - } - } - """ - .formatted(response); - - WireMock.reset(); - WireMock.stubFor(WireMock - .post(new UrlPathPattern( - new RegexPattern("/openai/deployments/text-davinci-003/completions"), true)) - .withRequestBody(WireMock.matching(".*" + regexMatcher + ".*")) - .willReturn(WireMock.ok() - .withBody(body))); - } - -} diff --git a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/Example01NativeFunctionsTest.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example01NativeFunctionsTest.java similarity index 90% rename from java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/Example01NativeFunctionsTest.java rename to java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example01NativeFunctionsTest.java index 16b82e7e8a..bdb24f9296 100644 --- a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/Example01NativeFunctionsTest.java +++ b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example01NativeFunctionsTest.java @@ -1,6 +1,5 @@ // Copyright (c) Microsoft. All rights reserved. - -package com.microsoft.semantickernel.syntaxexamples; +package com.microsoft.semantickernel.tests; import com.microsoft.semantickernel.plugins.text.TextPlugin; import org.junit.jupiter.api.Assertions; diff --git a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/Example03_ArgumentsTest.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example03_ArgumentsTest.java similarity index 96% rename from java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/Example03_ArgumentsTest.java rename to java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example03_ArgumentsTest.java index 745e9ecfd4..de86e82f8c 100644 --- a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/Example03_ArgumentsTest.java +++ b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example03_ArgumentsTest.java @@ -1,12 +1,12 @@ // Copyright (c) Microsoft. All rights reserved. -package com.microsoft.semantickernel.syntaxexamples; +package com.microsoft.semantickernel.tests; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.orchestration.FunctionResult; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.plugin.KernelPlugin; import com.microsoft.semantickernel.plugin.KernelPluginFactory; import com.microsoft.semantickernel.samples.syntaxexamples.Example03_Arguments.StaticTextPlugin; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/Example05_InlineFunctionDefinitionTest.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example05_InlineFunctionDefinitionTest.java similarity index 98% rename from java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/Example05_InlineFunctionDefinitionTest.java rename to java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example05_InlineFunctionDefinitionTest.java index 9a7e6bbb78..135a927f36 100644 --- a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/Example05_InlineFunctionDefinitionTest.java +++ b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example05_InlineFunctionDefinitionTest.java @@ -1,5 +1,5 @@ // Copyright (c) Microsoft. All rights reserved. -package com.microsoft.semantickernel.syntaxexamples; +package com.microsoft.semantickernel.tests; import com.azure.ai.openai.OpenAIAsyncClient; import com.azure.ai.openai.OpenAIClientBuilder; @@ -7,9 +7,9 @@ import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; import com.github.tomakehurst.wiremock.junit5.WireMockTest; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.orchestration.FunctionResult; +import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; -import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; import com.microsoft.semantickernel.services.textcompletion.TextGenerationService; import java.time.Instant; diff --git a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/KernelHooksTest.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/KernelHooksTest.java new file mode 100644 index 0000000000..a098268c22 --- /dev/null +++ b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/KernelHooksTest.java @@ -0,0 +1,103 @@ +// Copyright (c) Microsoft. All rights reserved. +package com.microsoft.semantickernel.tests; + +import com.azure.ai.openai.OpenAIAsyncClient; +import com.azure.ai.openai.OpenAIClientBuilder; +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; +import com.github.tomakehurst.wiremock.junit5.WireMockTest; +import com.microsoft.semantickernel.Kernel; +import com.microsoft.semantickernel.Kernel.Builder; +import com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatCompletion; +import com.microsoft.semantickernel.hooks.KernelHook.FunctionInvokedHook; +import com.microsoft.semantickernel.hooks.KernelHook.FunctionInvokingHook; +import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; +import com.microsoft.semantickernel.semanticfunctions.KernelFunction; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; +import com.microsoft.semantickernel.semanticfunctions.OutputVariable; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; +import java.util.concurrent.atomic.AtomicBoolean; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +@WireMockTest +public class KernelHooksTest { + + private static Builder getKernelBuilder(WireMockRuntimeInfo wmRuntimeInfo) { + final OpenAIAsyncClient client = new OpenAIClientBuilder() + .endpoint("http://localhost:" + wmRuntimeInfo.getHttpPort()) + .buildAsyncClient(); + + ChatCompletionService openAIChatCompletion = OpenAIChatCompletion.builder() + .withModelId("text-davinci-003") + .withOpenAIAsyncClient(client) + .build(); + + return Kernel.builder() + .withAIService(ChatCompletionService.class, openAIChatCompletion); + } + + @Test + public void getUsageAsync(WireMockRuntimeInfo wmRuntimeInfo) { + WireMockUtil.mockChatCompletionResponse("Write a random paragraph about", "a-response"); + Kernel kernel = getKernelBuilder(wmRuntimeInfo).build(); + + System.out.println("\n======== Get Usage Data ========\n"); + + // Initialize prompt + String functionPrompt = "Write a random paragraph about: {{$input}}."; + + KernelFunction excuseFunction = KernelFunctionFromPrompt.builder() + .withTemplate(functionPrompt) + .withName("Excuse") + .withDefaultExecutionSettings(PromptExecutionSettings + .builder() + .withMaxTokens(100) + .withTemperature(0.4) + .withTopP(1) + .build()) + .withOutputVariable(new OutputVariable("result", "java.lang.String")) + .build(); + + AtomicBoolean preHookTriggered = new AtomicBoolean(false); + + FunctionInvokingHook preHook = event -> { + preHookTriggered.set(true); + return event; + }; + + AtomicBoolean removedPreExecutionHandlerTriggered = new AtomicBoolean(false); + + FunctionInvokingHook removedPreExecutionHandler = event -> { + removedPreExecutionHandlerTriggered.set(true); + return event; + }; + + AtomicBoolean postExecutionHandlerTriggered = new AtomicBoolean(false); + + FunctionInvokedHook postExecutionHandler = event -> { + postExecutionHandlerTriggered.set(true); + return event; + }; + + kernel.getGlobalKernelHooks().addHook(preHook); + + // Demonstrate pattern for removing a handler. + kernel.getGlobalKernelHooks().addHook("pre-invoke-removed", removedPreExecutionHandler); + kernel.getGlobalKernelHooks().removeHook("pre-invoke-removed"); + kernel.getGlobalKernelHooks().addHook(postExecutionHandler); + + kernel.invokeAsync( + excuseFunction) + .withArguments( + KernelFunctionArguments + .builder() + .withVariable("input", "I missed the F1 final race") + .build()) + .block(); + + Assertions.assertTrue(preHookTriggered.get()); + Assertions.assertFalse(removedPreExecutionHandlerTriggered.get()); + Assertions.assertTrue(postExecutionHandlerTriggered.get()); + } +} diff --git a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/WireMockUtil.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/WireMockUtil.java new file mode 100644 index 0000000000..5bf39de86a --- /dev/null +++ b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/WireMockUtil.java @@ -0,0 +1,125 @@ +// Copyright (c) Microsoft. All rights reserved. +package com.microsoft.semantickernel.tests; + +import com.github.tomakehurst.wiremock.client.WireMock; +import com.github.tomakehurst.wiremock.matching.RegexPattern; +import com.github.tomakehurst.wiremock.matching.UrlPathPattern; + +public class WireMockUtil { + + public static void mockCompletionResponse( + String regexMatcher, + String response) { + String body = """ + { + "id": "1", + "object": "text_completion", + "created": 1589478378, + "model": "text-davinci-003", + "system_fingerprint": "fp_44709d6fb", + "choices": [ + { + "text": "%s", + "index": 0, + "logprobs": null, + "finish_reason": "length" + } + ], + "usage": { + "prompt_tokens": 1, + "completion_tokens": 2, + "total_tokens": 3 + } + } + """ + .formatted(response); + + WireMock.reset(); + WireMock.stubFor(WireMock + .post(new UrlPathPattern( + new RegexPattern("/openai/deployments/text-davinci-003/completions"), true)) + .withRequestBody(WireMock.matching(".*" + regexMatcher + ".*")) + .willReturn(WireMock.ok() + .withBody(body))); + } + + public static void mockChatCompletionResponse( + String regexMatcher, + String response) { + String body = """ + { + "choices" : [ + { + "content_filter_results" : { + "hate" : { + "filtered" : false, + "severity" : "safe" + }, + "self_harm" : { + "filtered" : false, + "severity" : "safe" + }, + "sexual" : { + "filtered" : false, + "severity" : "safe" + }, + "violence" : { + "filtered" : false, + "severity" : "safe" + } + }, + "finish_reason" : "length", + "index" : 0, + "message" : { + "content" : "%s", + "role" : "assistant" + } + } + ], + "created" : 1707253019, + "id" : "chatcmpl-xxx", + "model" : "gpt-35-turbo", + "object" : "chat.completion", + "prompt_filter_results" : [ + { + "content_filter_results" : { + "hate" : { + "filtered" : false, + "severity" : "safe" + }, + "self_harm" : { + "filtered" : false, + "severity" : "safe" + }, + "sexual" : { + "filtered" : false, + "severity" : "safe" + }, + "violence" : { + "filtered" : false, + "severity" : "safe" + } + }, + "prompt_index" : 0 + } + ], + "usage" : { + "completion_tokens" : 256, + "prompt_tokens" : 69, + "total_tokens" : 325 + } + } + + """ + .formatted(response); + + WireMock.reset(); + WireMock.stubFor(WireMock + .post(new UrlPathPattern( + new RegexPattern("/openai/deployments/text-davinci-003/chat/completions"), true)) + .withRequestBody(WireMock.matching(".*" + regexMatcher + ".*")) + .willReturn(WireMock.ok() + .withBody(body))); + } + +} diff --git a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/WiremockExamplesIT.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/WiremockExamplesIT.java similarity index 98% rename from java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/WiremockExamplesIT.java rename to java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/WiremockExamplesIT.java index d896595fc2..cf3eeaacab 100644 --- a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/WiremockExamplesIT.java +++ b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/WiremockExamplesIT.java @@ -1,4 +1,5 @@ -package com.microsoft.semantickernel.syntaxexamples; +// Copyright (c) Microsoft. All rights reserved. +package com.microsoft.semantickernel.tests; import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; diff --git a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/WiremockRecord.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/WiremockRecord.java similarity index 97% rename from java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/WiremockRecord.java rename to java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/WiremockRecord.java index 4fa53d26f0..90a02f11c9 100644 --- a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/WiremockRecord.java +++ b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/WiremockRecord.java @@ -1,4 +1,5 @@ -package com.microsoft.semantickernel.syntaxexamples; +// Copyright (c) Microsoft. All rights reserved. +package com.microsoft.semantickernel.tests; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/java/api-test/integration-tests/src/test/resources/log4j2.xml b/java/api-test/integration-tests/src/test/resources/log4j2.xml index 50a638f0dc..02e288f800 100644 --- a/java/api-test/integration-tests/src/test/resources/log4j2.xml +++ b/java/api-test/integration-tests/src/test/resources/log4j2.xml @@ -6,7 +6,7 @@ - + diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-45379a29-d6d3-4613-a885-b30ccaaa6db0.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-45379a29-d6d3-4613-a885-b30ccaaa6db0.json index 86f3280d54..7026d494b6 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-45379a29-d6d3-4613-a885-b30ccaaa6db0.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-45379a29-d6d3-4613-a885-b30ccaaa6db0.json @@ -1,23 +1,23 @@ { - "id" : "45379a29-d6d3-4613-a885-b30ccaaa6db0", - "insertionIndex" : 19, - "name" : "deployments_gpt-35-turbo-2_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian expert\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking some suggestions\"},{\"role\":\"assistant\",\"content\":\"Of course! I'd be happy to help you with some suggestions. What are you looking for?\"},{\"role\":\"user\",\"content\":\"I love history and philosophy, I'd like to learn something new about Greece, any suggestion\"}],\"max_tokens\":256,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{\"39142\":-100,\"17422\":-100,\"35199\":-100,\"56185\":-100,\"2363\":-100,\"23763\":-100,\"35097\":-100,\"1160\":-100,\"47913\":-100,\"58162\":-100,\"1888\":-100,\"79761\":-100,\"3229\":-100,\"2536\":-100,\"12735\":-100,\"301\":-100,\"3446\":-100,\"2653\":-100,\"86831\":-100,\"56741\":-100,\"3773\":-100,\"6875\":-100,\"17649\":-100,\"5403\":-100},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"model\":\"gpt-35-turbo-2\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253019,\"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\":\"length\",\"index\":0,\"message\":{\"role\":\"assistant\",\"content\":\"52dbd293-192d-4e01-8b31-e364b11a089d\"},\"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\":69,\"completion_tokens\":256,\"total_tokens\":325}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "45379a29-d6d3-4613-a885-b30ccaaa6db0" + "id": "45379a29-d6d3-4613-a885-b30ccaaa6db0", + "insertionIndex": 19, + "name": "deployments_gpt-35-turbo-2_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian expert\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking some suggestions\"},{\"role\":\"assistant\",\"content\":\"Of course! I'd be happy to help you with some suggestions. What are you looking for?\"},{\"role\":\"user\",\"content\":\"I love history and philosophy, I'd like to learn something new about Greece, any suggestion\"}],\"max_tokens\":256,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{\"39142\":-100,\"17422\":-100,\"35199\":-100,\"56185\":-100,\"2363\":-100,\"23763\":-100,\"35097\":-100,\"1160\":-100,\"47913\":-100,\"58162\":-100,\"1888\":-100,\"79761\":-100,\"3229\":-100,\"2536\":-100,\"12735\":-100,\"301\":-100,\"3446\":-100,\"2653\":-100,\"86831\":-100,\"56741\":-100,\"3773\":-100,\"6875\":-100,\"17649\":-100,\"5403\":-100},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"model\":\"gpt-35-turbo-2\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253019,\"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\":\"length\",\"index\":0,\"message\":{\"role\":\"assistant\",\"content\":\"52dbd293-192d-4e01-8b31-e364b11a089d\"},\"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\":69,\"completion_tokens\":256,\"total_tokens\":325}}", + "headers": {}, + "status": 200 + }, + "uuid": "45379a29-d6d3-4613-a885-b30ccaaa6db0" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-686c6f9b-7c66-41af-8b9b-86e44fcdb2b1.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-686c6f9b-7c66-41af-8b9b-86e44fcdb2b1.json index 8585ebb647..1723fddb05 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-686c6f9b-7c66-41af-8b9b-86e44fcdb2b1.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-686c6f9b-7c66-41af-8b9b-86e44fcdb2b1.json @@ -1,23 +1,23 @@ { - "id" : "686c6f9b-7c66-41af-8b9b-86e44fcdb2b1", - "insertionIndex" : 20, - "name" : "deployments_gpt-35-turbo-2_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian expert\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking some suggestions\"}],\"max_tokens\":256,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{\"39142\":-100,\"17422\":-100,\"35199\":-100,\"56185\":-100,\"2363\":-100,\"23763\":-100,\"35097\":-100,\"1160\":-100,\"47913\":-100,\"58162\":-100,\"1888\":-100,\"79761\":-100,\"3229\":-100,\"2536\":-100,\"12735\":-100,\"301\":-100,\"3446\":-100,\"2653\":-100,\"86831\":-100,\"56741\":-100,\"3773\":-100,\"6875\":-100,\"17649\":-100,\"5403\":-100},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"model\":\"gpt-35-turbo-2\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253018,\"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\":\"0aaf065e-3032-4d24-8d5d-10fc6b4c7eaf\"},\"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\":23,\"completion_tokens\":20,\"total_tokens\":43}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "686c6f9b-7c66-41af-8b9b-86e44fcdb2b1" + "id": "686c6f9b-7c66-41af-8b9b-86e44fcdb2b1", + "insertionIndex": 20, + "name": "deployments_gpt-35-turbo-2_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian expert\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking some suggestions\"}],\"max_tokens\":256,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{\"39142\":-100,\"17422\":-100,\"35199\":-100,\"56185\":-100,\"2363\":-100,\"23763\":-100,\"35097\":-100,\"1160\":-100,\"47913\":-100,\"58162\":-100,\"1888\":-100,\"79761\":-100,\"3229\":-100,\"2536\":-100,\"12735\":-100,\"301\":-100,\"3446\":-100,\"2653\":-100,\"86831\":-100,\"56741\":-100,\"3773\":-100,\"6875\":-100,\"17649\":-100,\"5403\":-100},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"model\":\"gpt-35-turbo-2\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253018,\"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\":\"0aaf065e-3032-4d24-8d5d-10fc6b4c7eaf\"},\"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\":23,\"completion_tokens\":20,\"total_tokens\":43}}", + "headers": {}, + "status": 200 + }, + "uuid": "686c6f9b-7c66-41af-8b9b-86e44fcdb2b1" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-71b07779-49a8-44e5-a60b-ee5b0a3ad697.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-71b07779-49a8-44e5-a60b-ee5b0a3ad697.json index 1267c7cd2d..dd6f49b4c0 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-71b07779-49a8-44e5-a60b-ee5b0a3ad697.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-71b07779-49a8-44e5-a60b-ee5b0a3ad697.json @@ -1,25 +1,25 @@ { - "id" : "71b07779-49a8-44e5-a60b-ee5b0a3ad697", - "insertionIndex" : 7, - "name" : "deployments_gpt-35-turbo-2_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Hello AI, what can you do for me?\"}],\"model\":\"gpt-35-turbo-2\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2023-12-01-preview" - }, - "requiredScenarioState" : "scenario-4-deployments-gpt-35-turbo-2-chat-completions-2", - "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}}", - "headers" : {}, - "status" : 200 - }, - "scenarioName" : "scenario-4-deployments-gpt-35-turbo-2-chat-completions", - "uuid" : "71b07779-49a8-44e5-a60b-ee5b0a3ad697" + "id": "71b07779-49a8-44e5-a60b-ee5b0a3ad697", + "insertionIndex": 7, + "name": "deployments_gpt-35-turbo-2_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Hello AI, what can you do for me?\"}],\"model\":\"gpt-35-turbo-2\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2023-12-01-preview" + }, + "requiredScenarioState": "scenario-4-deployments-gpt-35-turbo-2-chat-completions-2", + "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}}", + "headers": {}, + "status": 200 + }, + "scenarioName": "scenario-4-deployments-gpt-35-turbo-2-chat-completions", + "uuid": "71b07779-49a8-44e5-a60b-ee5b0a3ad697" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-c9edbe4a-e60b-4796-bd01-11bafa211bab.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-c9edbe4a-e60b-4796-bd01-11bafa211bab.json index 70cf03797c..7ff593b416 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-c9edbe4a-e60b-4796-bd01-11bafa211bab.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo-2_chat_completions-c9edbe4a-e60b-4796-bd01-11bafa211bab.json @@ -1,26 +1,26 @@ { - "id" : "c9edbe4a-e60b-4796-bd01-11bafa211bab", - "insertionIndex" : 8, - "name" : "deployments_gpt-35-turbo-2_chat_completions", - "newScenarioState" : "scenario-4-deployments-gpt-35-turbo-2-chat-completions-2", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Hello AI, what can you do for me?\"}],\"model\":\"gpt-35-turbo-2\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2023-12-01-preview" - }, - "requiredScenarioState" : "Started", - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253054,\"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\":\"28eee7e9-28c5-47c7-90c5-44cef75fd582\"},\"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\":297,\"total_tokens\":314}}", - "headers" : {}, - "status" : 200 - }, - "scenarioName" : "scenario-4-deployments-gpt-35-turbo-2-chat-completions", - "uuid" : "c9edbe4a-e60b-4796-bd01-11bafa211bab" + "id": "c9edbe4a-e60b-4796-bd01-11bafa211bab", + "insertionIndex": 8, + "name": "deployments_gpt-35-turbo-2_chat_completions", + "newScenarioState": "scenario-4-deployments-gpt-35-turbo-2-chat-completions-2", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Hello AI, what can you do for me?\"}],\"model\":\"gpt-35-turbo-2\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo-2/chat/completions?api-version=2023-12-01-preview" + }, + "requiredScenarioState": "Started", + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253054,\"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\":\"28eee7e9-28c5-47c7-90c5-44cef75fd582\"},\"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\":297,\"total_tokens\":314}}", + "headers": {}, + "status": 200 + }, + "scenarioName": "scenario-4-deployments-gpt-35-turbo-2-chat-completions", + "uuid": "c9edbe4a-e60b-4796-bd01-11bafa211bab" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-093a64da-80ba-49bf-a4fd-625224d60b3a.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-093a64da-80ba-49bf-a4fd-625224d60b3a.json index cb7cd5e564..03befd18ef 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-093a64da-80ba-49bf-a4fd-625224d60b3a.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-093a64da-80ba-49bf-a4fd-625224d60b3a.json @@ -1,23 +1,23 @@ { - "id" : "093a64da-80ba-49bf-a4fd-625224d60b3a", - "insertionIndex" : 25, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"List the two planets closest to 'Jupiter', excluding moons, using bullet points.\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253000,\"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\":\"120318d5-35af-487a-b335-7fa00c5f7dd7\"},\"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\":24,\"completion_tokens\":5,\"total_tokens\":29}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "093a64da-80ba-49bf-a4fd-625224d60b3a" + "id": "093a64da-80ba-49bf-a4fd-625224d60b3a", + "insertionIndex": 25, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"List the two planets closest to 'Jupiter', excluding moons, using bullet points.\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253000,\"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\":\"120318d5-35af-487a-b335-7fa00c5f7dd7\"},\"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\":24,\"completion_tokens\":5,\"total_tokens\":29}}", + "headers": {}, + "status": 200 + }, + "uuid": "093a64da-80ba-49bf-a4fd-625224d60b3a" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-0c8046c5-74ad-4836-8aa9-09da60f367a2.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-0c8046c5-74ad-4836-8aa9-09da60f367a2.json index 22ef9679a8..8c045a0251 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-0c8046c5-74ad-4836-8aa9-09da60f367a2.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-0c8046c5-74ad-4836-8aa9-09da60f367a2.json @@ -1,23 +1,23 @@ { - "id" : "0c8046c5-74ad-4836-8aa9-09da60f367a2", - "insertionIndex" : 12, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a paragraph about hats\"},{\"role\":\"system\",\"content\":\"Use upper case text when responding to the prompt.\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-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}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "0c8046c5-74ad-4836-8aa9-09da60f367a2" + "id": "0c8046c5-74ad-4836-8aa9-09da60f367a2", + "insertionIndex": 12, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a paragraph about hats\"},{\"role\":\"system\",\"content\":\"Use upper case text when responding to the prompt.\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-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}}", + "headers": {}, + "status": 200 + }, + "uuid": "0c8046c5-74ad-4836-8aa9-09da60f367a2" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-252c54f4-1111-467b-b028-7687e4ed5021.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-252c54f4-1111-467b-b028-7687e4ed5021.json index 43bda29117..363c24b77b 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-252c54f4-1111-467b-b028-7687e4ed5021.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-252c54f4-1111-467b-b028-7687e4ed5021.json @@ -1,26 +1,26 @@ { - "id" : "252c54f4-1111-467b-b028-7687e4ed5021", - "insertionIndex" : 27, - "name" : "deployments_gpt-35-turbo_chat_completions", - "newScenarioState" : "scenario-6-deployments-gpt-35-turbo-chat-completions-2", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian, expert about books\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking for book suggestions\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "requiredScenarioState" : "Started", - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707252992,\"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\":\"7d312938-df92-46bf-8729-8d7b92ddb026\"},\"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\":27,\"completion_tokens\":76,\"total_tokens\":103}}", - "headers" : {}, - "status" : 200 - }, - "scenarioName" : "scenario-6-deployments-gpt-35-turbo-chat-completions", - "uuid" : "252c54f4-1111-467b-b028-7687e4ed5021" + "id": "252c54f4-1111-467b-b028-7687e4ed5021", + "insertionIndex": 27, + "name": "deployments_gpt-35-turbo_chat_completions", + "newScenarioState": "scenario-6-deployments-gpt-35-turbo-chat-completions-2", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian, expert about books\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking for book suggestions\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "requiredScenarioState": "Started", + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707252992,\"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\":\"7d312938-df92-46bf-8729-8d7b92ddb026\"},\"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\":27,\"completion_tokens\":76,\"total_tokens\":103}}", + "headers": {}, + "status": 200 + }, + "scenarioName": "scenario-6-deployments-gpt-35-turbo-chat-completions", + "uuid": "252c54f4-1111-467b-b028-7687e4ed5021" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-270f9641-5867-4ca4-a738-d3b1d18faefb.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-270f9641-5867-4ca4-a738-d3b1d18faefb.json index d5394f0805..a140521131 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-270f9641-5867-4ca4-a738-d3b1d18faefb.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-270f9641-5867-4ca4-a738-d3b1d18faefb.json @@ -1,25 +1,25 @@ { - "id" : "270f9641-5867-4ca4-a738-d3b1d18faefb", - "insertionIndex" : 3, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"What is Seattle?\"},{\"role\":\"system\",\"content\":\"Respond with JSON.\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "requiredScenarioState" : "scenario-2-deployments-gpt-35-turbo-chat-completions-2", - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253067,\"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\":\"57e7d767-3d91-4622-8571-84710dd2e7ff\"},\"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\":19,\"completion_tokens\":151,\"total_tokens\":170}}", - "headers" : {}, - "status" : 200 - }, - "scenarioName" : "scenario-2-deployments-gpt-35-turbo-chat-completions", - "uuid" : "270f9641-5867-4ca4-a738-d3b1d18faefb" + "id": "270f9641-5867-4ca4-a738-d3b1d18faefb", + "insertionIndex": 3, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"What is Seattle?\"},{\"role\":\"system\",\"content\":\"Respond with JSON.\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "requiredScenarioState": "scenario-2-deployments-gpt-35-turbo-chat-completions-2", + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253067,\"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\":\"57e7d767-3d91-4622-8571-84710dd2e7ff\"},\"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\":19,\"completion_tokens\":151,\"total_tokens\":170}}", + "headers": {}, + "status": 200 + }, + "scenarioName": "scenario-2-deployments-gpt-35-turbo-chat-completions", + "uuid": "270f9641-5867-4ca4-a738-d3b1d18faefb" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-364efff1-b5dd-4796-8c01-936b19045de2.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-364efff1-b5dd-4796-8c01-936b19045de2.json index 7555075aa1..f7d797c812 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-364efff1-b5dd-4796-8c01-936b19045de2.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-364efff1-b5dd-4796-8c01-936b19045de2.json @@ -1,26 +1,26 @@ { - "id" : "364efff1-b5dd-4796-8c01-936b19045de2", - "insertionIndex" : 11, - "name" : "deployments_gpt-35-turbo_chat_completions", - "newScenarioState" : "scenario-5-deployments-gpt-35-turbo-chat-completions-2", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Hello AI, what can you do for me?\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "requiredScenarioState" : "Started", - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253042,\"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\":\"2fb33955-441a-429d-bbf6-603e449d21b6\"},\"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\":197,\"total_tokens\":214}}", - "headers" : {}, - "status" : 200 - }, - "scenarioName" : "scenario-5-deployments-gpt-35-turbo-chat-completions", - "uuid" : "364efff1-b5dd-4796-8c01-936b19045de2" + "id": "364efff1-b5dd-4796-8c01-936b19045de2", + "insertionIndex": 11, + "name": "deployments_gpt-35-turbo_chat_completions", + "newScenarioState": "scenario-5-deployments-gpt-35-turbo-chat-completions-2", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Hello AI, what can you do for me?\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "requiredScenarioState": "Started", + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253042,\"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\":\"2fb33955-441a-429d-bbf6-603e449d21b6\"},\"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\":197,\"total_tokens\":214}}", + "headers": {}, + "status": 200 + }, + "scenarioName": "scenario-5-deployments-gpt-35-turbo-chat-completions", + "uuid": "364efff1-b5dd-4796-8c01-936b19045de2" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-36d8c189-3b93-4a19-b92f-8effb670f75a.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-36d8c189-3b93-4a19-b92f-8effb670f75a.json index 550924807c..07c34adc1c 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-36d8c189-3b93-4a19-b92f-8effb670f75a.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-36d8c189-3b93-4a19-b92f-8effb670f75a.json @@ -1,23 +1,23 @@ { - "id" : "36d8c189-3b93-4a19-b92f-8effb670f75a", - "insertionIndex" : 26, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian, expert about books\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking for book suggestions\"},{\"role\":\"assistant\",\"content\":\"Certainly! I'd be happy to help you find some book suggestions. Could you please provide me with more information about what kind of books you enjoy? For example, do you have any favorite genres or authors? Are you looking for fiction or non-fiction books? Any specific themes or topics you're interested in? The more details you can provide, the better I can assist you.\"},{\"role\":\"user\",\"content\":\"I love history and philosophy, I'd like to learn something new about Greece, any suggestion\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707252994,\"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\":\"ace2c274-2932-4ba7-b132-6ec80ad55698\"},\"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\":129,\"completion_tokens\":308,\"total_tokens\":437}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "36d8c189-3b93-4a19-b92f-8effb670f75a" + "id": "36d8c189-3b93-4a19-b92f-8effb670f75a", + "insertionIndex": 26, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian, expert about books\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking for book suggestions\"},{\"role\":\"assistant\",\"content\":\"Certainly! I'd be happy to help you find some book suggestions. Could you please provide me with more information about what kind of books you enjoy? For example, do you have any favorite genres or authors? Are you looking for fiction or non-fiction books? Any specific themes or topics you're interested in? The more details you can provide, the better I can assist you.\"},{\"role\":\"user\",\"content\":\"I love history and philosophy, I'd like to learn something new about Greece, any suggestion\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707252994,\"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\":\"ace2c274-2932-4ba7-b132-6ec80ad55698\"},\"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\":129,\"completion_tokens\":308,\"total_tokens\":437}}", + "headers": {}, + "status": 200 + }, + "uuid": "36d8c189-3b93-4a19-b92f-8effb670f75a" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-3708b848-8dbe-4c2d-a057-04abcee675c0.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-3708b848-8dbe-4c2d-a057-04abcee675c0.json index 08b6b22e69..ffec06181e 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-3708b848-8dbe-4c2d-a057-04abcee675c0.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-3708b848-8dbe-4c2d-a057-04abcee675c0.json @@ -1,23 +1,23 @@ { - "id" : "3708b848-8dbe-4c2d-a057-04abcee675c0", - "insertionIndex" : 22, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Hi, give me 5 book suggestions about: travel\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253005,\"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\":\"67c9623d-7f83-432b-89e5-40ffb3c343c2\"},\"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\":18,\"completion_tokens\":281,\"total_tokens\":299}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "3708b848-8dbe-4c2d-a057-04abcee675c0" + "id": "3708b848-8dbe-4c2d-a057-04abcee675c0", + "insertionIndex": 22, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Hi, give me 5 book suggestions about: travel\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253005,\"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\":\"67c9623d-7f83-432b-89e5-40ffb3c343c2\"},\"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\":18,\"completion_tokens\":281,\"total_tokens\":299}}", + "headers": {}, + "status": 200 + }, + "uuid": "3708b848-8dbe-4c2d-a057-04abcee675c0" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-4939b782-4212-435b-8d7d-c3454fe0200c.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-4939b782-4212-435b-8d7d-c3454fe0200c.json index a31f9d20b6..d89da3ea54 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-4939b782-4212-435b-8d7d-c3454fe0200c.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-4939b782-4212-435b-8d7d-c3454fe0200c.json @@ -1,23 +1,23 @@ { - "id" : "4939b782-4212-435b-8d7d-c3454fe0200c", - "insertionIndex" : 16, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a random paragraph about: I missed the F1 final race in the style of Seinfeld.\\nUSE SHORT, CLEAR, COMPLETE SENTENCES.\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253027,\"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\":\"8e81b11a-5cd0-40f1-a80d-641ec60a3bc4\"},\"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\":36,\"completion_tokens\":336,\"total_tokens\":372}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "4939b782-4212-435b-8d7d-c3454fe0200c" + "id": "4939b782-4212-435b-8d7d-c3454fe0200c", + "insertionIndex": 16, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a random paragraph about: I missed the F1 final race in the style of Seinfeld.\\nUSE SHORT, CLEAR, COMPLETE SENTENCES.\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253027,\"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\":\"8e81b11a-5cd0-40f1-a80d-641ec60a3bc4\"},\"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\":36,\"completion_tokens\":336,\"total_tokens\":372}}", + "headers": {}, + "status": 200 + }, + "uuid": "4939b782-4212-435b-8d7d-c3454fe0200c" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-5d78a6d8-abca-488a-8752-599051a3e352.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-5d78a6d8-abca-488a-8752-599051a3e352.json index 35eef27ea8..d111644847 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-5d78a6d8-abca-488a-8752-599051a3e352.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-5d78a6d8-abca-488a-8752-599051a3e352.json @@ -1,26 +1,26 @@ { - "id" : "5d78a6d8-abca-488a-8752-599051a3e352", - "insertionIndex" : 4, - "name" : "deployments_gpt-35-turbo_chat_completions", - "newScenarioState" : "scenario-2-deployments-gpt-35-turbo-chat-completions-2", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"What is Seattle?\"},{\"role\":\"system\",\"content\":\"Respond with JSON.\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "requiredScenarioState" : "Started", - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253065,\"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\":\"28374b87-21d3-4506-9569-3c7c4aaf9052\"},\"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\":19,\"completion_tokens\":91,\"total_tokens\":110}}", - "headers" : {}, - "status" : 200 - }, - "scenarioName" : "scenario-2-deployments-gpt-35-turbo-chat-completions", - "uuid" : "5d78a6d8-abca-488a-8752-599051a3e352" + "id": "5d78a6d8-abca-488a-8752-599051a3e352", + "insertionIndex": 4, + "name": "deployments_gpt-35-turbo_chat_completions", + "newScenarioState": "scenario-2-deployments-gpt-35-turbo-chat-completions-2", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"What is Seattle?\"},{\"role\":\"system\",\"content\":\"Respond with JSON.\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "requiredScenarioState": "Started", + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253065,\"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\":\"28374b87-21d3-4506-9569-3c7c4aaf9052\"},\"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\":19,\"completion_tokens\":91,\"total_tokens\":110}}", + "headers": {}, + "status": 200 + }, + "scenarioName": "scenario-2-deployments-gpt-35-turbo-chat-completions", + "uuid": "5d78a6d8-abca-488a-8752-599051a3e352" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-604be5a5-3e55-44ee-a85f-9d9e63b1763a.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-604be5a5-3e55-44ee-a85f-9d9e63b1763a.json index fd64876e37..17c74af8bd 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-604be5a5-3e55-44ee-a85f-9d9e63b1763a.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-604be5a5-3e55-44ee-a85f-9d9e63b1763a.json @@ -1,26 +1,26 @@ { - "id" : "604be5a5-3e55-44ee-a85f-9d9e63b1763a", - "insertionIndex" : 2, - "name" : "deployments_gpt-35-turbo_chat_completions", - "newScenarioState" : "scenario-1-deployments-gpt-35-turbo-chat-completions-2", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Hello AI, my name is Bob. What is the origin of my name?\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "requiredScenarioState" : "Started", - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253070,\"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\":\"aed93937-6747-4092-8b1d-6a3345a63197\"},\"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\":23,\"completion_tokens\":75,\"total_tokens\":98}}", - "headers" : {}, - "status" : 200 - }, - "scenarioName" : "scenario-1-deployments-gpt-35-turbo-chat-completions", - "uuid" : "604be5a5-3e55-44ee-a85f-9d9e63b1763a" + "id": "604be5a5-3e55-44ee-a85f-9d9e63b1763a", + "insertionIndex": 2, + "name": "deployments_gpt-35-turbo_chat_completions", + "newScenarioState": "scenario-1-deployments-gpt-35-turbo-chat-completions-2", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Hello AI, my name is Bob. What is the origin of my name?\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "requiredScenarioState": "Started", + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253070,\"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\":\"aed93937-6747-4092-8b1d-6a3345a63197\"},\"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\":23,\"completion_tokens\":75,\"total_tokens\":98}}", + "headers": {}, + "status": 200 + }, + "scenarioName": "scenario-1-deployments-gpt-35-turbo-chat-completions", + "uuid": "604be5a5-3e55-44ee-a85f-9d9e63b1763a" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-70facef2-7e60-49d5-8009-b38915a1b355.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-70facef2-7e60-49d5-8009-b38915a1b355.json index 885e448446..f04494d6ad 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-70facef2-7e60-49d5-8009-b38915a1b355.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-70facef2-7e60-49d5-8009-b38915a1b355.json @@ -1,23 +1,23 @@ { - "id" : "70facef2-7e60-49d5-8009-b38915a1b355", - "insertionIndex" : 23, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian, expert about books\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking for book suggestions\"},{\"role\":\"assistant\",\"content\":\"Of course! I'd be happy to help you find some book suggestions. What genre or type of book are you interested in?\"},{\"role\":\"user\",\"content\":\"I love history and philosophy, I'd like to learn something new about Greece, any suggestion\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253001,\"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\":\"6fe0e3aa-5670-435c-9c90-976f97ce9c4c\"},\"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\":79,\"completion_tokens\":276,\"total_tokens\":355}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "70facef2-7e60-49d5-8009-b38915a1b355" + "id": "70facef2-7e60-49d5-8009-b38915a1b355", + "insertionIndex": 23, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian, expert about books\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking for book suggestions\"},{\"role\":\"assistant\",\"content\":\"Of course! I'd be happy to help you find some book suggestions. What genre or type of book are you interested in?\"},{\"role\":\"user\",\"content\":\"I love history and philosophy, I'd like to learn something new about Greece, any suggestion\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253001,\"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\":\"6fe0e3aa-5670-435c-9c90-976f97ce9c4c\"},\"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\":79,\"completion_tokens\":276,\"total_tokens\":355}}", + "headers": {}, + "status": 200 + }, + "uuid": "70facef2-7e60-49d5-8009-b38915a1b355" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-779728d0-3cfa-4374-aa56-7038de43449e.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-779728d0-3cfa-4374-aa56-7038de43449e.json index 9c64264459..8b839fd51b 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-779728d0-3cfa-4374-aa56-7038de43449e.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-779728d0-3cfa-4374-aa56-7038de43449e.json @@ -1,25 +1,25 @@ { - "id" : "779728d0-3cfa-4374-aa56-7038de43449e", - "insertionIndex" : 24, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian, expert about books\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking for book suggestions\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "requiredScenarioState" : "scenario-6-deployments-gpt-35-turbo-chat-completions-2", - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253000,\"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\":\"4772ff60-75e0-46bc-8224-6ec8ba5b9be1\"},\"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\":27,\"completion_tokens\":26,\"total_tokens\":53}}", - "headers" : {}, - "status" : 200 - }, - "scenarioName" : "scenario-6-deployments-gpt-35-turbo-chat-completions", - "uuid" : "779728d0-3cfa-4374-aa56-7038de43449e" + "id": "779728d0-3cfa-4374-aa56-7038de43449e", + "insertionIndex": 24, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian, expert about books\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking for book suggestions\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "requiredScenarioState": "scenario-6-deployments-gpt-35-turbo-chat-completions-2", + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253000,\"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\":\"4772ff60-75e0-46bc-8224-6ec8ba5b9be1\"},\"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\":27,\"completion_tokens\":26,\"total_tokens\":53}}", + "headers": {}, + "status": 200 + }, + "scenarioName": "scenario-6-deployments-gpt-35-turbo-chat-completions", + "uuid": "779728d0-3cfa-4374-aa56-7038de43449e" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-79f4220d-21e6-43e2-8a2e-6a281fcbfea9.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-79f4220d-21e6-43e2-8a2e-6a281fcbfea9.json index d61f14e096..ff6af76b9f 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-79f4220d-21e6-43e2-8a2e-6a281fcbfea9.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-79f4220d-21e6-43e2-8a2e-6a281fcbfea9.json @@ -1,23 +1,23 @@ { - "id" : "79f4220d-21e6-43e2-8a2e-6a281fcbfea9", - "insertionIndex" : 21, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian, expert about books\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking for 3 different book suggestions about sci-fi\"}],\"max_tokens\":1024,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":2,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253010,\"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\":\"4949cf23-7039-4226-be78-8dd8c6e678e3\"},\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}}},{\"finish_reason\":\"stop\",\"index\":1,\"message\":{\"role\":\"assistant\",\"content\":\"7c66554a-3003-467d-9ce7-9bf7e22ab921\"},\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"low\"}}}],\"usage\":{\"prompt_tokens\":33,\"completion_tokens\":640,\"total_tokens\":673}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "79f4220d-21e6-43e2-8a2e-6a281fcbfea9" + "id": "79f4220d-21e6-43e2-8a2e-6a281fcbfea9", + "insertionIndex": 21, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"assistant\",\"content\":\"You are a librarian, expert about books\"},{\"role\":\"user\",\"content\":\"Hi, I'm looking for 3 different book suggestions about sci-fi\"}],\"max_tokens\":1024,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":2,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253010,\"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\":\"4949cf23-7039-4226-be78-8dd8c6e678e3\"},\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"safe\"}}},{\"finish_reason\":\"stop\",\"index\":1,\"message\":{\"role\":\"assistant\",\"content\":\"7c66554a-3003-467d-9ce7-9bf7e22ab921\"},\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"low\"}}}],\"usage\":{\"prompt_tokens\":33,\"completion_tokens\":640,\"total_tokens\":673}}", + "headers": {}, + "status": 200 + }, + "uuid": "79f4220d-21e6-43e2-8a2e-6a281fcbfea9" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-8ccdcbb2-4a82-47c4-a3da-93041481ce06.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-8ccdcbb2-4a82-47c4-a3da-93041481ce06.json index d3f82e5c18..a5a05ec53c 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-8ccdcbb2-4a82-47c4-a3da-93041481ce06.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-8ccdcbb2-4a82-47c4-a3da-93041481ce06.json @@ -1,23 +1,23 @@ { - "id" : "8ccdcbb2-4a82-47c4-a3da-93041481ce06", - "insertionIndex" : 18, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a haiku about the following: Harry Potter\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253023,\"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\":\"9043bdfe-acca-4068-8880-31f68015d800\"},\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"low\"}}}],\"usage\":{\"prompt_tokens\":17,\"completion_tokens\":18,\"total_tokens\":35}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "8ccdcbb2-4a82-47c4-a3da-93041481ce06" + "id": "8ccdcbb2-4a82-47c4-a3da-93041481ce06", + "insertionIndex": 18, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a haiku about the following: Harry Potter\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253023,\"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\":\"9043bdfe-acca-4068-8880-31f68015d800\"},\"content_filter_results\":{\"hate\":{\"filtered\":false,\"severity\":\"safe\"},\"self_harm\":{\"filtered\":false,\"severity\":\"safe\"},\"sexual\":{\"filtered\":false,\"severity\":\"safe\"},\"violence\":{\"filtered\":false,\"severity\":\"low\"}}}],\"usage\":{\"prompt_tokens\":17,\"completion_tokens\":18,\"total_tokens\":35}}", + "headers": {}, + "status": 200 + }, + "uuid": "8ccdcbb2-4a82-47c4-a3da-93041481ce06" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-bcdbf876-8b4c-4de1-99b4-deaad761fdbe.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-bcdbf876-8b4c-4de1-99b4-deaad761fdbe.json index 5115cc1100..2883487c7a 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-bcdbf876-8b4c-4de1-99b4-deaad761fdbe.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-bcdbf876-8b4c-4de1-99b4-deaad761fdbe.json @@ -1,23 +1,23 @@ { - "id" : "bcdbf876-8b4c-4de1-99b4-deaad761fdbe", - "insertionIndex" : 14, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a phrase with Cancellation.\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253036,\"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\":\"49ec813d-2f20-4424-9a3f-b6ead6b4894f\"},\"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\":14,\"completion_tokens\":12,\"total_tokens\":26}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "bcdbf876-8b4c-4de1-99b4-deaad761fdbe" + "id": "bcdbf876-8b4c-4de1-99b4-deaad761fdbe", + "insertionIndex": 14, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a phrase with Cancellation.\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253036,\"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\":\"49ec813d-2f20-4424-9a3f-b6ead6b4894f\"},\"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\":14,\"completion_tokens\":12,\"total_tokens\":26}}", + "headers": {}, + "status": 200 + }, + "uuid": "bcdbf876-8b4c-4de1-99b4-deaad761fdbe" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-c71f3ff7-70f7-4966-a752-811bf1c01382.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-c71f3ff7-70f7-4966-a752-811bf1c01382.json index 239aeb483f..e4985753bc 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-c71f3ff7-70f7-4966-a752-811bf1c01382.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-c71f3ff7-70f7-4966-a752-811bf1c01382.json @@ -1,25 +1,25 @@ { - "id" : "c71f3ff7-70f7-4966-a752-811bf1c01382", - "insertionIndex" : 1, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Hello AI, my name is Bob. What is the origin of my name?\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "requiredScenarioState" : "scenario-1-deployments-gpt-35-turbo-chat-completions-2", - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253072,\"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\":\"b82a811f-96d2-479f-96db-cadddfa99c1d\"},\"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\":23,\"completion_tokens\":80,\"total_tokens\":103}}", - "headers" : {}, - "status" : 200 - }, - "scenarioName" : "scenario-1-deployments-gpt-35-turbo-chat-completions", - "uuid" : "c71f3ff7-70f7-4966-a752-811bf1c01382" + "id": "c71f3ff7-70f7-4966-a752-811bf1c01382", + "insertionIndex": 1, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Hello AI, my name is Bob. What is the origin of my name?\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "requiredScenarioState": "scenario-1-deployments-gpt-35-turbo-chat-completions-2", + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253072,\"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\":\"b82a811f-96d2-479f-96db-cadddfa99c1d\"},\"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\":23,\"completion_tokens\":80,\"total_tokens\":103}}", + "headers": {}, + "status": 200 + }, + "scenarioName": "scenario-1-deployments-gpt-35-turbo-chat-completions", + "uuid": "c71f3ff7-70f7-4966-a752-811bf1c01382" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-ca797b35-ef23-4628-9c6f-b1ea00ba5e3e.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-ca797b35-ef23-4628-9c6f-b1ea00ba5e3e.json index 6664521ab3..36bd24780d 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-ca797b35-ef23-4628-9c6f-b1ea00ba5e3e.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-ca797b35-ef23-4628-9c6f-b1ea00ba5e3e.json @@ -1,23 +1,23 @@ { - "id" : "ca797b35-ef23-4628-9c6f-b1ea00ba5e3e", - "insertionIndex" : 15, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a paragraph about Handlers.\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253032,\"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\":\"49c63368-9fe4-42ca-bd0c-ff1064c44eb6\"},\"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\":13,\"completion_tokens\":149,\"total_tokens\":162}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "ca797b35-ef23-4628-9c6f-b1ea00ba5e3e" + "id": "ca797b35-ef23-4628-9c6f-b1ea00ba5e3e", + "insertionIndex": 15, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a paragraph about Handlers.\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253032,\"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\":\"49c63368-9fe4-42ca-bd0c-ff1064c44eb6\"},\"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\":13,\"completion_tokens\":149,\"total_tokens\":162}}", + "headers": {}, + "status": 200 + }, + "uuid": "ca797b35-ef23-4628-9c6f-b1ea00ba5e3e" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-daf144e4-182b-4100-91f2-49b6115a1026.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-daf144e4-182b-4100-91f2-49b6115a1026.json index b5ac6375fc..e3415ef522 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-daf144e4-182b-4100-91f2-49b6115a1026.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-daf144e4-182b-4100-91f2-49b6115a1026.json @@ -1,25 +1,25 @@ { - "id" : "daf144e4-182b-4100-91f2-49b6115a1026", - "insertionIndex" : 10, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Hello AI, what can you do for me?\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "requiredScenarioState" : "scenario-5-deployments-gpt-35-turbo-chat-completions-2", - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253047,\"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\":\"4aab22a1-8bb4-462e-a72d-5abeb5b91335\"},\"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\":251,\"total_tokens\":268}}", - "headers" : {}, - "status" : 200 - }, - "scenarioName" : "scenario-5-deployments-gpt-35-turbo-chat-completions", - "uuid" : "daf144e4-182b-4100-91f2-49b6115a1026" + "id": "daf144e4-182b-4100-91f2-49b6115a1026", + "insertionIndex": 10, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Hello AI, what can you do for me?\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "requiredScenarioState": "scenario-5-deployments-gpt-35-turbo-chat-completions-2", + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253047,\"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\":\"4aab22a1-8bb4-462e-a72d-5abeb5b91335\"},\"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\":251,\"total_tokens\":268}}", + "headers": {}, + "status": 200 + }, + "scenarioName": "scenario-5-deployments-gpt-35-turbo-chat-completions", + "uuid": "daf144e4-182b-4100-91f2-49b6115a1026" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-dc3d7bb6-815c-44fc-a15f-a6f9ce7eb012.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-dc3d7bb6-815c-44fc-a15f-a6f9ce7eb012.json index 746e3e5748..ca3f68c04a 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-dc3d7bb6-815c-44fc-a15f-a6f9ce7eb012.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-dc3d7bb6-815c-44fc-a15f-a6f9ce7eb012.json @@ -1,23 +1,23 @@ { - "id" : "dc3d7bb6-815c-44fc-a15f-a6f9ce7eb012", - "insertionIndex" : 13, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a paragraph about hats\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253037,\"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\":\"8dafdc23-45e2-4c72-949d-0b88c107c76e\"},\"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\":12,\"completion_tokens\":130,\"total_tokens\":142}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "dc3d7bb6-815c-44fc-a15f-a6f9ce7eb012" + "id": "dc3d7bb6-815c-44fc-a15f-a6f9ce7eb012", + "insertionIndex": 13, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a paragraph about hats\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253037,\"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\":\"8dafdc23-45e2-4c72-949d-0b88c107c76e\"},\"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\":12,\"completion_tokens\":130,\"total_tokens\":142}}", + "headers": {}, + "status": 200 + }, + "uuid": "dc3d7bb6-815c-44fc-a15f-a6f9ce7eb012" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-f0070b1d-f4eb-4691-9d72-a0b935a227eb.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-f0070b1d-f4eb-4691-9d72-a0b935a227eb.json index 34c657cee5..ea296f3757 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-f0070b1d-f4eb-4691-9d72-a0b935a227eb.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_gpt-35-turbo_chat_completions-f0070b1d-f4eb-4691-9d72-a0b935a227eb.json @@ -1,23 +1,23 @@ { - "id" : "f0070b1d-f4eb-4691-9d72-a0b935a227eb", - "insertionIndex" : 17, - "name" : "deployments_gpt-35-turbo_chat_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a random paragraph about: I missed the F1 final race.\"}],\"model\":\"gpt-35-turbo\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253024,\"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\":\"97aeec5d-1555-4548-a681-cb1cc52b15c5\"},\"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\":21,\"completion_tokens\":175,\"total_tokens\":196}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "f0070b1d-f4eb-4691-9d72-a0b935a227eb" + "id": "f0070b1d-f4eb-4691-9d72-a0b935a227eb", + "insertionIndex": 17, + "name": "deployments_gpt-35-turbo_chat_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"messages\":[{\"role\":\"user\",\"content\":\"Write a random paragraph about: I missed the F1 final race.\"}],\"model\":\"gpt-35-turbo\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"chatcmpl-xxx\",\"object\":\"chat.completion\",\"created\":1707253024,\"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\":\"97aeec5d-1555-4548-a681-cb1cc52b15c5\"},\"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\":21,\"completion_tokens\":175,\"total_tokens\":196}}", + "headers": {}, + "status": 200 + }, + "uuid": "f0070b1d-f4eb-4691-9d72-a0b935a227eb" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-0215b128-4822-4368-ac3d-2f580a221f00.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-0215b128-4822-4368-ac3d-2f580a221f00.json index 08b36b629e..46455db79b 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-0215b128-4822-4368-ac3d-2f580a221f00.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-0215b128-4822-4368-ac3d-2f580a221f00.json @@ -1,26 +1,26 @@ { - "id" : "0215b128-4822-4368-ac3d-2f580a221f00", - "insertionIndex" : 6, - "name" : "deployments_text-davinci-003_completions", - "newScenarioState" : "scenario-3-deployments-text-davinci-003-completions-3", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"prompt\":[\"Hello AI, what can you do for me?\"],\"max_tokens\":256,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" - }, - "requiredScenarioState" : "scenario-3-deployments-text-davinci-003-completions-2", - "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}}", - "headers" : {}, - "status" : 200 - }, - "scenarioName" : "scenario-3-deployments-text-davinci-003-completions", - "uuid" : "0215b128-4822-4368-ac3d-2f580a221f00" + "id": "0215b128-4822-4368-ac3d-2f580a221f00", + "insertionIndex": 6, + "name": "deployments_text-davinci-003_completions", + "newScenarioState": "scenario-3-deployments-text-davinci-003-completions-3", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"prompt\":[\"Hello AI, what can you do for me?\"],\"max_tokens\":256,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" + }, + "requiredScenarioState": "scenario-3-deployments-text-davinci-003-completions-2", + "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}}", + "headers": {}, + "status": 200 + }, + "scenarioName": "scenario-3-deployments-text-davinci-003-completions", + "uuid": "0215b128-4822-4368-ac3d-2f580a221f00" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-1296bcee-1e54-43b1-b4b3-4642dd8bd0a0.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-1296bcee-1e54-43b1-b4b3-4642dd8bd0a0.json index 2e05edad2b..486a8b19cb 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-1296bcee-1e54-43b1-b4b3-4642dd8bd0a0.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-1296bcee-1e54-43b1-b4b3-4642dd8bd0a0.json @@ -1,25 +1,25 @@ { - "id" : "1296bcee-1e54-43b1-b4b3-4642dd8bd0a0", - "insertionIndex" : 5, - "name" : "deployments_text-davinci-003_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"prompt\":[\"Hello AI, what can you do for me?\"],\"max_tokens\":256,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" - }, - "requiredScenarioState" : "scenario-3-deployments-text-davinci-003-completions-3", - "response" : { - "body" : "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707253064,\"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\":\"f3d22bfb-13ae-41f1-ba1c-e162da7cf3ec\",\"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\":34,\"total_tokens\":44}}", - "headers" : {}, - "status" : 200 - }, - "scenarioName" : "scenario-3-deployments-text-davinci-003-completions", - "uuid" : "1296bcee-1e54-43b1-b4b3-4642dd8bd0a0" + "id": "1296bcee-1e54-43b1-b4b3-4642dd8bd0a0", + "insertionIndex": 5, + "name": "deployments_text-davinci-003_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"prompt\":[\"Hello AI, what can you do for me?\"],\"max_tokens\":256,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" + }, + "requiredScenarioState": "scenario-3-deployments-text-davinci-003-completions-3", + "response": { + "body": "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707253064,\"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\":\"f3d22bfb-13ae-41f1-ba1c-e162da7cf3ec\",\"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\":34,\"total_tokens\":44}}", + "headers": {}, + "status": 200 + }, + "scenarioName": "scenario-3-deployments-text-davinci-003-completions", + "uuid": "1296bcee-1e54-43b1-b4b3-4642dd8bd0a0" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-350fea53-3d73-4d59-b603-dba32fdc5af9.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-350fea53-3d73-4d59-b603-dba32fdc5af9.json index 7decc7282d..d2042ae323 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-350fea53-3d73-4d59-b603-dba32fdc5af9.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-350fea53-3d73-4d59-b603-dba32fdc5af9.json @@ -1,23 +1,23 @@ { - "id" : "350fea53-3d73-4d59-b603-dba32fdc5af9", - "insertionIndex" : 37, - "name" : "deployments_text-davinci-003_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"prompt\":[\" Generate a creative reason or excuse for the given event.\\n Be creative and be funny. Let your imagination run wild.\\n\\n Event: I am running late.\\n Excuse: I was being held ransom by giraffe gangsters.\\n\\n Event: I haven't been to the gym for a year\\n Excuse: I've been too busy training my pet dragon.\\n\\n Event: I missed the F1 final race\\n\"],\"max_tokens\":100,\"temperature\":0.4,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252975,\"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\":\"1ec9fb4c-eae2-44b4-9974-c87d452220ae\",\"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\":93,\"completion_tokens\":15,\"total_tokens\":108}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "350fea53-3d73-4d59-b603-dba32fdc5af9" + "id": "350fea53-3d73-4d59-b603-dba32fdc5af9", + "insertionIndex": 37, + "name": "deployments_text-davinci-003_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"prompt\":[\" Generate a creative reason or excuse for the given event.\\n Be creative and be funny. Let your imagination run wild.\\n\\n Event: I am running late.\\n Excuse: I was being held ransom by giraffe gangsters.\\n\\n Event: I haven't been to the gym for a year\\n Excuse: I've been too busy training my pet dragon.\\n\\n Event: I missed the F1 final race\\n\"],\"max_tokens\":100,\"temperature\":0.4,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252975,\"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\":\"1ec9fb4c-eae2-44b4-9974-c87d452220ae\",\"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\":93,\"completion_tokens\":15,\"total_tokens\":108}}", + "headers": {}, + "status": 200 + }, + "uuid": "350fea53-3d73-4d59-b603-dba32fdc5af9" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-3ce79fbf-90ee-4575-aeb4-6f7d545d1db6.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-3ce79fbf-90ee-4575-aeb4-6f7d545d1db6.json index c99bd97f30..8422dfec0e 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-3ce79fbf-90ee-4575-aeb4-6f7d545d1db6.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-3ce79fbf-90ee-4575-aeb4-6f7d545d1db6.json @@ -1,23 +1,23 @@ { - "id" : "3ce79fbf-90ee-4575-aeb4-6f7d545d1db6", - "insertionIndex" : 32, - "name" : "deployments_text-davinci-003_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"prompt\":[\"BEGIN CONTENT TO SUMMARIZE:\\nJane: I think we're almost there. Let me check.\\nJane: I have some bad news, we're only half way there.\\nJohn: Oh no, I'm not sure I can keep going. I'm getting tired.\\nJane: I'm getting tired too.\\nJohn: Maybe there is a large piece of text we can use to generate a long conversation.\\nJane: That's a good idea. Let me see if I can find one. Maybe Lorem Ipsum?\\nJohn: Yeah, that's a good idea.\\nJane: I found a Lorem Ipsum generator.\\nJane: Here's a 4096 character Lorem Ipsum text:\\nJane: Lorem ipsum dolor sit amet, con\\nJane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam\\nJane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam\\nJane: Darn, it's just repeating stuf now.\\nJohn: I think we're done.\\nJane: We're not though! We need like 1500 more characters.\\nJohn: Oh Cananda, our home and native land.\\nJane: True patriot love in all thy sons command.\\nJohn: With glowing hearts we see thee rise.\\nJane: The True North strong and free.\\nJohn: From far and wide, O Canada, we stand on guard for thee.\\nJane: God keep our land glorious and free.\\nJohn: O Canada, we stand on guard for thee.\\nJane: O Canada, we stand on guard for thee.\\nJane: That was fun, thank you. Let me check now.\\nJane: I think we need about 600 more characters.\\nJohn: Oh say can you see?\\nJane: By the dawn's early light.\\nJohn: What so proudly we hailed.\\nJane: At the twilight's last gleaming.\\nJohn: Whose broad stripes and bright stars.\\nJane: Through the perilous fight.\\nJohn: O'er the ramparts we watched.\\nJane: Were so gallantly streaming.\\nJohn: And the rockets' red glare.\\nJane: The bombs bursting in air.\\nJohn: Gave proof through the night.\\nJane: That our flag was still there.\\nJohn: Oh say does that star-spangled banner yet wave.\\nJane: O'er the land of the free.\\nJohn: And the home of the brave.\\nJane: Are you a Seattle Kraken Fan?\\nJohn: Yes, I am. I love going to the games.\\nJane: I'm a Seattle Kraken Fan too. Who is your favorite player?\\nJohn: I like watching all the players, but I think my favorite is Matty Beniers.\\nJane: Yeah, he's a great player. I like watching him too. I also like watching Jaden Schwartz.\\nJohn: Adam Larsson is another good one. The big cat!\\nJane: WE MADE IT! It's long enough. Thank you!\\nJohn: Can you automate generating long text next time?\\nJane: I will.\\nJohn: You're welcome. I'm glad we could help. Goodbye!\\nJane: Goodbye!\\n\\nEND CONTENT TO SUMMARIZE.\\n\\nSummarize the conversation in 'CONTENT TO SUMMARIZE', identifying main points of discussion and any conclusions that were reached.\\nDo not incorporate other general knowledge.\\nSummary is in plain text, in complete sentences, with no markup or tags.\\n\\nBEGIN SUMMARY:\\n\"],\"max_tokens\":1024,\"temperature\":0.1,\"top_p\":0.5,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252982,\"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\":\"caf6e239-7150-4d70-b814-62cd93e7c525\",\"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\":791,\"completion_tokens\":48,\"total_tokens\":839}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "3ce79fbf-90ee-4575-aeb4-6f7d545d1db6" + "id": "3ce79fbf-90ee-4575-aeb4-6f7d545d1db6", + "insertionIndex": 32, + "name": "deployments_text-davinci-003_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"prompt\":[\"BEGIN CONTENT TO SUMMARIZE:\\nJane: I think we're almost there. Let me check.\\nJane: I have some bad news, we're only half way there.\\nJohn: Oh no, I'm not sure I can keep going. I'm getting tired.\\nJane: I'm getting tired too.\\nJohn: Maybe there is a large piece of text we can use to generate a long conversation.\\nJane: That's a good idea. Let me see if I can find one. Maybe Lorem Ipsum?\\nJohn: Yeah, that's a good idea.\\nJane: I found a Lorem Ipsum generator.\\nJane: Here's a 4096 character Lorem Ipsum text:\\nJane: Lorem ipsum dolor sit amet, con\\nJane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam\\nJane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam\\nJane: Darn, it's just repeating stuf now.\\nJohn: I think we're done.\\nJane: We're not though! We need like 1500 more characters.\\nJohn: Oh Cananda, our home and native land.\\nJane: True patriot love in all thy sons command.\\nJohn: With glowing hearts we see thee rise.\\nJane: The True North strong and free.\\nJohn: From far and wide, O Canada, we stand on guard for thee.\\nJane: God keep our land glorious and free.\\nJohn: O Canada, we stand on guard for thee.\\nJane: O Canada, we stand on guard for thee.\\nJane: That was fun, thank you. Let me check now.\\nJane: I think we need about 600 more characters.\\nJohn: Oh say can you see?\\nJane: By the dawn's early light.\\nJohn: What so proudly we hailed.\\nJane: At the twilight's last gleaming.\\nJohn: Whose broad stripes and bright stars.\\nJane: Through the perilous fight.\\nJohn: O'er the ramparts we watched.\\nJane: Were so gallantly streaming.\\nJohn: And the rockets' red glare.\\nJane: The bombs bursting in air.\\nJohn: Gave proof through the night.\\nJane: That our flag was still there.\\nJohn: Oh say does that star-spangled banner yet wave.\\nJane: O'er the land of the free.\\nJohn: And the home of the brave.\\nJane: Are you a Seattle Kraken Fan?\\nJohn: Yes, I am. I love going to the games.\\nJane: I'm a Seattle Kraken Fan too. Who is your favorite player?\\nJohn: I like watching all the players, but I think my favorite is Matty Beniers.\\nJane: Yeah, he's a great player. I like watching him too. I also like watching Jaden Schwartz.\\nJohn: Adam Larsson is another good one. The big cat!\\nJane: WE MADE IT! It's long enough. Thank you!\\nJohn: Can you automate generating long text next time?\\nJane: I will.\\nJohn: You're welcome. I'm glad we could help. Goodbye!\\nJane: Goodbye!\\n\\nEND CONTENT TO SUMMARIZE.\\n\\nSummarize the conversation in 'CONTENT TO SUMMARIZE', identifying main points of discussion and any conclusions that were reached.\\nDo not incorporate other general knowledge.\\nSummary is in plain text, in complete sentences, with no markup or tags.\\n\\nBEGIN SUMMARY:\\n\"],\"max_tokens\":1024,\"temperature\":0.1,\"top_p\":0.5,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252982,\"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\":\"caf6e239-7150-4d70-b814-62cd93e7c525\",\"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\":791,\"completion_tokens\":48,\"total_tokens\":839}}", + "headers": {}, + "status": 200 + }, + "uuid": "3ce79fbf-90ee-4575-aeb4-6f7d545d1db6" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-3d48b3d9-5263-4d35-97dc-6db5b0335989.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-3d48b3d9-5263-4d35-97dc-6db5b0335989.json index f57d5e139d..a47a658d5d 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-3d48b3d9-5263-4d35-97dc-6db5b0335989.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-3d48b3d9-5263-4d35-97dc-6db5b0335989.json @@ -1,23 +1,23 @@ { - "id" : "3d48b3d9-5263-4d35-97dc-6db5b0335989", - "insertionIndex" : 30, - "name" : "deployments_text-davinci-003_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"prompt\":[\"You are an action item extractor. You will be given chat history and need to make note of action items mentioned in the chat.\\nExtract action items from the content if there are any. If there are no action, return nothing. If a single field is missing, use an empty string.\\nReturn the action items in json.\\n\\nPossible statuses for action items are: Open, Closed, In Progress.\\n\\nEXAMPLE INPUT WITH ACTION ITEMS:\\n\\nJohn Doe said: \\\"I will record a demo for the new feature by Friday\\\"\\nI said: \\\"Great, thanks John. We may not use all of it but it's good to get it out there.\\\"\\n\\nEXAMPLE OUTPUT:\\n{\\n \\\"actionItems\\\": [\\n {\\n \\\"owner\\\": \\\"John Doe\\\",\\n \\\"actionItem\\\": \\\"Record a demo for the new feature\\\",\\n \\\"dueDate\\\": \\\"Friday\\\",\\n \\\"status\\\": \\\"Open\\\",\\n \\\"notes\\\": \\\"\\n }\\n ]\\n}\\n\\nEXAMPLE INPUT WITHOUT ACTION ITEMS:\\n\\nJohn Doe said: \\\"Hey I'm going to the store, do you need anything?\\\"\\nI said: \\\"No thanks, I'm good.\\\"\\n\\nEXAMPLE OUTPUT:\\n{\\n \\\"action_items\\\": []\\n}\\n\\nCONTENT STARTS HERE.\\n\\nJane: I think we're almost there. Let me check.\\nJane: I have some bad news, we're only half way there.\\nJohn: Oh no, I'm not sure I can keep going. I'm getting tired.\\nJane: I'm getting tired too.\\nJohn: Maybe there is a large piece of text we can use to generate a long conversation.\\nJane: That's a good idea. Let me see if I can find one. Maybe Lorem Ipsum?\\nJohn: Yeah, that's a good idea.\\nJane: I found a Lorem Ipsum generator.\\nJane: Here's a 4096 character Lorem Ipsum text:\\nJane: Lorem ipsum dolor sit amet, con\\nJane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam\\nJane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam\\nJane: Darn, it's just repeating stuf now.\\nJohn: I think we're done.\\nJane: We're not though! We need like 1500 more characters.\\nJohn: Oh Cananda, our home and native land.\\nJane: True patriot love in all thy sons command.\\nJohn: With glowing hearts we see thee rise.\\nJane: The True North strong and free.\\nJohn: From far and wide, O Canada, we stand on guard for thee.\\nJane: God keep our land glorious and free.\\nJohn: O Canada, we stand on guard for thee.\\nJane: O Canada, we stand on guard for thee.\\nJane: That was fun, thank you. Let me check now.\\nJane: I think we need about 600 more characters.\\nJohn: Oh say can you see?\\nJane: By the dawn's early light.\\nJohn: What so proudly we hailed.\\nJane: At the twilight's last gleaming.\\nJohn: Whose broad stripes and bright stars.\\nJane: Through the perilous fight.\\nJohn: O'er the ramparts we watched.\\nJane: Were so gallantly streaming.\\nJohn: And the rockets' red glare.\\nJane: The bombs bursting in air.\\nJohn: Gave proof through the night.\\nJane: That our flag was still there.\\nJohn: Oh say does that star-spangled banner yet wave.\\nJane: O'er the land of the free.\\nJohn: And the home of the brave.\\nJane: Are you a Seattle Kraken Fan?\\nJohn: Yes, I am. I love going to the games.\\nJane: I'm a Seattle Kraken Fan too. Who is your favorite player?\\nJohn: I like watching all the players, but I think my favorite is Matty Beniers.\\nJane: Yeah, he's a great player. I like watching him too. I also like watching Jaden Schwartz.\\nJohn: Adam Larsson is another good one. The big cat!\\nJane: WE MADE IT! It's long enough. Thank you!\\nJohn: Can you automate generating long text next time?\\nJane: I will.\\nJohn: You're welcome. I'm glad we could help. Goodbye!\\nJane: Goodbye!\\n\\nCONTENT STOPS HERE.\\n\\nOUTPUT:\\n\"],\"max_tokens\":1024,\"temperature\":0.1,\"top_p\":0.5,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252987,\"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\":\"cab3c6e5-6681-48a0-8c56-3727299a890d\",\"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\":1018,\"completion_tokens\":62,\"total_tokens\":1080}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "3d48b3d9-5263-4d35-97dc-6db5b0335989" + "id": "3d48b3d9-5263-4d35-97dc-6db5b0335989", + "insertionIndex": 30, + "name": "deployments_text-davinci-003_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"prompt\":[\"You are an action item extractor. You will be given chat history and need to make note of action items mentioned in the chat.\\nExtract action items from the content if there are any. If there are no action, return nothing. If a single field is missing, use an empty string.\\nReturn the action items in json.\\n\\nPossible statuses for action items are: Open, Closed, In Progress.\\n\\nEXAMPLE INPUT WITH ACTION ITEMS:\\n\\nJohn Doe said: \\\"I will record a demo for the new feature by Friday\\\"\\nI said: \\\"Great, thanks John. We may not use all of it but it's good to get it out there.\\\"\\n\\nEXAMPLE OUTPUT:\\n{\\n \\\"actionItems\\\": [\\n {\\n \\\"owner\\\": \\\"John Doe\\\",\\n \\\"actionItem\\\": \\\"Record a demo for the new feature\\\",\\n \\\"dueDate\\\": \\\"Friday\\\",\\n \\\"status\\\": \\\"Open\\\",\\n \\\"notes\\\": \\\"\\n }\\n ]\\n}\\n\\nEXAMPLE INPUT WITHOUT ACTION ITEMS:\\n\\nJohn Doe said: \\\"Hey I'm going to the store, do you need anything?\\\"\\nI said: \\\"No thanks, I'm good.\\\"\\n\\nEXAMPLE OUTPUT:\\n{\\n \\\"action_items\\\": []\\n}\\n\\nCONTENT STARTS HERE.\\n\\nJane: I think we're almost there. Let me check.\\nJane: I have some bad news, we're only half way there.\\nJohn: Oh no, I'm not sure I can keep going. I'm getting tired.\\nJane: I'm getting tired too.\\nJohn: Maybe there is a large piece of text we can use to generate a long conversation.\\nJane: That's a good idea. Let me see if I can find one. Maybe Lorem Ipsum?\\nJohn: Yeah, that's a good idea.\\nJane: I found a Lorem Ipsum generator.\\nJane: Here's a 4096 character Lorem Ipsum text:\\nJane: Lorem ipsum dolor sit amet, con\\nJane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam\\nJane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam\\nJane: Darn, it's just repeating stuf now.\\nJohn: I think we're done.\\nJane: We're not though! We need like 1500 more characters.\\nJohn: Oh Cananda, our home and native land.\\nJane: True patriot love in all thy sons command.\\nJohn: With glowing hearts we see thee rise.\\nJane: The True North strong and free.\\nJohn: From far and wide, O Canada, we stand on guard for thee.\\nJane: God keep our land glorious and free.\\nJohn: O Canada, we stand on guard for thee.\\nJane: O Canada, we stand on guard for thee.\\nJane: That was fun, thank you. Let me check now.\\nJane: I think we need about 600 more characters.\\nJohn: Oh say can you see?\\nJane: By the dawn's early light.\\nJohn: What so proudly we hailed.\\nJane: At the twilight's last gleaming.\\nJohn: Whose broad stripes and bright stars.\\nJane: Through the perilous fight.\\nJohn: O'er the ramparts we watched.\\nJane: Were so gallantly streaming.\\nJohn: And the rockets' red glare.\\nJane: The bombs bursting in air.\\nJohn: Gave proof through the night.\\nJane: That our flag was still there.\\nJohn: Oh say does that star-spangled banner yet wave.\\nJane: O'er the land of the free.\\nJohn: And the home of the brave.\\nJane: Are you a Seattle Kraken Fan?\\nJohn: Yes, I am. I love going to the games.\\nJane: I'm a Seattle Kraken Fan too. Who is your favorite player?\\nJohn: I like watching all the players, but I think my favorite is Matty Beniers.\\nJane: Yeah, he's a great player. I like watching him too. I also like watching Jaden Schwartz.\\nJohn: Adam Larsson is another good one. The big cat!\\nJane: WE MADE IT! It's long enough. Thank you!\\nJohn: Can you automate generating long text next time?\\nJane: I will.\\nJohn: You're welcome. I'm glad we could help. Goodbye!\\nJane: Goodbye!\\n\\nCONTENT STOPS HERE.\\n\\nOUTPUT:\\n\"],\"max_tokens\":1024,\"temperature\":0.1,\"top_p\":0.5,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252987,\"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\":\"cab3c6e5-6681-48a0-8c56-3727299a890d\",\"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\":1018,\"completion_tokens\":62,\"total_tokens\":1080}}", + "headers": {}, + "status": 200 + }, + "uuid": "3d48b3d9-5263-4d35-97dc-6db5b0335989" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-544c72c2-de8a-407d-a319-b7c04a8c237e.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-544c72c2-de8a-407d-a319-b7c04a8c237e.json index 904b360fbd..21d76e6f02 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-544c72c2-de8a-407d-a319-b7c04a8c237e.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-544c72c2-de8a-407d-a319-b7c04a8c237e.json @@ -1,23 +1,23 @@ { - "id" : "544c72c2-de8a-407d-a319-b7c04a8c237e", - "insertionIndex" : 31, - "name" : "deployments_text-davinci-003_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"prompt\":[\"You are an action item extractor. You will be given chat history and need to make note of action items mentioned in the chat.\\nExtract action items from the content if there are any. If there are no action, return nothing. If a single field is missing, use an empty string.\\nReturn the action items in json.\\n\\nPossible statuses for action items are: Open, Closed, In Progress.\\n\\nEXAMPLE INPUT WITH ACTION ITEMS:\\n\\nJohn Doe said: \\\"I will record a demo for the new feature by Friday\\\"\\nI said: \\\"Great, thanks John. We may not use all of it but it's good to get it out there.\\\"\\n\\nEXAMPLE OUTPUT:\\n{\\n \\\"actionItems\\\": [\\n {\\n \\\"owner\\\": \\\"John Doe\\\",\\n \\\"actionItem\\\": \\\"Record a demo for the new feature\\\",\\n \\\"dueDate\\\": \\\"Friday\\\",\\n \\\"status\\\": \\\"Open\\\",\\n \\\"notes\\\": \\\"\\n }\\n ]\\n}\\n\\nEXAMPLE INPUT WITHOUT ACTION ITEMS:\\n\\nJohn Doe said: \\\"Hey I'm going to the store, do you need anything?\\\"\\nI said: \\\"No thanks, I'm good.\\\"\\n\\nEXAMPLE OUTPUT:\\n{\\n \\\"action_items\\\": []\\n}\\n\\nCONTENT STARTS HERE.\\n\\nJohn: Hello, how are you?\\nJane: I'm fine, thanks. How are you?\\nJohn: I'm doing well, writing some example code.\\nJane: That's great! I'm writing some example code too.\\nJohn: What are you writing?\\nJane: I'm writing a chatbot.\\nJohn: That's cool. I'm writing a chatbot too.\\nJane: What language are you writing it in?\\nJohn: I'm writing it in C#.\\nJane: I'm writing it in Python.\\nJohn: That's cool. I need to learn Python.\\nJane: I need to learn C#.\\nJohn: Can I try out your chatbot?\\nJane: Sure, here's the link.\\nJohn: Thanks!\\nJane: You're welcome.\\nJane: Look at this poem my chatbot wrote:\\nJane: Roses are red\\nJane: Violets are blue\\nJane: I'm writing a chatbot\\nJane: What about you?\\nJohn: That's cool. Let me see if mine will write a poem, too.\\nJohn: Here's a poem my chatbot wrote:\\nJohn: The singularity of the universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: Looks like I need to improve mine, oh well.\\nJane: You might want to try using a different model.\\nJane: I'm using the GPT-3 model.\\nJohn: I'm using the GPT-2 model. That makes sense.\\nJohn: Here is a new poem after updating the model.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: Yikes, it's really stuck isn't it. Would you help me debug my code?\\nJane: Sure, what's the problem?\\nJohn: I'm not sure. I think it's a bug in the code.\\nJane: I'll take a look.\\nJane: I think I found the problem.\\nJane: It looks like you're not passing the right parameters to the model.\\nJohn: Thanks for the help!\\nJane: I'm now writing a bot to summarize conversations. I want to make sure it works when the conversation is long.\\nJohn: So you need to keep talking with me to generate a long conversation?\\nJane: Yes, that's right.\\nJohn: Ok, I'll keep talking. What should we talk about?\\nJane: I don't know, what do you want to talk about?\\nJohn: I don't know, it's nice how CoPilot is doing most of the talking for us. But it definitely gets stuck sometimes.\\nJane: I agree, it's nice that CoPilot is doing most of the talking for us.\\nJane: But it definitely gets stuck sometimes.\\nJohn: Do you know how long it needs to be?\\nJane: I think the max length is 1024 tokens. Which is approximately 1024*4= 4096 characters.\\nJohn: That's a lot of characters.\\nJane: Yes, it is.\\nJohn: I'm not sure how much longer I can keep talking.\\n\\nCONTENT STOPS HERE.\\n\\nOUTPUT:\\n\"],\"max_tokens\":1024,\"temperature\":0.1,\"top_p\":0.5,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252983,\"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\":\"ee5e62b0-d339-4171-b42a-664a5eb77685\",\"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\":998,\"completion_tokens\":167,\"total_tokens\":1165}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "544c72c2-de8a-407d-a319-b7c04a8c237e" + "id": "544c72c2-de8a-407d-a319-b7c04a8c237e", + "insertionIndex": 31, + "name": "deployments_text-davinci-003_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"prompt\":[\"You are an action item extractor. You will be given chat history and need to make note of action items mentioned in the chat.\\nExtract action items from the content if there are any. If there are no action, return nothing. If a single field is missing, use an empty string.\\nReturn the action items in json.\\n\\nPossible statuses for action items are: Open, Closed, In Progress.\\n\\nEXAMPLE INPUT WITH ACTION ITEMS:\\n\\nJohn Doe said: \\\"I will record a demo for the new feature by Friday\\\"\\nI said: \\\"Great, thanks John. We may not use all of it but it's good to get it out there.\\\"\\n\\nEXAMPLE OUTPUT:\\n{\\n \\\"actionItems\\\": [\\n {\\n \\\"owner\\\": \\\"John Doe\\\",\\n \\\"actionItem\\\": \\\"Record a demo for the new feature\\\",\\n \\\"dueDate\\\": \\\"Friday\\\",\\n \\\"status\\\": \\\"Open\\\",\\n \\\"notes\\\": \\\"\\n }\\n ]\\n}\\n\\nEXAMPLE INPUT WITHOUT ACTION ITEMS:\\n\\nJohn Doe said: \\\"Hey I'm going to the store, do you need anything?\\\"\\nI said: \\\"No thanks, I'm good.\\\"\\n\\nEXAMPLE OUTPUT:\\n{\\n \\\"action_items\\\": []\\n}\\n\\nCONTENT STARTS HERE.\\n\\nJohn: Hello, how are you?\\nJane: I'm fine, thanks. How are you?\\nJohn: I'm doing well, writing some example code.\\nJane: That's great! I'm writing some example code too.\\nJohn: What are you writing?\\nJane: I'm writing a chatbot.\\nJohn: That's cool. I'm writing a chatbot too.\\nJane: What language are you writing it in?\\nJohn: I'm writing it in C#.\\nJane: I'm writing it in Python.\\nJohn: That's cool. I need to learn Python.\\nJane: I need to learn C#.\\nJohn: Can I try out your chatbot?\\nJane: Sure, here's the link.\\nJohn: Thanks!\\nJane: You're welcome.\\nJane: Look at this poem my chatbot wrote:\\nJane: Roses are red\\nJane: Violets are blue\\nJane: I'm writing a chatbot\\nJane: What about you?\\nJohn: That's cool. Let me see if mine will write a poem, too.\\nJohn: Here's a poem my chatbot wrote:\\nJohn: The singularity of the universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: Looks like I need to improve mine, oh well.\\nJane: You might want to try using a different model.\\nJane: I'm using the GPT-3 model.\\nJohn: I'm using the GPT-2 model. That makes sense.\\nJohn: Here is a new poem after updating the model.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: Yikes, it's really stuck isn't it. Would you help me debug my code?\\nJane: Sure, what's the problem?\\nJohn: I'm not sure. I think it's a bug in the code.\\nJane: I'll take a look.\\nJane: I think I found the problem.\\nJane: It looks like you're not passing the right parameters to the model.\\nJohn: Thanks for the help!\\nJane: I'm now writing a bot to summarize conversations. I want to make sure it works when the conversation is long.\\nJohn: So you need to keep talking with me to generate a long conversation?\\nJane: Yes, that's right.\\nJohn: Ok, I'll keep talking. What should we talk about?\\nJane: I don't know, what do you want to talk about?\\nJohn: I don't know, it's nice how CoPilot is doing most of the talking for us. But it definitely gets stuck sometimes.\\nJane: I agree, it's nice that CoPilot is doing most of the talking for us.\\nJane: But it definitely gets stuck sometimes.\\nJohn: Do you know how long it needs to be?\\nJane: I think the max length is 1024 tokens. Which is approximately 1024*4= 4096 characters.\\nJohn: That's a lot of characters.\\nJane: Yes, it is.\\nJohn: I'm not sure how much longer I can keep talking.\\n\\nCONTENT STOPS HERE.\\n\\nOUTPUT:\\n\"],\"max_tokens\":1024,\"temperature\":0.1,\"top_p\":0.5,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252983,\"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\":\"ee5e62b0-d339-4171-b42a-664a5eb77685\",\"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\":998,\"completion_tokens\":167,\"total_tokens\":1165}}", + "headers": {}, + "status": 200 + }, + "uuid": "544c72c2-de8a-407d-a319-b7c04a8c237e" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-7441c9cd-22ef-41a0-8c0b-f050326ca99c.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-7441c9cd-22ef-41a0-8c0b-f050326ca99c.json index eb5f452952..ea2b259780 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-7441c9cd-22ef-41a0-8c0b-f050326ca99c.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-7441c9cd-22ef-41a0-8c0b-f050326ca99c.json @@ -1,26 +1,26 @@ { - "id" : "7441c9cd-22ef-41a0-8c0b-f050326ca99c", - "insertionIndex" : 9, - "name" : "deployments_text-davinci-003_completions", - "newScenarioState" : "scenario-3-deployments-text-davinci-003-completions-2", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"prompt\":[\"Hello AI, what can you do for me?\"],\"max_tokens\":256,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" - }, - "requiredScenarioState" : "Started", - "response" : { - "body" : "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707253052,\"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\":\"50ea41ad-bd16-4241-bb54-c98e091dac99\",\"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\":35,\"total_tokens\":45}}", - "headers" : {}, - "status" : 200 - }, - "scenarioName" : "scenario-3-deployments-text-davinci-003-completions", - "uuid" : "7441c9cd-22ef-41a0-8c0b-f050326ca99c" + "id": "7441c9cd-22ef-41a0-8c0b-f050326ca99c", + "insertionIndex": 9, + "name": "deployments_text-davinci-003_completions", + "newScenarioState": "scenario-3-deployments-text-davinci-003-completions-2", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"prompt\":[\"Hello AI, what can you do for me?\"],\"max_tokens\":256,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" + }, + "requiredScenarioState": "Started", + "response": { + "body": "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707253052,\"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\":\"50ea41ad-bd16-4241-bb54-c98e091dac99\",\"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\":35,\"total_tokens\":45}}", + "headers": {}, + "status": 200 + }, + "scenarioName": "scenario-3-deployments-text-davinci-003-completions", + "uuid": "7441c9cd-22ef-41a0-8c0b-f050326ca99c" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-7718fb6b-1cae-4420-8e34-126c14d00539.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-7718fb6b-1cae-4420-8e34-126c14d00539.json index 773a1f60bc..348670d755 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-7718fb6b-1cae-4420-8e34-126c14d00539.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-7718fb6b-1cae-4420-8e34-126c14d00539.json @@ -1,23 +1,23 @@ { - "id" : "7718fb6b-1cae-4420-8e34-126c14d00539", - "insertionIndex" : 29, - "name" : "deployments_text-davinci-003_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"prompt\":[\"Analyze the following extract taken from a conversation transcript and extract key topics.\\n- Topics only worth remembering.\\n- Be brief. Short phrases.\\n- Can use broken English.\\n- Conciseness is very important.\\n- Topics can include names of memories you want to recall.\\n- NO LONG SENTENCES. SHORT PHRASES.\\n- Return in JSON\\n[Input]\\nMy name is Macbeth. I used to be King of Scotland, but I died. My wife's name is Lady Macbeth and we were married for 15 years. We had no children. Our beloved dog Toby McDuff was a famous hunter of rats in the forest.\\nMy tragic story was immortalized by Shakespeare in a play.\\n[Output]\\n{\\n \\\"topics\\\": [\\n \\\"Macbeth\\\",\\n \\\"King of Scotland\\\",\\n \\\"Lady Macbeth\\\",\\n \\\"Dog\\\",\\n \\\"Toby McDuff\\\",\\n \\\"Shakespeare\\\",\\n \\\"Play\\\",\\n \\\"Tragedy\\\"\\n ]\\n}\\n+++++\\n[Input]\\nJohn: Hello, how are you?\\nJane: I'm fine, thanks. How are you?\\nJohn: I'm doing well, writing some example code.\\nJane: That's great! I'm writing some example code too.\\nJohn: What are you writing?\\nJane: I'm writing a chatbot.\\nJohn: That's cool. I'm writing a chatbot too.\\nJane: What language are you writing it in?\\nJohn: I'm writing it in C#.\\nJane: I'm writing it in Python.\\nJohn: That's cool. I need to learn Python.\\nJane: I need to learn C#.\\nJohn: Can I try out your chatbot?\\nJane: Sure, here's the link.\\nJohn: Thanks!\\nJane: You're welcome.\\nJane: Look at this poem my chatbot wrote:\\nJane: Roses are red\\nJane: Violets are blue\\nJane: I'm writing a chatbot\\nJane: What about you?\\nJohn: That's cool. Let me see if mine will write a poem, too.\\nJohn: Here's a poem my chatbot wrote:\\nJohn: The singularity of the universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: Looks like I need to improve mine, oh well.\\nJane: You might want to try using a different model.\\nJane: I'm using the GPT-3 model.\\nJohn: I'm using the GPT-2 model. That makes sense.\\nJohn: Here is a new poem after updating the model.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: Yikes, it's really stuck isn't it. Would you help me debug my code?\\nJane: Sure, what's the problem?\\nJohn: I'm not sure. I think it's a bug in the code.\\nJane: I'll take a look.\\nJane: I think I found the problem.\\nJane: It looks like you're not passing the right parameters to the model.\\nJohn: Thanks for the help!\\nJane: I'm now writing a bot to summarize conversations. I want to make sure it works when the conversation is long.\\nJohn: So you need to keep talking with me to generate a long conversation?\\nJane: Yes, that's right.\\nJohn: Ok, I'll keep talking. What should we talk about?\\nJane: I don't know, what do you want to talk about?\\nJohn: I don't know, it's nice how CoPilot is doing most of the talking for us. But it definitely gets stuck sometimes.\\nJane: I agree, it's nice that CoPilot is doing most of the talking for us.\\nJane: But it definitely gets stuck sometimes.\\nJohn: Do you know how long it needs to be?\\nJane: I think the max length is 1024 tokens. Which is approximately 1024*4= 4096 characters.\\nJohn: That's a lot of characters.\\nJane: Yes, it is.\\nJohn: I'm not sure how much longer I can keep talking.\\n[Output]\"],\"max_tokens\":1024,\"temperature\":0.1,\"top_p\":0.5,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252988,\"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\":\"527e770d-c106-4b6d-8595-f584b0532d75\",\"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\":927,\"completion_tokens\":77,\"total_tokens\":1004}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "7718fb6b-1cae-4420-8e34-126c14d00539" + "id": "7718fb6b-1cae-4420-8e34-126c14d00539", + "insertionIndex": 29, + "name": "deployments_text-davinci-003_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"prompt\":[\"Analyze the following extract taken from a conversation transcript and extract key topics.\\n- Topics only worth remembering.\\n- Be brief. Short phrases.\\n- Can use broken English.\\n- Conciseness is very important.\\n- Topics can include names of memories you want to recall.\\n- NO LONG SENTENCES. SHORT PHRASES.\\n- Return in JSON\\n[Input]\\nMy name is Macbeth. I used to be King of Scotland, but I died. My wife's name is Lady Macbeth and we were married for 15 years. We had no children. Our beloved dog Toby McDuff was a famous hunter of rats in the forest.\\nMy tragic story was immortalized by Shakespeare in a play.\\n[Output]\\n{\\n \\\"topics\\\": [\\n \\\"Macbeth\\\",\\n \\\"King of Scotland\\\",\\n \\\"Lady Macbeth\\\",\\n \\\"Dog\\\",\\n \\\"Toby McDuff\\\",\\n \\\"Shakespeare\\\",\\n \\\"Play\\\",\\n \\\"Tragedy\\\"\\n ]\\n}\\n+++++\\n[Input]\\nJohn: Hello, how are you?\\nJane: I'm fine, thanks. How are you?\\nJohn: I'm doing well, writing some example code.\\nJane: That's great! I'm writing some example code too.\\nJohn: What are you writing?\\nJane: I'm writing a chatbot.\\nJohn: That's cool. I'm writing a chatbot too.\\nJane: What language are you writing it in?\\nJohn: I'm writing it in C#.\\nJane: I'm writing it in Python.\\nJohn: That's cool. I need to learn Python.\\nJane: I need to learn C#.\\nJohn: Can I try out your chatbot?\\nJane: Sure, here's the link.\\nJohn: Thanks!\\nJane: You're welcome.\\nJane: Look at this poem my chatbot wrote:\\nJane: Roses are red\\nJane: Violets are blue\\nJane: I'm writing a chatbot\\nJane: What about you?\\nJohn: That's cool. Let me see if mine will write a poem, too.\\nJohn: Here's a poem my chatbot wrote:\\nJohn: The singularity of the universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: Looks like I need to improve mine, oh well.\\nJane: You might want to try using a different model.\\nJane: I'm using the GPT-3 model.\\nJohn: I'm using the GPT-2 model. That makes sense.\\nJohn: Here is a new poem after updating the model.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: Yikes, it's really stuck isn't it. Would you help me debug my code?\\nJane: Sure, what's the problem?\\nJohn: I'm not sure. I think it's a bug in the code.\\nJane: I'll take a look.\\nJane: I think I found the problem.\\nJane: It looks like you're not passing the right parameters to the model.\\nJohn: Thanks for the help!\\nJane: I'm now writing a bot to summarize conversations. I want to make sure it works when the conversation is long.\\nJohn: So you need to keep talking with me to generate a long conversation?\\nJane: Yes, that's right.\\nJohn: Ok, I'll keep talking. What should we talk about?\\nJane: I don't know, what do you want to talk about?\\nJohn: I don't know, it's nice how CoPilot is doing most of the talking for us. But it definitely gets stuck sometimes.\\nJane: I agree, it's nice that CoPilot is doing most of the talking for us.\\nJane: But it definitely gets stuck sometimes.\\nJohn: Do you know how long it needs to be?\\nJane: I think the max length is 1024 tokens. Which is approximately 1024*4= 4096 characters.\\nJohn: That's a lot of characters.\\nJane: Yes, it is.\\nJohn: I'm not sure how much longer I can keep talking.\\n[Output]\"],\"max_tokens\":1024,\"temperature\":0.1,\"top_p\":0.5,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252988,\"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\":\"527e770d-c106-4b6d-8595-f584b0532d75\",\"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\":927,\"completion_tokens\":77,\"total_tokens\":1004}}", + "headers": {}, + "status": 200 + }, + "uuid": "7718fb6b-1cae-4420-8e34-126c14d00539" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-857195c1-97b9-4118-8c05-d25d0020f8e2.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-857195c1-97b9-4118-8c05-d25d0020f8e2.json index 894208d1fe..ae05b7c2f2 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-857195c1-97b9-4118-8c05-d25d0020f8e2.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-857195c1-97b9-4118-8c05-d25d0020f8e2.json @@ -1,23 +1,23 @@ { - "id" : "857195c1-97b9-4118-8c05-d25d0020f8e2", - "insertionIndex" : 35, - "name" : "deployments_text-davinci-003_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"prompt\":[\"Translate this date 1970-01-01 to French format\"],\"max_tokens\":100,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252976,\"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\":\"5cfcf9bb-5adc-43ab-ac46-80009b0e3cf9\",\"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\":12,\"completion_tokens\":7,\"total_tokens\":19}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "857195c1-97b9-4118-8c05-d25d0020f8e2" + "id": "857195c1-97b9-4118-8c05-d25d0020f8e2", + "insertionIndex": 35, + "name": "deployments_text-davinci-003_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"prompt\":[\"Translate this date 1970-01-01 to French format\"],\"max_tokens\":100,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252976,\"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\":\"5cfcf9bb-5adc-43ab-ac46-80009b0e3cf9\",\"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\":12,\"completion_tokens\":7,\"total_tokens\":19}}", + "headers": {}, + "status": 200 + }, + "uuid": "857195c1-97b9-4118-8c05-d25d0020f8e2" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-85f3675c-e404-4138-96c2-e49d4521e4f6.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-85f3675c-e404-4138-96c2-e49d4521e4f6.json index 8f94812356..dec6a70872 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-85f3675c-e404-4138-96c2-e49d4521e4f6.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-85f3675c-e404-4138-96c2-e49d4521e4f6.json @@ -1,23 +1,23 @@ { - "id" : "85f3675c-e404-4138-96c2-e49d4521e4f6", - "insertionIndex" : 36, - "name" : "deployments_text-davinci-003_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"prompt\":[\" Generate a creative reason or excuse for the given event.\\n Be creative and be funny. Let your imagination run wild.\\n\\n Event: I am running late.\\n Excuse: I was being held ransom by giraffe gangsters.\\n\\n Event: I haven't been to the gym for a year\\n Excuse: I've been too busy training my pet dragon.\\n\\n Event: sorry I forgot your birthday\\n\"],\"max_tokens\":100,\"temperature\":0.4,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252976,\"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\":\"936e5f54-9693-4a66-bd9d-96a9fa72d314\",\"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\":91,\"completion_tokens\":14,\"total_tokens\":105}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "85f3675c-e404-4138-96c2-e49d4521e4f6" + "id": "85f3675c-e404-4138-96c2-e49d4521e4f6", + "insertionIndex": 36, + "name": "deployments_text-davinci-003_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"prompt\":[\" Generate a creative reason or excuse for the given event.\\n Be creative and be funny. Let your imagination run wild.\\n\\n Event: I am running late.\\n Excuse: I was being held ransom by giraffe gangsters.\\n\\n Event: I haven't been to the gym for a year\\n Excuse: I've been too busy training my pet dragon.\\n\\n Event: sorry I forgot your birthday\\n\"],\"max_tokens\":100,\"temperature\":0.4,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252976,\"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\":\"936e5f54-9693-4a66-bd9d-96a9fa72d314\",\"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\":91,\"completion_tokens\":14,\"total_tokens\":105}}", + "headers": {}, + "status": 200 + }, + "uuid": "85f3675c-e404-4138-96c2-e49d4521e4f6" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-990e9efb-2d61-424d-bbf6-a68e2d25552f.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-990e9efb-2d61-424d-bbf6-a68e2d25552f.json index 43a478e7c7..22d1bb82c9 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-990e9efb-2d61-424d-bbf6-a68e2d25552f.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-990e9efb-2d61-424d-bbf6-a68e2d25552f.json @@ -1,23 +1,23 @@ { - "id" : "990e9efb-2d61-424d-bbf6-a68e2d25552f", - "insertionIndex" : 34, - "name" : "deployments_text-davinci-003_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"prompt\":[\"Today is: 2021-09-01\\nCurrent time is: 12:00:00\\n\\nAnswer to the following questions using JSON syntax, including the data used.\\n Is it morning, afternoon, evening, or night (morning/afternoon/evening/night)?\\n Is it weekend time (weekend/not weekend)?\\n\"],\"max_tokens\":100,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252977,\"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\":\"c0c8de7b-5fdf-43ff-a261-380cbf4be59e\",\"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\":71,\"completion_tokens\":44,\"total_tokens\":115}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "990e9efb-2d61-424d-bbf6-a68e2d25552f" + "id": "990e9efb-2d61-424d-bbf6-a68e2d25552f", + "insertionIndex": 34, + "name": "deployments_text-davinci-003_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"prompt\":[\"Today is: 2021-09-01\\nCurrent time is: 12:00:00\\n\\nAnswer to the following questions using JSON syntax, including the data used.\\n Is it morning, afternoon, evening, or night (morning/afternoon/evening/night)?\\n Is it weekend time (weekend/not weekend)?\\n\"],\"max_tokens\":100,\"temperature\":1.0,\"top_p\":1.0,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252977,\"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\":\"c0c8de7b-5fdf-43ff-a261-380cbf4be59e\",\"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\":71,\"completion_tokens\":44,\"total_tokens\":115}}", + "headers": {}, + "status": 200 + }, + "uuid": "990e9efb-2d61-424d-bbf6-a68e2d25552f" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-a29ad1f1-2423-4dbf-a127-fd2c93998fcd.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-a29ad1f1-2423-4dbf-a127-fd2c93998fcd.json index 99b6a95e60..ef8e9a60ab 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-a29ad1f1-2423-4dbf-a127-fd2c93998fcd.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-a29ad1f1-2423-4dbf-a127-fd2c93998fcd.json @@ -1,23 +1,23 @@ { - "id" : "a29ad1f1-2423-4dbf-a127-fd2c93998fcd", - "insertionIndex" : 28, - "name" : "deployments_text-davinci-003_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"prompt\":[\"Analyze the following extract taken from a conversation transcript and extract key topics.\\n- Topics only worth remembering.\\n- Be brief. Short phrases.\\n- Can use broken English.\\n- Conciseness is very important.\\n- Topics can include names of memories you want to recall.\\n- NO LONG SENTENCES. SHORT PHRASES.\\n- Return in JSON\\n[Input]\\nMy name is Macbeth. I used to be King of Scotland, but I died. My wife's name is Lady Macbeth and we were married for 15 years. We had no children. Our beloved dog Toby McDuff was a famous hunter of rats in the forest.\\nMy tragic story was immortalized by Shakespeare in a play.\\n[Output]\\n{\\n \\\"topics\\\": [\\n \\\"Macbeth\\\",\\n \\\"King of Scotland\\\",\\n \\\"Lady Macbeth\\\",\\n \\\"Dog\\\",\\n \\\"Toby McDuff\\\",\\n \\\"Shakespeare\\\",\\n \\\"Play\\\",\\n \\\"Tragedy\\\"\\n ]\\n}\\n+++++\\n[Input]\\nJane: I think we're almost there. Let me check.\\nJane: I have some bad news, we're only half way there.\\nJohn: Oh no, I'm not sure I can keep going. I'm getting tired.\\nJane: I'm getting tired too.\\nJohn: Maybe there is a large piece of text we can use to generate a long conversation.\\nJane: That's a good idea. Let me see if I can find one. Maybe Lorem Ipsum?\\nJohn: Yeah, that's a good idea.\\nJane: I found a Lorem Ipsum generator.\\nJane: Here's a 4096 character Lorem Ipsum text:\\nJane: Lorem ipsum dolor sit amet, con\\nJane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam\\nJane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam\\nJane: Darn, it's just repeating stuf now.\\nJohn: I think we're done.\\nJane: We're not though! We need like 1500 more characters.\\nJohn: Oh Cananda, our home and native land.\\nJane: True patriot love in all thy sons command.\\nJohn: With glowing hearts we see thee rise.\\nJane: The True North strong and free.\\nJohn: From far and wide, O Canada, we stand on guard for thee.\\nJane: God keep our land glorious and free.\\nJohn: O Canada, we stand on guard for thee.\\nJane: O Canada, we stand on guard for thee.\\nJane: That was fun, thank you. Let me check now.\\nJane: I think we need about 600 more characters.\\nJohn: Oh say can you see?\\nJane: By the dawn's early light.\\nJohn: What so proudly we hailed.\\nJane: At the twilight's last gleaming.\\nJohn: Whose broad stripes and bright stars.\\nJane: Through the perilous fight.\\nJohn: O'er the ramparts we watched.\\nJane: Were so gallantly streaming.\\nJohn: And the rockets' red glare.\\nJane: The bombs bursting in air.\\nJohn: Gave proof through the night.\\nJane: That our flag was still there.\\nJohn: Oh say does that star-spangled banner yet wave.\\nJane: O'er the land of the free.\\nJohn: And the home of the brave.\\nJane: Are you a Seattle Kraken Fan?\\nJohn: Yes, I am. I love going to the games.\\nJane: I'm a Seattle Kraken Fan too. Who is your favorite player?\\nJohn: I like watching all the players, but I think my favorite is Matty Beniers.\\nJane: Yeah, he's a great player. I like watching him too. I also like watching Jaden Schwartz.\\nJohn: Adam Larsson is another good one. The big cat!\\nJane: WE MADE IT! It's long enough. Thank you!\\nJohn: Can you automate generating long text next time?\\nJane: I will.\\nJohn: You're welcome. I'm glad we could help. Goodbye!\\nJane: Goodbye!\\n[Output]\"],\"max_tokens\":1024,\"temperature\":0.1,\"top_p\":0.5,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252990,\"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\":\"18733ff5-6af1-4bfc-98b9-a6e7cc1a5005\",\"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\":947,\"completion_tokens\":56,\"total_tokens\":1003}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "a29ad1f1-2423-4dbf-a127-fd2c93998fcd" + "id": "a29ad1f1-2423-4dbf-a127-fd2c93998fcd", + "insertionIndex": 28, + "name": "deployments_text-davinci-003_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"prompt\":[\"Analyze the following extract taken from a conversation transcript and extract key topics.\\n- Topics only worth remembering.\\n- Be brief. Short phrases.\\n- Can use broken English.\\n- Conciseness is very important.\\n- Topics can include names of memories you want to recall.\\n- NO LONG SENTENCES. SHORT PHRASES.\\n- Return in JSON\\n[Input]\\nMy name is Macbeth. I used to be King of Scotland, but I died. My wife's name is Lady Macbeth and we were married for 15 years. We had no children. Our beloved dog Toby McDuff was a famous hunter of rats in the forest.\\nMy tragic story was immortalized by Shakespeare in a play.\\n[Output]\\n{\\n \\\"topics\\\": [\\n \\\"Macbeth\\\",\\n \\\"King of Scotland\\\",\\n \\\"Lady Macbeth\\\",\\n \\\"Dog\\\",\\n \\\"Toby McDuff\\\",\\n \\\"Shakespeare\\\",\\n \\\"Play\\\",\\n \\\"Tragedy\\\"\\n ]\\n}\\n+++++\\n[Input]\\nJane: I think we're almost there. Let me check.\\nJane: I have some bad news, we're only half way there.\\nJohn: Oh no, I'm not sure I can keep going. I'm getting tired.\\nJane: I'm getting tired too.\\nJohn: Maybe there is a large piece of text we can use to generate a long conversation.\\nJane: That's a good idea. Let me see if I can find one. Maybe Lorem Ipsum?\\nJohn: Yeah, that's a good idea.\\nJane: I found a Lorem Ipsum generator.\\nJane: Here's a 4096 character Lorem Ipsum text:\\nJane: Lorem ipsum dolor sit amet, con\\nJane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam\\nJane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam\\nJane: Darn, it's just repeating stuf now.\\nJohn: I think we're done.\\nJane: We're not though! We need like 1500 more characters.\\nJohn: Oh Cananda, our home and native land.\\nJane: True patriot love in all thy sons command.\\nJohn: With glowing hearts we see thee rise.\\nJane: The True North strong and free.\\nJohn: From far and wide, O Canada, we stand on guard for thee.\\nJane: God keep our land glorious and free.\\nJohn: O Canada, we stand on guard for thee.\\nJane: O Canada, we stand on guard for thee.\\nJane: That was fun, thank you. Let me check now.\\nJane: I think we need about 600 more characters.\\nJohn: Oh say can you see?\\nJane: By the dawn's early light.\\nJohn: What so proudly we hailed.\\nJane: At the twilight's last gleaming.\\nJohn: Whose broad stripes and bright stars.\\nJane: Through the perilous fight.\\nJohn: O'er the ramparts we watched.\\nJane: Were so gallantly streaming.\\nJohn: And the rockets' red glare.\\nJane: The bombs bursting in air.\\nJohn: Gave proof through the night.\\nJane: That our flag was still there.\\nJohn: Oh say does that star-spangled banner yet wave.\\nJane: O'er the land of the free.\\nJohn: And the home of the brave.\\nJane: Are you a Seattle Kraken Fan?\\nJohn: Yes, I am. I love going to the games.\\nJane: I'm a Seattle Kraken Fan too. Who is your favorite player?\\nJohn: I like watching all the players, but I think my favorite is Matty Beniers.\\nJane: Yeah, he's a great player. I like watching him too. I also like watching Jaden Schwartz.\\nJohn: Adam Larsson is another good one. The big cat!\\nJane: WE MADE IT! It's long enough. Thank you!\\nJohn: Can you automate generating long text next time?\\nJane: I will.\\nJohn: You're welcome. I'm glad we could help. Goodbye!\\nJane: Goodbye!\\n[Output]\"],\"max_tokens\":1024,\"temperature\":0.1,\"top_p\":0.5,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252990,\"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\":\"18733ff5-6af1-4bfc-98b9-a6e7cc1a5005\",\"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\":947,\"completion_tokens\":56,\"total_tokens\":1003}}", + "headers": {}, + "status": 200 + }, + "uuid": "a29ad1f1-2423-4dbf-a127-fd2c93998fcd" } diff --git a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-fb3fd96e-de60-4e75-b551-493819766937.json b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-fb3fd96e-de60-4e75-b551-493819766937.json index 3156d090ae..73ef9f552e 100644 --- a/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-fb3fd96e-de60-4e75-b551-493819766937.json +++ b/java/api-test/integration-tests/src/test/resources/wiremock/mappings/deployments_text-davinci-003_completions-fb3fd96e-de60-4e75-b551-493819766937.json @@ -1,23 +1,23 @@ { - "id" : "fb3fd96e-de60-4e75-b551-493819766937", - "insertionIndex" : 33, - "name" : "deployments_text-davinci-003_completions", - "persistent" : true, - "request" : { - "bodyPatterns" : [ - { - "equalToJson" : "{\"prompt\":[\"BEGIN CONTENT TO SUMMARIZE:\\nJohn: Hello, how are you?\\nJane: I'm fine, thanks. How are you?\\nJohn: I'm doing well, writing some example code.\\nJane: That's great! I'm writing some example code too.\\nJohn: What are you writing?\\nJane: I'm writing a chatbot.\\nJohn: That's cool. I'm writing a chatbot too.\\nJane: What language are you writing it in?\\nJohn: I'm writing it in C#.\\nJane: I'm writing it in Python.\\nJohn: That's cool. I need to learn Python.\\nJane: I need to learn C#.\\nJohn: Can I try out your chatbot?\\nJane: Sure, here's the link.\\nJohn: Thanks!\\nJane: You're welcome.\\nJane: Look at this poem my chatbot wrote:\\nJane: Roses are red\\nJane: Violets are blue\\nJane: I'm writing a chatbot\\nJane: What about you?\\nJohn: That's cool. Let me see if mine will write a poem, too.\\nJohn: Here's a poem my chatbot wrote:\\nJohn: The singularity of the universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: Looks like I need to improve mine, oh well.\\nJane: You might want to try using a different model.\\nJane: I'm using the GPT-3 model.\\nJohn: I'm using the GPT-2 model. That makes sense.\\nJohn: Here is a new poem after updating the model.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: Yikes, it's really stuck isn't it. Would you help me debug my code?\\nJane: Sure, what's the problem?\\nJohn: I'm not sure. I think it's a bug in the code.\\nJane: I'll take a look.\\nJane: I think I found the problem.\\nJane: It looks like you're not passing the right parameters to the model.\\nJohn: Thanks for the help!\\nJane: I'm now writing a bot to summarize conversations. I want to make sure it works when the conversation is long.\\nJohn: So you need to keep talking with me to generate a long conversation?\\nJane: Yes, that's right.\\nJohn: Ok, I'll keep talking. What should we talk about?\\nJane: I don't know, what do you want to talk about?\\nJohn: I don't know, it's nice how CoPilot is doing most of the talking for us. But it definitely gets stuck sometimes.\\nJane: I agree, it's nice that CoPilot is doing most of the talking for us.\\nJane: But it definitely gets stuck sometimes.\\nJohn: Do you know how long it needs to be?\\nJane: I think the max length is 1024 tokens. Which is approximately 1024*4= 4096 characters.\\nJohn: That's a lot of characters.\\nJane: Yes, it is.\\nJohn: I'm not sure how much longer I can keep talking.\\n\\nEND CONTENT TO SUMMARIZE.\\n\\nSummarize the conversation in 'CONTENT TO SUMMARIZE', identifying main points of discussion and any conclusions that were reached.\\nDo not incorporate other general knowledge.\\nSummary is in plain text, in complete sentences, with no markup or tags.\\n\\nBEGIN SUMMARY:\\n\"],\"max_tokens\":1024,\"temperature\":0.1,\"top_p\":0.5,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", - "ignoreArrayOrder" : true, - "ignoreExtraElements" : true - } - ], - "method" : "POST", - "url" : "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" - }, - "response" : { - "body" : "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252979,\"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\":\"daed202a-7933-40ce-941a-4f17954f3e8d\",\"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\":771,\"completion_tokens\":91,\"total_tokens\":862}}", - "headers" : {}, - "status" : 200 - }, - "uuid" : "fb3fd96e-de60-4e75-b551-493819766937" + "id": "fb3fd96e-de60-4e75-b551-493819766937", + "insertionIndex": 33, + "name": "deployments_text-davinci-003_completions", + "persistent": true, + "request": { + "bodyPatterns": [ + { + "equalToJson": "{\"prompt\":[\"BEGIN CONTENT TO SUMMARIZE:\\nJohn: Hello, how are you?\\nJane: I'm fine, thanks. How are you?\\nJohn: I'm doing well, writing some example code.\\nJane: That's great! I'm writing some example code too.\\nJohn: What are you writing?\\nJane: I'm writing a chatbot.\\nJohn: That's cool. I'm writing a chatbot too.\\nJane: What language are you writing it in?\\nJohn: I'm writing it in C#.\\nJane: I'm writing it in Python.\\nJohn: That's cool. I need to learn Python.\\nJane: I need to learn C#.\\nJohn: Can I try out your chatbot?\\nJane: Sure, here's the link.\\nJohn: Thanks!\\nJane: You're welcome.\\nJane: Look at this poem my chatbot wrote:\\nJane: Roses are red\\nJane: Violets are blue\\nJane: I'm writing a chatbot\\nJane: What about you?\\nJohn: That's cool. Let me see if mine will write a poem, too.\\nJohn: Here's a poem my chatbot wrote:\\nJohn: The singularity of the universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: Looks like I need to improve mine, oh well.\\nJane: You might want to try using a different model.\\nJane: I'm using the GPT-3 model.\\nJohn: I'm using the GPT-2 model. That makes sense.\\nJohn: Here is a new poem after updating the model.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: The universe is a mystery.\\nJohn: Yikes, it's really stuck isn't it. Would you help me debug my code?\\nJane: Sure, what's the problem?\\nJohn: I'm not sure. I think it's a bug in the code.\\nJane: I'll take a look.\\nJane: I think I found the problem.\\nJane: It looks like you're not passing the right parameters to the model.\\nJohn: Thanks for the help!\\nJane: I'm now writing a bot to summarize conversations. I want to make sure it works when the conversation is long.\\nJohn: So you need to keep talking with me to generate a long conversation?\\nJane: Yes, that's right.\\nJohn: Ok, I'll keep talking. What should we talk about?\\nJane: I don't know, what do you want to talk about?\\nJohn: I don't know, it's nice how CoPilot is doing most of the talking for us. But it definitely gets stuck sometimes.\\nJane: I agree, it's nice that CoPilot is doing most of the talking for us.\\nJane: But it definitely gets stuck sometimes.\\nJohn: Do you know how long it needs to be?\\nJane: I think the max length is 1024 tokens. Which is approximately 1024*4= 4096 characters.\\nJohn: That's a lot of characters.\\nJane: Yes, it is.\\nJohn: I'm not sure how much longer I can keep talking.\\n\\nEND CONTENT TO SUMMARIZE.\\n\\nSummarize the conversation in 'CONTENT TO SUMMARIZE', identifying main points of discussion and any conclusions that were reached.\\nDo not incorporate other general knowledge.\\nSummary is in plain text, in complete sentences, with no markup or tags.\\n\\nBEGIN SUMMARY:\\n\"],\"max_tokens\":1024,\"temperature\":0.1,\"top_p\":0.5,\"logit_bias\":{},\"user\":\"\",\"n\":1,\"presence_penalty\":0.0,\"frequency_penalty\":0.0,\"best_of\":1,\"model\":\"text-davinci-003\"}", + "ignoreArrayOrder": true, + "ignoreExtraElements": true + } + ], + "method": "POST", + "url": "//openai/deployments/text-davinci-003/completions?api-version=2023-12-01-preview" + }, + "response": { + "body": "{\"id\":\"cmpl-xxx\",\"object\":\"text_completion\",\"created\":1707252979,\"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\":\"daed202a-7933-40ce-941a-4f17954f3e8d\",\"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\":771,\"completion_tokens\":91,\"total_tokens\":862}}", + "headers": {}, + "status": 200 + }, + "uuid": "fb3fd96e-de60-4e75-b551-493819766937" } diff --git a/java/api-test/pom.xml b/java/api-test/pom.xml index 69bb8b8c3f..db7842b0de 100644 --- a/java/api-test/pom.xml +++ b/java/api-test/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 diff --git a/java/connectors/semantickernel-connectors-web-bing/src/main/java/com/microsoft/semantickernel/connectors/web/bing/BingConnector.java b/java/connectors/semantickernel-connectors-web-bing/src/main/java/com/microsoft/semantickernel/connectors/web/bing/BingConnector.java index c4b4171855..a2ef62c366 100644 --- a/java/connectors/semantickernel-connectors-web-bing/src/main/java/com/microsoft/semantickernel/connectors/web/bing/BingConnector.java +++ b/java/connectors/semantickernel-connectors-web-bing/src/main/java/com/microsoft/semantickernel/connectors/web/bing/BingConnector.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.connectors.web.bing; import com.azure.core.http.HttpClient; diff --git a/java/plugins/semantickernel-plugin-core/src/main/java/com/microsoft/semantickernel/plugins/web/SearchUrlPlugin.java b/java/plugins/semantickernel-plugin-core/src/main/java/com/microsoft/semantickernel/plugins/web/SearchUrlPlugin.java index 96280972c2..cdf906a71a 100644 --- a/java/plugins/semantickernel-plugin-core/src/main/java/com/microsoft/semantickernel/plugins/web/SearchUrlPlugin.java +++ b/java/plugins/semantickernel-plugin-core/src/main/java/com/microsoft/semantickernel/plugins/web/SearchUrlPlugin.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.plugins.web; import com.microsoft.semantickernel.semanticfunctions.annotations.DefineKernelFunction; diff --git a/java/pom.xml b/java/pom.xml index 553e7dbf42..496bbfbd6e 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -662,11 +663,11 @@ true + --> // Copyright (c) Microsoft. All rights reserved. - - --> + diff --git a/java/samples/pom.xml b/java/samples/pom.xml index 540edd4b33..cdda4c4989 100644 --- a/java/samples/pom.xml +++ b/java/samples/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 com.microsoft.semantic-kernel @@ -130,8 +131,8 @@ ${project.build.sourceEncoding} true - - + + diff --git a/java/samples/sample-code/pom.xml b/java/samples/sample-code/pom.xml index 21efb67c9b..118d40bf8a 100644 --- a/java/samples/sample-code/pom.xml +++ b/java/samples/sample-code/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 com.microsoft.semantic-kernel diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/plugins/ConversationSummaryPlugin.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/plugins/ConversationSummaryPlugin.java index b486c24cad..089a4941ee 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/plugins/ConversationSummaryPlugin.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/plugins/ConversationSummaryPlugin.java @@ -1,10 +1,11 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.plugins; import com.microsoft.semantickernel.Kernel; +import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; +import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; -import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; -import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; import com.microsoft.semantickernel.semanticfunctions.annotations.DefineKernelFunction; import com.microsoft.semantickernel.semanticfunctions.annotations.KernelFunctionParameter; import com.microsoft.semantickernel.text.TextChunker; @@ -60,6 +61,27 @@ public class ConversationSummaryPlugin { .build(); } + private static Mono processAsync(KernelFunction func, String input, + Kernel kernel) { + List lines = TextChunker.splitPlainTextLines(input, MaxTokens); + List paragraphs = TextChunker.splitPlainTextParagraphs(lines, MaxTokens); + + return Flux.fromIterable(paragraphs) + .concatMap(paragraph -> { + // The first parameter is the input text. + return func.invokeAsync(kernel) + .withArguments( + new KernelFunctionArguments.Builder() + .withInput(paragraph) + .build()) + .withResultType( + ContextVariableTypes.getGlobalVariableTypeForClass(String.class)); + }) + .reduce("", (acc, next) -> { + return acc + "\n" + next.getResult(); + }); + } + /// /// Given a long conversation transcript, summarize the conversation. /// @@ -96,25 +118,4 @@ public class ConversationSummaryPlugin { Kernel kernel) { return processAsync(this.conversationTopicsFunction, input, kernel); } - - private static Mono processAsync(KernelFunction func, String input, - Kernel kernel) { - List lines = TextChunker.splitPlainTextLines(input, MaxTokens); - List paragraphs = TextChunker.splitPlainTextParagraphs(lines, MaxTokens); - - return Flux.fromIterable(paragraphs) - .concatMap(paragraph -> { - // The first parameter is the input text. - return func.invokeAsync(kernel) - .withArguments( - new KernelFunctionArguments.Builder() - .withInput(paragraph) - .build()) - .withResultType( - ContextVariableTypes.getGlobalVariableTypeForClass(String.class)); - }) - .reduce("", (acc, next) -> { - return acc + "\n" + next.getResult(); - }); - } } diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/plugins/PromptFunctionConstants.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/plugins/PromptFunctionConstants.java index 324e2bad73..e88e6ba34a 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/plugins/PromptFunctionConstants.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/plugins/PromptFunctionConstants.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.plugins; public class PromptFunctionConstants { diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example01_NativeFunctions.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example01_NativeFunctions.java index 0bc76d4739..5b71f675b0 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example01_NativeFunctions.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example01_NativeFunctions.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.microsoft.semantickernel.plugins.text.TextPlugin; diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example03_Arguments.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example03_Arguments.java index d6fab4495f..dbca6fd24e 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example03_Arguments.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example03_Arguments.java @@ -3,9 +3,9 @@ package com.microsoft.semantickernel.samples.syntaxexamples; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.orchestration.FunctionResult; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.plugin.KernelPlugin; import com.microsoft.semantickernel.plugin.KernelPluginFactory; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.annotations.DefineKernelFunction; import com.microsoft.semantickernel.semanticfunctions.annotations.KernelFunctionParameter; import java.util.Locale; @@ -17,22 +17,6 @@ import reactor.core.publisher.Mono; */ public class Example03_Arguments { - public static class StaticTextPlugin { - - @DefineKernelFunction(description = "Change all string chars to uppercase.", name = "Uppercase", returnType = "java.lang.String") - public static Mono uppercase( - @KernelFunctionParameter(description = "Text to uppercase", name = "input") String text) { - return Mono.just(text.toUpperCase(Locale.ROOT)); - } - - @DefineKernelFunction(description = "Append the day variable", name = "appendDay", returnType = "java.lang.String") - public Mono appendDay( - @KernelFunctionParameter(description = "Text to append to", name = "input") String input, - @KernelFunctionParameter(description = "Current day", name = "day") String day) { - return Mono.just(input + day); - } - } - public static void main(String[] args) { Kernel kernel = Kernel.builder().build(); @@ -51,4 +35,20 @@ public class Example03_Arguments { System.out.println(resultValue.getResult()); } + + public static class StaticTextPlugin { + + @DefineKernelFunction(description = "Change all string chars to uppercase.", name = "Uppercase", returnType = "java.lang.String") + public static Mono uppercase( + @KernelFunctionParameter(description = "Text to uppercase", name = "input") String text) { + return Mono.just(text.toUpperCase(Locale.ROOT)); + } + + @DefineKernelFunction(description = "Append the day variable", name = "appendDay", returnType = "java.lang.String") + public Mono appendDay( + @KernelFunctionParameter(description = "Text to append to", name = "input") String input, + @KernelFunctionParameter(description = "Current day", name = "day") String day) { + return Mono.just(input + day); + } + } } diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example05_InlineFunctionDefinition.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example05_InlineFunctionDefinition.java index c70882f233..bce940b69a 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example05_InlineFunctionDefinition.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example05_InlineFunctionDefinition.java @@ -8,9 +8,9 @@ import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.exceptions.ConfigurationException; import com.microsoft.semantickernel.orchestration.FunctionResult; +import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; -import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; import com.microsoft.semantickernel.services.textcompletion.TextGenerationService; import java.time.Instant; diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example06_TemplateLanguage.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example06_TemplateLanguage.java index 6f305c79b9..4d5aa71aae 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example06_TemplateLanguage.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example06_TemplateLanguage.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -7,13 +8,13 @@ import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.aiservices.openai.textcompletion.OpenAITextGenerationService; import com.microsoft.semantickernel.exceptions.ConfigurationException; -import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.plugin.KernelPlugin; import com.microsoft.semantickernel.plugin.KernelPluginFactory; -import com.microsoft.semantickernel.semanticfunctions.annotations.DefineKernelFunction; +import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.semanticfunctions.KernelPromptTemplateFactory; import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig; +import com.microsoft.semantickernel.semanticfunctions.annotations.DefineKernelFunction; import com.microsoft.semantickernel.services.textcompletion.TextGenerationService; public class Example06_TemplateLanguage { @@ -26,19 +27,6 @@ public class Example06_TemplateLanguage { private static final String MODEL_ID = System.getenv() .getOrDefault("MODEL_ID", "text-davinci-003"); - public static class Time { - - @DefineKernelFunction(name = "date") - public String date() { - return "2021-09-01"; - } - - @DefineKernelFunction(name = "time") - public String time() { - return "12:00:00"; - } - } - public static void main(String[] args) throws ConfigurationException { System.out.println("======== TemplateLanguage ========"); @@ -104,4 +92,17 @@ public class Example06_TemplateLanguage { var result = kernel.invokeAsync(kindOfDay).block(); System.out.println(result.getResult()); } + + public static class Time { + + @DefineKernelFunction(name = "date") + public String date() { + return "2021-09-01"; + } + + @DefineKernelFunction(name = "time") + public String time() { + return "12:00:00"; + } + } } diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example07_BingAndGooglePlugins.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example07_BingAndGooglePlugins.java index b859124bbf..66c2826310 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example07_BingAndGooglePlugins.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example07_BingAndGooglePlugins.java @@ -6,18 +6,18 @@ import com.azure.ai.openai.OpenAIClientBuilder; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; import com.microsoft.semantickernel.connectors.web.bing.BingConnector; import com.microsoft.semantickernel.orchestration.FunctionResult; -import com.microsoft.semantickernel.semanticfunctions.KernelFunction; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.plugin.KernelPluginFactory; import com.microsoft.semantickernel.plugins.web.WebSearchEnginePlugin; +import com.microsoft.semantickernel.semanticfunctions.KernelFunction; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; import com.microsoft.semantickernel.semanticfunctions.KernelPromptTemplateFactory; import com.microsoft.semantickernel.semanticfunctions.PromptTemplate; import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; /// /// The example shows how to use Bing and Google to search for current data @@ -96,7 +96,7 @@ public class Example07_BingAndGooglePlugins { /* * OUTPUT: - * + * * What's the largest building in the world? * ---- * The Aerium near Berlin, Germany is the largest uninterrupted volume in the world, while @@ -202,11 +202,11 @@ public class Example07_BingAndGooglePlugins { /* * OUTPUT: - * + * * Who is the most followed person on TikTok right now? What's the exchange rate EUR:USD? * ---- Fetching information from Bing... * Information found: - * + * * Khaby Lame is the most-followed user on TikTok. This list contains the top 50 accounts by * number * of followers on the Chinese social media platform TikTok, which was merged with @@ -220,7 +220,7 @@ public class Example07_BingAndGooglePlugins { * rate when sending money. Check send rates Convert Euro to US Dollar Convert US Dollar to * Euro.. * ---- ANSWER: - * + * * The most followed person on TikTok right now is Khaby Lame, with over 153 million * followers. * The exchange rate for EUR to USD is 1.1037097 US Dollars for 1 Euro. diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example08_RetryHandler.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example08_RetryHandler.java index ad7c283756..a1881feab3 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example08_RetryHandler.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example08_RetryHandler.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -41,7 +42,9 @@ public class Example08_RetryHandler { String question = "How popular is the Polly library?"; - KernelFunction fuction = KernelFunctionFromPrompt.create(question); + KernelFunction fuction = KernelFunctionFromPrompt.builder() + .withTemplate(question) + .build(); try { // Will retry 3 times with exponential backoff diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example09_FunctionTypes.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example09_FunctionTypes.java index 30a886434c..2ee6e28883 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example09_FunctionTypes.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example09_FunctionTypes.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import static com.microsoft.semantickernel.contextvariables.ContextVariableTypes.convert; @@ -8,14 +9,14 @@ import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.aiservices.openai.textcompletion.OpenAITextGenerationService; -import com.microsoft.semantickernel.orchestration.FunctionResult; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.contextvariables.ContextVariable; import com.microsoft.semantickernel.contextvariables.ContextVariableType; import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter.NoopConverter; +import com.microsoft.semantickernel.orchestration.FunctionResult; import com.microsoft.semantickernel.plugin.KernelPlugin; import com.microsoft.semantickernel.plugin.KernelPluginFactory; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.annotations.DefineKernelFunction; import com.microsoft.semantickernel.semanticfunctions.annotations.KernelFunctionParameter; import com.microsoft.semantickernel.services.textcompletion.TextGenerationService; @@ -43,38 +44,6 @@ public class Example09_FunctionTypes { private static final String MODEL_ID = System.getenv() .getOrDefault("MODEL_ID", "text-davinci-003"); - private static class DateTimeContextVariableTypeConverter extends - ContextVariableTypeConverter { - - private static final List> converters = List.of( - new DefaultConverter<>(ZonedDateTime.class, Date.class) { - @Override - public Date toObject(ZonedDateTime zonedDateTime) { - return new Date(zonedDateTime.toInstant().toEpochMilli()); - } - }, - new DefaultConverter<>(ZonedDateTime.class, String.class) { - @Override - public String toObject(ZonedDateTime zonedDateTime) { - return zonedDateTime.format(DateTimeFormatter.ISO_DATE_TIME); - } - }); - - public DateTimeContextVariableTypeConverter() { - super( - ZonedDateTime.class, - (x) -> { - if (x instanceof OffsetDateTime) { - return ((OffsetDateTime) x).toZonedDateTime(); - } - return convert(x, ZonedDateTime.class); - }, - zonedDateTime -> zonedDateTime.format(DateTimeFormatter.ISO_DATE_TIME), - promptString -> ZonedDateTime.parse(promptString, DateTimeFormatter.ISO_DATE_TIME), - converters); - } - } - public static void main(String[] args) throws InterruptedException { System.out.println("======== Method Function types ========"); @@ -161,7 +130,7 @@ public class Example09_FunctionTypes { .block(); System.out.println(result.getResult()); - kernel.invokeAsync(plugin.get("MultipleInputsWithVoidResult")) + result = kernel.invokeAsync(plugin.get("MultipleInputsWithVoidResult")) .withArguments( KernelFunctionArguments .builder() @@ -170,7 +139,6 @@ public class Example09_FunctionTypes { .withVariable("z", 1.5) .build()) .block(); - System.out.println(result.getResult()); result = kernel .invokeAsync(plugin.get("ComplexInputWithStringResult")) @@ -285,6 +253,15 @@ public class Example09_FunctionTypes { .block(); System.out.println(result9.getResult()); + result = kernel.invokeAsync(plugin.get("MultipleComplexInputsWithVoidResult")) + .withArguments( + KernelFunctionArguments + .builder() + .withVariable("x", OffsetDateTime.of(1, 1, 1, 1, 1, 1, 1, ZoneOffset.UTC)) + .withVariable("y", OffsetDateTime.of(1, 1, 1, 1, 1, 1, 1, ZoneOffset.UTC)) + .build()) + .withTypeConverter(new DateTimeContextVariableTypeConverter()) + .block(); /* * TODO: support FunctionResult * kernel @@ -292,7 +269,7 @@ public class Example09_FunctionTypes { * null, * Void.class) * .block(); - * + * */ /* @@ -319,7 +296,7 @@ public class Example09_FunctionTypes { * with Visual Basic's simplicity. It's ideal for a wide range of applications, * emphasizing type safety, modularity, and modern programming paradigms." * }); - * + * */ // You can also use the kernel.Plugins collection to invoke a function @@ -329,6 +306,38 @@ public class Example09_FunctionTypes { .block(); } + private static class DateTimeContextVariableTypeConverter extends + ContextVariableTypeConverter { + + private static final List> converters = List.of( + new DefaultConverter<>(ZonedDateTime.class, Date.class) { + @Override + public Date toObject(ZonedDateTime zonedDateTime) { + return new Date(zonedDateTime.toInstant().toEpochMilli()); + } + }, + new DefaultConverter<>(ZonedDateTime.class, String.class) { + @Override + public String toObject(ZonedDateTime zonedDateTime) { + return zonedDateTime.format(DateTimeFormatter.ISO_DATE_TIME); + } + }); + + public DateTimeContextVariableTypeConverter() { + super( + ZonedDateTime.class, + (x) -> { + if (x instanceof OffsetDateTime) { + return ((OffsetDateTime) x).toZonedDateTime(); + } + return convert(x, ZonedDateTime.class); + }, + zonedDateTime -> zonedDateTime.format(DateTimeFormatter.ISO_DATE_TIME), + promptString -> ZonedDateTime.parse(promptString, DateTimeFormatter.ISO_DATE_TIME), + converters); + } + } + public static class LocalExamplePlugin { /// @@ -465,11 +474,21 @@ public class Example09_FunctionTypes { return OffsetDateTime.of(1, 1, 1, 1, 1, 1, 1, ZoneOffset.UTC); } + @DefineKernelFunction(name = "MultipleComplexInputsWithVoidResult") + public void MultipleComplexInputsWithVoidResult( + @KernelFunctionParameter(name = "x", type = ZonedDateTime.class) ZonedDateTime x, + + @KernelFunctionParameter(name = "y", type = ZonedDateTime.class) ZonedDateTime y) { + System.out.println( + "Running {nameof(this.MultipleComplexInputsWithVoidResult)} -> input: [x = {" + x + + "}, y = {" + y + "}]"); + } + /* * /// * /// Example using a function to return the result of another inner function * /// - * + * * @DefineKernelFunction(name = "InputStringTaskWithVoidResult") * public FunctionResult NoInputWithFunctionResult() * { @@ -483,7 +502,7 @@ public class Example09_FunctionTypes { */ /* - * + * * /// * /// Example using a task function to return the result of another kernel function * /// @@ -497,7 +516,7 @@ public class Example09_FunctionTypes { * ); * return result; * } - * + * * /// * /// Example how to inject Kernel in your function * /// This example uses the injected kernel to invoke a plugin from within another function @@ -514,7 +533,7 @@ public class Example09_FunctionTypes { * ); * return summary!; * } - * + * * /// * /// Example how to inject the executing KernelFunction as a parameter * /// @@ -529,7 +548,7 @@ public class Example09_FunctionTypes { * ); * return result; * } - * + * * /// * /// Example how to inject ILogger in your function * /// @@ -543,7 +562,7 @@ public class Example09_FunctionTypes { * ); * return Task.CompletedTask; * } - * + * * /// * /// Example how to inject ILoggerFactory in your function * /// @@ -554,13 +573,13 @@ public class Example09_FunctionTypes { * .CreateLogger() * .LogWarning("Running {FunctionName} -> Injected Logger", * nameof(this.TaskInjectingLoggerWithNoResult)); - * + * * Console.WriteLine( * $"Running {nameof(this.TaskInjectingKernelWithInputTextAndStringResult)} -> Injected Logger" * ); * return Task.CompletedTask; * } - * + * * /// * /// Example how to inject a service selector in your function and use a specific service * /// @@ -575,14 +594,14 @@ public class Example09_FunctionTypes { * chatMessageContent = await chatCompletion.GetChatMessageContentAsync(new * ChatHistory("How much is 5 + 5 ?"), executionSettings); * } - * + * * var result = chatMessageContent?.Content; * Console.WriteLine( * $"Running {nameof(this.TaskInjectingKernelWithInputTextAndStringResult)} -> Injected Kernel, KernelFunction, KernelArguments, Service Selector -> result: {result}" * ); * return result ?? string.Empty; * } - * + * * /// * /// Example how to inject CultureInfo or IFormatProvider in your function * /// @@ -598,7 +617,7 @@ public class Example09_FunctionTypes { * ); * return result; * } - * + * * /// * /// Example how to inject current CancellationToken in your function * /// @@ -612,12 +631,12 @@ public class Example09_FunctionTypes { * ); * return result; * } - * + * * public override string ToString() * { * return "Complex type result ToString override"; * } - * + * */ } } diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example10_DescribeAllPluginsAndFunctions.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example10_DescribeAllPluginsAndFunctions.java index a558b1f281..9b9ffd5641 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example10_DescribeAllPluginsAndFunctions.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example10_DescribeAllPluginsAndFunctions.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -6,14 +7,14 @@ import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.aiservices.openai.textcompletion.OpenAITextGenerationService; -import com.microsoft.semantickernel.semanticfunctions.KernelFunction; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionMetadata; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.plugin.KernelPluginFactory; +import com.microsoft.semantickernel.plugins.text.TextPlugin; +import com.microsoft.semantickernel.semanticfunctions.KernelFunction; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionMetadata; import com.microsoft.semantickernel.semanticfunctions.annotations.DefineKernelFunction; import com.microsoft.semantickernel.semanticfunctions.annotations.KernelFunctionParameter; -import com.microsoft.semantickernel.plugins.text.TextPlugin; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; import com.microsoft.semantickernel.services.textcompletion.TextGenerationService; import java.nio.file.Path; import java.util.Locale; @@ -30,22 +31,6 @@ public class Example10_DescribeAllPluginsAndFunctions { private static final String MODEL_ID = System.getenv() .getOrDefault("MODEL_ID", "text-davinci-003"); - public static class StaticTextPlugin { - - @DefineKernelFunction(description = "Change all string chars to uppercase", name = "uppercase") - public static String uppercase( - @KernelFunctionParameter(description = "Text to uppercase", name = "input") String input) { - return input.toUpperCase(Locale.ROOT); - } - - @DefineKernelFunction(description = "Append the day variable", name = "appendDay") - public String appendDay( - @KernelFunctionParameter(description = "Append the day variable", name = "appendDay") String input, - @KernelFunctionParameter(description = "Value of the day to append", name = "day") String day) { - return input + day; - } - } - /// /// Print a list of all the functions imported into the kernel, including function descriptions, /// list of parameters, parameters descriptions, etc. @@ -143,4 +128,20 @@ public class Example10_DescribeAllPluginsAndFunctions { System.out.println(); } + + public static class StaticTextPlugin { + + @DefineKernelFunction(description = "Change all string chars to uppercase", name = "uppercase") + public static String uppercase( + @KernelFunctionParameter(description = "Text to uppercase", name = "input") String input) { + return input.toUpperCase(Locale.ROOT); + } + + @DefineKernelFunction(description = "Append the day variable", name = "appendDay") + public String appendDay( + @KernelFunctionParameter(description = "Append the day variable", name = "appendDay") String input, + @KernelFunctionParameter(description = "Value of the day to append", name = "day") String day) { + return input + day; + } + } } \ No newline at end of file diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example11_WebSearchQueries.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example11_WebSearchQueries.java index 486b8bec4e..6796a7790e 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example11_WebSearchQueries.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example11_WebSearchQueries.java @@ -1,9 +1,10 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.plugin.KernelPluginFactory; import com.microsoft.semantickernel.plugins.web.SearchUrlPlugin; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; public class Example11_WebSearchQueries { diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example13_ConversationSummaryPlugin.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example13_ConversationSummaryPlugin.java index 84f52e47ed..78291333b1 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example13_ConversationSummaryPlugin.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example13_ConversationSummaryPlugin.java @@ -9,15 +9,16 @@ import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.aiservices.openai.textcompletion.OpenAITextGenerationService; import com.microsoft.semantickernel.exceptions.ConfigurationException; import com.microsoft.semantickernel.orchestration.FunctionResult; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments.Builder; import com.microsoft.semantickernel.plugin.KernelPlugin; import com.microsoft.semantickernel.plugin.KernelPluginFactory; import com.microsoft.semantickernel.samples.plugins.ConversationSummaryPlugin; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments.Builder; import com.microsoft.semantickernel.services.textcompletion.TextGenerationService; import reactor.core.publisher.Mono; /** - * Demonstrate the {@see com.microsoft.semantickernel.samples.plugins.ConversationSummaryPlugin} plugin. + * Demonstrate the {@see com.microsoft.semantickernel.samples.plugins.ConversationSummaryPlugin} + * plugin. *

* Refer to the diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example17_ChatGPT.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example17_ChatGPT.java index 2e81be0655..16b701ef6d 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example17_ChatGPT.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example17_ChatGPT.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example26_AADAuth.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example26_AADAuth.java index 85ee544f5b..59c607308e 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example26_AADAuth.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example26_AADAuth.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -5,9 +6,9 @@ import com.azure.ai.openai.OpenAIClientBuilder; import com.azure.identity.DeviceCodeCredential; import com.azure.identity.DeviceCodeCredentialBuilder; import com.microsoft.semantickernel.Kernel; +import com.microsoft.semantickernel.exceptions.ConfigurationException; import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; import com.microsoft.semantickernel.services.chatcompletion.ChatHistory; -import com.microsoft.semantickernel.exceptions.ConfigurationException; public class Example26_AADAuth { diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example27_PromptFunctionsUsingChatGPT.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example27_PromptFunctionsUsingChatGPT.java index 6a0c65ac02..f126aca804 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example27_PromptFunctionsUsingChatGPT.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example27_PromptFunctionsUsingChatGPT.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -5,10 +6,10 @@ import com.azure.ai.openai.OpenAIClientBuilder; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; +import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; -import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; public class Example27_PromptFunctionsUsingChatGPT { diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example30_ChatWithPrompts.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example30_ChatWithPrompts.java index f2202d6741..5830afce7a 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example30_ChatWithPrompts.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example30_ChatWithPrompts.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -5,16 +6,16 @@ import com.azure.ai.openai.OpenAIClientBuilder; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; -import com.microsoft.semantickernel.services.chatcompletion.ChatHistory; import com.microsoft.semantickernel.implementation.EmbeddedResourceLoader; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.plugin.KernelPlugin; import com.microsoft.semantickernel.plugin.KernelPluginFactory; import com.microsoft.semantickernel.samples.plugins.TimePlugin; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig; import com.microsoft.semantickernel.semanticfunctions.PromptTemplateFactory; import com.microsoft.semantickernel.services.ServiceNotFoundException; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; +import com.microsoft.semantickernel.services.chatcompletion.ChatHistory; import java.io.FileNotFoundException; import java.time.ZoneId; import java.time.ZonedDateTime; diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example33_Chat.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example33_Chat.java index 6f9dca94b6..0d498ed2a5 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example33_Chat.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example33_Chat.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example41_HttpClientUsage.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example41_HttpClientUsage.java index b579379925..30ddafb77e 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example41_HttpClientUsage.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example41_HttpClientUsage.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example42_KernelBuilder.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example42_KernelBuilder.java index 1f2e5a959f..ddbe5deb5b 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example42_KernelBuilder.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example42_KernelBuilder.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -6,10 +7,10 @@ import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.azure.core.http.HttpClient; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; import com.microsoft.semantickernel.plugin.KernelPluginFactory; import com.microsoft.semantickernel.samples.plugins.ConversationSummaryPlugin; import com.microsoft.semantickernel.services.OrderedAIServiceSelector; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; import com.microsoft.semantickernel.services.textcompletion.TextGenerationService; import java.util.ArrayList; diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example43_GetModelResult.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example43_GetModelResult.java index a973ea6f9c..9d2f371c1f 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example43_GetModelResult.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example43_GetModelResult.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -6,11 +7,11 @@ import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatCompletion; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; import com.microsoft.semantickernel.orchestration.FunctionResult; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; public class Example43_GetModelResult { @@ -52,8 +53,8 @@ public class Example43_GetModelResult { // Create function String FunctionDefinition = "Hi, give me 5 book suggestions about: {{$input}}"; - KernelFunction myFunction = KernelFunctionFromPrompt.create( - FunctionDefinition); + KernelFunction myFunction = KernelFunctionFromPrompt.builder() + .withTemplate(FunctionDefinition).build(); // Invoke function through kernel FunctionResult result = kernel.invokeAsync( diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example44_MultiChatCompletion.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example44_MultiChatCompletion.java index cc81ddac46..5384291eee 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example44_MultiChatCompletion.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example44_MultiChatCompletion.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -5,10 +6,10 @@ import com.azure.ai.openai.OpenAIClientBuilder; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatCompletion; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; -import com.microsoft.semantickernel.services.chatcompletion.ChatHistory; import com.microsoft.semantickernel.orchestration.InvocationContext; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; +import com.microsoft.semantickernel.services.chatcompletion.ChatHistory; public class Example44_MultiChatCompletion { diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example49_LogitBias.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example49_LogitBias.java index fa7599f6e4..6d961b9ede 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example49_LogitBias.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example49_LogitBias.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -5,10 +6,10 @@ import com.azure.ai.openai.OpenAIClientBuilder; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; -import com.microsoft.semantickernel.services.chatcompletion.ChatHistory; import com.microsoft.semantickernel.orchestration.InvocationContext; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; +import com.microsoft.semantickernel.services.chatcompletion.ChatHistory; import java.util.Arrays; import java.util.HashMap; import java.util.Map; diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example55_TextChunker.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example55_TextChunker.java index 7738ec9a2e..8b171d7e00 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example55_TextChunker.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example55_TextChunker.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.microsoft.semantickernel.text.TextChunker; diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example56_TemplateMethodFunctionsWithMultipleArguments.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example56_TemplateMethodFunctionsWithMultipleArguments.java index b5727fd5ae..24929e7e9b 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example56_TemplateMethodFunctionsWithMultipleArguments.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example56_TemplateMethodFunctionsWithMultipleArguments.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -6,14 +7,14 @@ import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatCompletion; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.plugin.KernelPluginFactory; import com.microsoft.semantickernel.plugins.text.TextPlugin; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; import com.microsoft.semantickernel.semanticfunctions.KernelPromptTemplateFactory; import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; public class Example56_TemplateMethodFunctionsWithMultipleArguments { diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example57_KernelHooks.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example57_KernelHooks.java index 763c24eef3..309cbd6d90 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example57_KernelHooks.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example57_KernelHooks.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -10,7 +11,7 @@ import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.Kernel.Builder; import com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatCompletion; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; +import com.microsoft.semantickernel.contextvariables.ContextVariable; import com.microsoft.semantickernel.hooks.FunctionInvokedEvent; import com.microsoft.semantickernel.hooks.KernelHook.FunctionInvokedHook; import com.microsoft.semantickernel.hooks.KernelHook.FunctionInvokingHook; @@ -21,11 +22,11 @@ import com.microsoft.semantickernel.hooks.KernelHooks; import com.microsoft.semantickernel.hooks.PreChatCompletionEvent; import com.microsoft.semantickernel.hooks.PromptRenderedEvent; import com.microsoft.semantickernel.orchestration.FunctionResult; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; -import com.microsoft.semantickernel.contextvariables.ContextVariable; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; import com.microsoft.semantickernel.semanticfunctions.OutputVariable; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -288,8 +289,10 @@ public class Example57_KernelHooks { System.out.println("\n======== Cancelling Pipeline Execution - Invoked event ========\n"); // Initialize prompts - var firstFunction = KernelFunctionFromPrompt.create("Write a phrase with Invoke."); - var secondFunction = KernelFunctionFromPrompt.create("Write a phrase with Cancellation."); + var firstFunction = KernelFunctionFromPrompt.builder() + .withTemplate("Write a phrase with Invoke.").build(); + var secondFunction = KernelFunctionFromPrompt.builder() + .withTemplate("Write a phrase with Cancellation.").build(); AtomicInteger invokingCounter = new AtomicInteger(0); kernel.getGlobalKernelHooks().addHook((FunctionInvokingHook) event -> { diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example58_ConfigureExecutionSettings.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example58_ConfigureExecutionSettings.java index 8915b357ed..0315e60fba 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example58_ConfigureExecutionSettings.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example58_ConfigureExecutionSettings.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -6,12 +7,12 @@ import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatCompletion; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; -import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; +import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; import com.microsoft.semantickernel.semanticfunctions.OutputVariable; import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; public class Example58_ConfigureExecutionSettings { @@ -88,7 +89,9 @@ public class Example58_ConfigureExecutionSettings { var promptConfig = PromptTemplateConfig .parseFromJson(configPayload) - .setTemplate(prompt); + .copy() + .withTemplate(prompt) + .build(); var func = KernelFunction .createFromPrompt(promptConfig) diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example59_OpenAIFunctionCalling.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example59_OpenAIFunctionCalling.java index 3a66d72f64..76bf55927c 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example59_OpenAIFunctionCalling.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example59_OpenAIFunctionCalling.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -6,16 +7,16 @@ import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatCompletion; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; -import com.microsoft.semantickernel.semanticfunctions.KernelFunction; +import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.orchestration.ToolCallBehavior; -import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; import com.microsoft.semantickernel.plugin.KernelPlugin; import com.microsoft.semantickernel.plugin.KernelPluginFactory; +import com.microsoft.semantickernel.semanticfunctions.KernelFunction; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; import com.microsoft.semantickernel.semanticfunctions.annotations.DefineKernelFunction; import com.microsoft.semantickernel.semanticfunctions.annotations.KernelFunctionParameter; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; public class Example59_OpenAIFunctionCalling { @@ -27,33 +28,6 @@ public class Example59_OpenAIFunctionCalling { private static final String MODEL_ID = System.getenv() .getOrDefault("MODEL_ID", "gpt-35-turbo-2"); - public static class Plugin { - @DefineKernelFunction(name = "getLatitudeOfCity", description = "Gets the latitude of a given city") - public String getLatitudeOfCity( - @KernelFunctionParameter(name = "cityName", description = "City name") String cityName) { - return "1.0"; - } - - @DefineKernelFunction(name = "getLongitudeOfCity", description = "Gets the longitude of a given city") - public String getLongitudeOfCity( - @KernelFunctionParameter(name = "cityName", description = "City name") String cityName) { - return "2.0"; - } - - @DefineKernelFunction(name = "getsTheWeatherAtAGivenLocation", description = "Gets the current weather at a given longitude and latitude") - public String getWeatherForCityAtTime( - @KernelFunctionParameter(name = "latitude", description = "latitude of the location") String latitude, - @KernelFunctionParameter(name = "longitude", description = "longitude of the location") String longitude) { - return "61 and rainy"; - } - - @DefineKernelFunction(name = "getsTheWeatherForCity", description = "Gets the current weather at a city name") - public String getsTheWeatherForCity( - @KernelFunctionParameter(name = "cityName", description = "Name of the city") String cityName) { - return "80 and sunny"; - } - } - public static void main(String[] args) throws NoSuchMethodException { System.out.println("======== Open AI - Function calling ========"); @@ -156,4 +130,32 @@ public class Example59_OpenAIFunctionCalling { System.out.println(result.getResult()); } + + public static class Plugin { + + @DefineKernelFunction(name = "getLatitudeOfCity", description = "Gets the latitude of a given city") + public String getLatitudeOfCity( + @KernelFunctionParameter(name = "cityName", description = "City name") String cityName) { + return "1.0"; + } + + @DefineKernelFunction(name = "getLongitudeOfCity", description = "Gets the longitude of a given city") + public String getLongitudeOfCity( + @KernelFunctionParameter(name = "cityName", description = "City name") String cityName) { + return "2.0"; + } + + @DefineKernelFunction(name = "getsTheWeatherAtAGivenLocation", description = "Gets the current weather at a given longitude and latitude") + public String getWeatherForCityAtTime( + @KernelFunctionParameter(name = "latitude", description = "latitude of the location") String latitude, + @KernelFunctionParameter(name = "longitude", description = "longitude of the location") String longitude) { + return "61 and rainy"; + } + + @DefineKernelFunction(name = "getsTheWeatherForCity", description = "Gets the current weather at a city name") + public String getsTheWeatherForCity( + @KernelFunctionParameter(name = "cityName", description = "Name of the city") String cityName) { + return "80 and sunny"; + } + } } diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example60_AdvancedMethodFunctions.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example60_AdvancedMethodFunctions.java index 0b564ea751..4e7eaac079 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example60_AdvancedMethodFunctions.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example60_AdvancedMethodFunctions.java @@ -1,10 +1,11 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; import com.microsoft.semantickernel.plugin.KernelPluginFactory; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.annotations.DefineKernelFunction; import reactor.core.publisher.Mono; diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example61_MultipleLLMs.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example61_MultipleLLMs.java index 7a69df800e..3ab911b7bd 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example61_MultipleLLMs.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example61_MultipleLLMs.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -5,12 +6,12 @@ import com.azure.ai.openai.OpenAIClientBuilder; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; +import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; -import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; import com.microsoft.semantickernel.services.textcompletion.TextGenerationService; import java.util.Arrays; import java.util.HashMap; @@ -124,11 +125,14 @@ public class Example61_MultipleLLMs { .build()); }); - var promptConfig = new PromptTemplateConfig(prompt); - promptConfig.setName("HelloAI"); - promptConfig.setExecutionSettings(modelSettings); + var promptConfig = PromptTemplateConfig.defaultTemplateBuilder() + .withTemplate(prompt) + .withName("HelloAI") + .withExecutionSettings(modelSettings) + .build(); - var function = KernelFunctionFromPrompt.create(promptConfig); + var function = KernelFunctionFromPrompt.builder().withPromptTemplateConfig(promptConfig) + .build(); var result = kernel.invokeAsync(function) .withArguments(KernelFunctionArguments.builder().build()) diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example62_CustomAIServiceSelector.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example62_CustomAIServiceSelector.java index b14e0399fd..be296705f5 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example62_CustomAIServiceSelector.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example62_CustomAIServiceSelector.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -5,15 +6,15 @@ import com.azure.ai.openai.OpenAIClientBuilder; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; +import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; -import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; import com.microsoft.semantickernel.services.AIService; -import com.microsoft.semantickernel.services.AIServiceSelection; import com.microsoft.semantickernel.services.AIServiceCollection; +import com.microsoft.semantickernel.services.AIServiceSelection; import com.microsoft.semantickernel.services.BaseAIServiceSelector; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; import com.microsoft.semantickernel.services.textcompletion.TextGenerationService; import java.util.Map; import javax.annotation.Nullable; diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example63_ChatCompletionPrompts.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example63_ChatCompletionPrompts.java index 9388c88384..89006440da 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example63_ChatCompletionPrompts.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example63_ChatCompletionPrompts.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -5,8 +6,8 @@ import com.azure.ai.openai.OpenAIClientBuilder; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; import java.util.concurrent.CountDownLatch; public class Example63_ChatCompletionPrompts { @@ -49,7 +50,8 @@ public class Example63_ChatCompletionPrompts { Respond with JSON. """.stripIndent(); - var chatSemanticFunction = KernelFunctionFromPrompt.create(chatPrompt); + var chatSemanticFunction = KernelFunctionFromPrompt.builder() + .withTemplate(chatPrompt).build(); var chatPromptResult = kernel.invokeAsync(chatSemanticFunction).block(); System.out.println("Chat Prompt:"); diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example64_MultiplePromptTemplates.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example64_MultiplePromptTemplates.java index 186504e308..28fe19d821 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example64_MultiplePromptTemplates.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example64_MultiplePromptTemplates.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.azure.ai.openai.OpenAIAsyncClient; @@ -6,13 +7,13 @@ import com.azure.core.credential.AzureKeyCredential; import com.azure.core.credential.KeyCredential; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatCompletion; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.AggregatorPromptTemplateFactory; import com.microsoft.semantickernel.semanticfunctions.HandlebarsPromptTemplateFactory; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; import com.microsoft.semantickernel.semanticfunctions.KernelPromptTemplateFactory; import com.microsoft.semantickernel.semanticfunctions.PromptTemplateFactory; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; import java.util.List; public class Example64_MultiplePromptTemplates { diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example67_KernelStreaming.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example67_KernelStreaming.java index bbc11dc21c..36a0a42488 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example67_KernelStreaming.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example67_KernelStreaming.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; /* diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example69_MutableKernelPlugin.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example69_MutableKernelPlugin.java index 8a4bc0f462..4200a1688e 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example69_MutableKernelPlugin.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example69_MutableKernelPlugin.java @@ -1,20 +1,13 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.plugin.KernelPlugin; +import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.semanticfunctions.annotations.DefineKernelFunction; public class Example69_MutableKernelPlugin { - public static class Time { - - @DefineKernelFunction(name = "date") - public String date() { - return "2021-09-01"; - } - } - /** * Mutable KernelPlugin example *

@@ -31,6 +24,7 @@ public class Example69_MutableKernelPlugin { .build()); Kernel kernel = Kernel.builder().build(); + kernel.addPlugin(plugin); var result = kernel.invokeAsync(kernel.getFunction("Plugin", "dateFunction")) @@ -38,4 +32,12 @@ public class Example69_MutableKernelPlugin { System.out.println("Result: " + result.getResult()); } + + public static class Time { + + @DefineKernelFunction(name = "date") + public String date() { + return "2021-09-01"; + } + } } diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/RunAll.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/RunAll.java index 4c96afc782..81b933f377 100644 --- a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/RunAll.java +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/RunAll.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import java.util.Arrays; @@ -13,11 +14,6 @@ import java.util.Scanner; */ public class RunAll { - public interface MainMethod { - - void run(String[] args) throws Exception; - } - public static void main(String[] args) { List mains = Arrays.asList( Example01_NativeFunctions::main, @@ -43,6 +39,7 @@ public class RunAll { Example56_TemplateMethodFunctionsWithMultipleArguments::main, Example57_KernelHooks::main, Example58_ConfigureExecutionSettings::main, + Example60_AdvancedMethodFunctions::main, Example61_MultipleLLMs::main, Example62_CustomAIServiceSelector::main, Example63_ChatCompletionPrompts::main, @@ -63,4 +60,9 @@ public class RunAll { } }); } + + public interface MainMethod { + + void run(String[] args) throws Exception; + } } diff --git a/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/java/KernelFunctionYaml_Example.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/java/KernelFunctionYaml_Example.java new file mode 100644 index 0000000000..05e12e105d --- /dev/null +++ b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/java/KernelFunctionYaml_Example.java @@ -0,0 +1,93 @@ +// Copyright (c) Microsoft. All rights reserved. +package com.microsoft.semantickernel.samples.syntaxexamples.java; + +import com.azure.ai.openai.OpenAIAsyncClient; +import com.azure.ai.openai.OpenAIClientBuilder; +import com.azure.core.credential.AzureKeyCredential; +import com.azure.core.credential.KeyCredential; +import com.microsoft.semantickernel.Kernel; +import com.microsoft.semantickernel.Kernel.Builder; +import com.microsoft.semantickernel.exceptions.ConfigurationException; +import com.microsoft.semantickernel.implementation.EmbeddedResourceLoader; +import com.microsoft.semantickernel.orchestration.FunctionResult; +import com.microsoft.semantickernel.semanticfunctions.KernelFunction; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionYaml; +import com.microsoft.semantickernel.services.textcompletion.TextGenerationService; +import java.io.IOException; + +public class KernelFunctionYaml_Example { + + private static final String CLIENT_KEY = System.getenv("CLIENT_KEY"); + private static final String AZURE_CLIENT_KEY = System.getenv("AZURE_CLIENT_KEY"); + + // Only required if AZURE_CLIENT_KEY is set + private static final String CLIENT_ENDPOINT = System.getenv("CLIENT_ENDPOINT"); + private static final String MODEL_ID = System.getenv() + .getOrDefault("MODEL_ID", "text-davinci-003"); + + public static void main(String[] args) throws ConfigurationException, IOException { + + OpenAIAsyncClient client; + + if (AZURE_CLIENT_KEY != null) { + client = new OpenAIClientBuilder() + .credential(new AzureKeyCredential(AZURE_CLIENT_KEY)) + .endpoint(CLIENT_ENDPOINT) + .buildAsyncClient(); + } else { + client = new OpenAIClientBuilder() + .credential(new KeyCredential(CLIENT_KEY)) + .buildAsyncClient(); + } + + TextGenerationService textGenerationService = TextGenerationService.builder() + .withOpenAIAsyncClient(client) + .withModelId(MODEL_ID) + .build(); + + Builder kernelBuilder = Kernel.builder() + .withAIService(TextGenerationService.class, textGenerationService); + + semanticKernelTemplate(kernelBuilder.build()); + handlebarsTemplate(kernelBuilder.build()); + + } + + private static void handlebarsTemplate(Kernel kernel) throws IOException { + String yaml = EmbeddedResourceLoader.readFile("GenerateStoryHandlebars.yaml", + KernelFunctionYaml_Example.class); + + KernelFunction function = KernelFunctionYaml.fromPromptYaml(yaml); + + FunctionResult result = function + .invokeAsync(kernel) + .withArguments( + KernelFunctionArguments.builder() + .withVariable("length", 5) + .withVariable("topic", "dogs") + .build()) + .block(); + + System.out.println(result.getResult()); + } + + private static void semanticKernelTemplate(Kernel kernel) throws IOException { + String yaml = EmbeddedResourceLoader.readFile("GenerateStory.yaml", + KernelFunctionYaml_Example.class); + + KernelFunction function = KernelFunctionYaml.fromPromptYaml(yaml); + + FunctionResult result = function + .invokeAsync(kernel) + .withArguments( + KernelFunctionArguments.builder() + .withVariable("length", 5) + .withVariable("topic", "cats") + .build()) + .block(); + + System.out.println(result.getResult()); + } + +} diff --git a/java/samples/sample-code/src/main/resources/com/microsoft/semantickernel/samples/syntaxexamples/java/GenerateStory.yaml b/java/samples/sample-code/src/main/resources/com/microsoft/semantickernel/samples/syntaxexamples/java/GenerateStory.yaml new file mode 100644 index 0000000000..fc5ecd88f3 --- /dev/null +++ b/java/samples/sample-code/src/main/resources/com/microsoft/semantickernel/samples/syntaxexamples/java/GenerateStory.yaml @@ -0,0 +1,17 @@ +name: GenerateStory +template: | + Tell a story about {{$topic}} that is {{$length}} sentences long. +template_format: semantic-kernel +description: A function that generates a story about a topic. +input_variables: + - name: topic + description: The topic of the story. + is_required: true + - name: length + description: The number of sentences in the story. + is_required: true +output_variable: + description: The generated story. +execution_settings: + default: + temperature: 0.6 diff --git a/java/samples/sample-code/src/main/resources/com/microsoft/semantickernel/samples/syntaxexamples/java/GenerateStoryHandlebars.yaml b/java/samples/sample-code/src/main/resources/com/microsoft/semantickernel/samples/syntaxexamples/java/GenerateStoryHandlebars.yaml new file mode 100644 index 0000000000..88bc4d7c31 --- /dev/null +++ b/java/samples/sample-code/src/main/resources/com/microsoft/semantickernel/samples/syntaxexamples/java/GenerateStoryHandlebars.yaml @@ -0,0 +1,23 @@ +name: GenerateStory +template: | + Tell a story about {{topic}} that is {{length}} sentences long. +template_format: handlebars +description: A function that generates a story about a topic. +input_variables: + - name: topic + description: The topic of the story. + is_required: true + - name: length + description: The number of sentences in the story. + is_required: true +output_variable: + description: The generated story. +execution_settings: + service1: + model_id: gpt-4 + temperature: 0.6 + service2: + model_id: gpt-3 + temperature: 0.4 + default: + temperature: 0.5 diff --git a/java/semantickernel-api/pom.xml b/java/semantickernel-api/pom.xml index 56e9f20da1..84ed2305d0 100644 --- a/java/semantickernel-api/pom.xml +++ b/java/semantickernel-api/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -66,5 +67,11 @@ junit-jupiter-api test + + org.wiremock + wiremock + 3.3.1 + test + \ No newline at end of file diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/Kernel.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/Kernel.java index afbd6494f5..f2a7477cef 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/Kernel.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/Kernel.java @@ -3,14 +3,17 @@ package com.microsoft.semantickernel; import com.microsoft.semantickernel.builders.Buildable; import com.microsoft.semantickernel.builders.SemanticKernelBuilder; +import com.microsoft.semantickernel.contextvariables.ContextVariableType; import com.microsoft.semantickernel.hooks.KernelHooks; import com.microsoft.semantickernel.orchestration.FunctionInvocation; -import com.microsoft.semantickernel.semanticfunctions.KernelFunction; +import com.microsoft.semantickernel.orchestration.InvocationContext; import com.microsoft.semantickernel.plugin.KernelPlugin; +import com.microsoft.semantickernel.semanticfunctions.KernelFunction; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.services.AIService; +import com.microsoft.semantickernel.services.AIServiceCollection; import com.microsoft.semantickernel.services.AIServiceSelection; import com.microsoft.semantickernel.services.AIServiceSelector; -import com.microsoft.semantickernel.services.AIServiceCollection; import com.microsoft.semantickernel.services.OrderedAIServiceSelector; import com.microsoft.semantickernel.services.ServiceNotFoundException; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -35,9 +38,13 @@ public class Kernel implements Buildable { /** * Initializes a new instance of {@code Kernel}. - * @param serviceSelector The {@code AIServiceSelector} used to query for services available through the kernel. - * @param plugins The collection of plugins available through the kernel. If {@code null}, an empty collection will be used. - * @param globalKernelHooks The global hooks to be used throughout the kernel. If {@code null}, an empty collection will be used. + * + * @param serviceSelector The {@code AIServiceSelector} used to query for services available + * through the kernel. + * @param plugins The collection of plugins available through the kernel. If + * {@code null}, an empty collection will be used. + * @param globalKernelHooks The global hooks to be used throughout the kernel. If {@code null}, + * an empty collection will be used. */ public Kernel( AIServiceSelector serviceSelector, @@ -53,10 +60,20 @@ public class Kernel implements Buildable { this.globalKernelHooks = new KernelHooks(globalKernelHooks); } + /** + * Get the fluent builder for creating a new instance of {@code Kernel}. + * + * @return The fluent builder for creating a new instance of {@code Kernel}. + */ + public static Kernel.Builder builder() { + return new Kernel.Builder(); + } + /** * Invokes a {@code KernelFunction} function by name. - * @param The return type of the function. - * @param pluginName The name of the plugin containing the function. + * + * @param The return type of the function. + * @param pluginName The name of the plugin containing the function. * @param functionName The name of the function to invoke. * @return The result of the function invocation. * @throws IllegalArgumentException if the plugin or function is not found. @@ -73,7 +90,8 @@ public class Kernel implements Buildable { /** * Invokes a {@code KernelFunction}. - * @param The return type of the function. + * + * @param The return type of the function. * @param function The function to invoke. * @return The result of the function invocation. * @see KernelFunction#invokeAsync(Kernel) @@ -83,8 +101,9 @@ public class Kernel implements Buildable { } /** - * This method is used to add plugins to the kernel after it has been created. - * If a plugin with the same name already exists, it will be replaced. + * This method is used to add plugins to the kernel after it has been created. If a plugin with + * the same name already exists, it will be replaced. + * * @param plugin The plugin to add. * @return {@code this} kernel with the plugin added. */ @@ -95,6 +114,7 @@ public class Kernel implements Buildable { /** * Gets the plugin with the specified name. + * * @param pluginName The name of the plugin to get. * @return The plugin with the specified name, or {@code null} if no such plugin exists. */ @@ -105,6 +125,7 @@ public class Kernel implements Buildable { /** * Gets the plugins that were added to the kernel. + * * @return The plugins available through the kernel (unmodifiable list). * @see Kernel#getPlugins() */ @@ -114,8 +135,9 @@ public class Kernel implements Buildable { /** * Gets the function with the specified name from the plugin with the specified name. - * @param The return type of the function. - * @param pluginName The name of the plugin containing the function. + * + * @param The return type of the function. + * @param pluginName The name of the plugin containing the function. * @param functionName The name of the function to get. * @return The function with the specified name from the plugin with the specified name. * @throws IllegalArgumentException if the plugin or function is not found. @@ -128,7 +150,8 @@ public class Kernel implements Buildable { /** * Gets the functions available through the kernel. Functions are collected from all plugins - * available through the kernel. + * available through the kernel. + * * @return The functions available through the kernel. * @see Kernel#getPlugins() * @see Kernel.Builder#withPlugin(KernelPlugin) @@ -138,10 +161,12 @@ public class Kernel implements Buildable { } /** - * Get the {@code KernelHooks} used throughout the kernel. - * These {@code KernelHooks} are used in addition to any hooks provided to a function. + * Get the {@code KernelHooks} used throughout the kernel. These {@code KernelHooks} are used in + * addition to any hooks provided to a function. + * * @return The {@code KernelHooks} used throughout the kernel. - * @see KernelFunction#invokeAsync(Kernel, KernelFunctionArguments, ContextVariableType, InvocationContext) + * @see KernelFunction#invokeAsync(Kernel, KernelFunctionArguments, ContextVariableType, + * InvocationContext) */ @SuppressFBWarnings("EI_EXPOSE_REP") public KernelHooks getGlobalKernelHooks() { @@ -150,6 +175,7 @@ public class Kernel implements Buildable { /** * Get the AIServiceSelector used to query for services available through the kernel. + * * @return The AIServiceSelector used to query for services available through the kernel. */ public AIServiceSelector getServiceSelector() { @@ -158,11 +184,13 @@ public class Kernel implements Buildable { /** * Get the service of the specified type from the kernel. - * @param The type of the service to get. + * + * @param The type of the service to get. * @param clazz The class of the service to get. * @return The service of the specified type from the kernel. * @throws ServiceNotFoundException if the service is not found. - * @see com.microsoft.semantickernel.services.AIServiceSelector#trySelectAIService(Class, KernelFunction, KernelFunctionArguments) + * @see com.microsoft.semantickernel.services.AIServiceSelector#trySelectAIService(Class, + * KernelFunction, com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments) */ public T getService(Class clazz) throws ServiceNotFoundException { AIServiceSelection selector = serviceSelector @@ -178,14 +206,6 @@ public class Kernel implements Buildable { return selector.getService(); } - /** - * Get the fluent builder for creating a new instance of {@code Kernel}. - * @return The fluent builder for creating a new instance of {@code Kernel}. - */ - public static Kernel.Builder builder() { - return new Kernel.Builder(); - } - /** * A fluent builder for creating a new instance of {@code Kernel}. */ @@ -198,8 +218,9 @@ public class Kernel implements Buildable { /** * Adds a service to the kernel. - * @param The type of the service to add. - * @param clazz The class of the service to add. + * + * @param The type of the service to add. + * @param clazz The class of the service to add. * @param aiService The service to add. * @return {@code this} builder with the service added. */ @@ -210,6 +231,7 @@ public class Kernel implements Buildable { /** * Adds a plugin to the kernel. + * * @param plugin The plugin to add. * @return {@code this} builder with the plugin added. */ @@ -220,6 +242,7 @@ public class Kernel implements Buildable { /** * Sets the service selector provider for the kernel. + * * @param serviceSelector The service selector provider for the kernel. * @return {@code this} builder with the service selector provider set. */ @@ -231,6 +254,7 @@ public class Kernel implements Buildable { /** * Builds a new instance of {@code Kernel} with the services and plugins provided. + * * @return A new instance of {@code Kernel}. */ @Override diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/KernelPluginCollection.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/KernelPluginCollection.java index 81f7485916..3348e447b8 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/KernelPluginCollection.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/KernelPluginCollection.java @@ -1,17 +1,18 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel; -import com.microsoft.semantickernel.semanticfunctions.KernelFunction; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionMetadata; import com.microsoft.semantickernel.contextvariables.CaseInsensitiveMap; import com.microsoft.semantickernel.plugin.KernelPlugin; +import com.microsoft.semantickernel.semanticfunctions.KernelFunction; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionMetadata; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nullable; /** * A collection of {@link KernelPlugin} instances. @@ -23,15 +24,15 @@ class KernelPluginCollection { private final Map plugins = new CaseInsensitiveMap<>(); /** - * Initialize a new instance of the {@link KernelPluginCollection} - * class with an empty collection of plugins. + * Initialize a new instance of the {@link KernelPluginCollection} class with an empty + * collection of plugins. */ KernelPluginCollection() { } /** - * Initialize a new instance of the {@link KernelPluginCollection} - * class from a collection of plugins. + * Initialize a new instance of the {@link KernelPluginCollection} class from a collection of + * plugins. */ KernelPluginCollection(List plugins) { plugins.forEach(plugin -> this.plugins.put(plugin.getName(), plugin)); @@ -39,7 +40,8 @@ class KernelPluginCollection { /** * Gets the function with the given name from the plugin with the given name. - * @param pluginName The name of the plugin containing the function. + * + * @param pluginName The name of the plugin containing the function. * @param functionName The name of the function to get. * @return The function with the given name from the plugin with the given name. * @throws IllegalArgumentException If the plugin or function is not found. @@ -60,6 +62,7 @@ class KernelPluginCollection { /** * Gets all functions from all plugins. + * * @return A list of all functions from all plugins. */ List> getFunctions() { @@ -70,6 +73,7 @@ class KernelPluginCollection { /** * Gets all function metadata from all plugins. + * * @return A list of all function metadata from all plugins. */ List> getFunctionsMetadata() { @@ -81,6 +85,7 @@ class KernelPluginCollection { /** * Gets all plugins that were added to the kernel. + * * @return The plugins available through the kernel. */ Collection getPlugins() { @@ -89,6 +94,7 @@ class KernelPluginCollection { /** * Gets the plugin with the specified name. + * * @param pluginName The name of the plugin to get. * @return The plugin with the specified name, or {@code null} if no such plugin exists. */ @@ -98,8 +104,9 @@ class KernelPluginCollection { } /** - * Adds a plugin to the collection. - * If a plugin with the same name already exists, it will be replaced. + * Adds a plugin to the collection. If a plugin with the same name already exists, it will be + * replaced. + * * @param plugin The plugin to add. */ void add(KernelPlugin plugin) { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/builders/Buildable.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/builders/Buildable.java index e92c299acc..0f54dba6f7 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/builders/Buildable.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/builders/Buildable.java @@ -2,9 +2,10 @@ package com.microsoft.semantickernel.builders; /** - * A marker interface for all classes that are buildable. By convention, {@code Buildable} - * classes will have a {@code public static Builder builder()} method for obtaining a + * A marker interface for all classes that are buildable. By convention, {@code Buildable} classes + * will have a {@code public static Builder builder()} method for obtaining a * {@link SemanticKernelBuilder} for the given class. */ public interface Buildable { + } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/connectors/WebSearchEngineConnector.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/connectors/WebSearchEngineConnector.java index 7687172165..0d1bf8777f 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/connectors/WebSearchEngineConnector.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/connectors/WebSearchEngineConnector.java @@ -8,36 +8,42 @@ import reactor.core.publisher.Mono; * Web search engine connector interface. */ public interface WebSearchEngineConnector { + + /** + * Execute a web search engine search. + * + * @param query Query to search. + * @param count Number of results. Defaults to 1. Must be between 1 and 50. + * @param offset Number of results to skip. Defaults to 0. + * @return First snippet returned from search. + */ + Mono> searchAsync(String query, int count, int offset); + /** * Represents a web page. */ interface WebPage { + /** * Gets the name of the web page. + * * @return The name of the web page. */ String getName(); - /** + /** * Gets the URL of the web page. + * * @return The URL of the web page. */ String getUrl(); /** * Gets the snippet of the web page. + * * @return The snippet of the web page. */ String getSnippet(); } - /** - * Execute a web search engine search. - * @param query Query to search. - * @param count Number of results. Defaults to 1. Must be between 1 and 50. - * @param offset Number of results to skip. Defaults to 0. - * @return First snippet returned from search. - */ - Mono> searchAsync(String query, int count, int offset); - } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/CaseInsensitiveMap.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/CaseInsensitiveMap.java index 783c2a9a28..daf78791cd 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/CaseInsensitiveMap.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/CaseInsensitiveMap.java @@ -11,12 +11,14 @@ import javax.annotation.Nullable; /** * A {@code java.util.HashMap} in which the keys are case-insensitive. + * * @param the type of the value */ public class CaseInsensitiveMap extends HashMap { /** * Creates a new instance of the {@link CaseInsensitiveMap} class. + * * @param kvMap the map */ public CaseInsensitiveMap(Map kvMap) { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariable.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariable.java index 20b032bc84..232b974cf4 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariable.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariable.java @@ -2,17 +2,18 @@ package com.microsoft.semantickernel.contextvariables; import com.azure.ai.openai.models.CompletionsUsage; -import com.microsoft.semantickernel.exceptions.SKException; import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter.NoopConverter; +import com.microsoft.semantickernel.exceptions.SKException; import java.time.OffsetDateTime; import java.util.Collections; import java.util.Objects; import javax.annotation.Nullable; /** - * A context variable wraps an arbitrary value and a {@code ContextVariableType}. - * {@code ContextVariableType} is used throughout the Semantic Kernel for passing - * arguments to functions and as function return types. + * A context variable wraps an arbitrary value and a {@code ContextVariableType}. + * {@code ContextVariableType} is used throughout the Semantic Kernel for passing arguments to + * functions and as function return types. + * * @param the type of the context variable */ public class ContextVariable { @@ -24,7 +25,8 @@ public class ContextVariable { /** * Creates a new instance of the {@link ContextVariable} class. - * @param type the type + * + * @param type the type * @param value the value */ public ContextVariable( @@ -36,9 +38,10 @@ public class ContextVariable { /** * Converts the given value to the requested result type. - * @param the type of the requested result - * @param the type of the input value - * @param it the input value + * + * @param the type of the requested result + * @param the type of the input value + * @param it the input value * @param requestedResultType the requested result type * @return the converted value */ @@ -56,15 +59,15 @@ public class ContextVariable { * Converts the given value to the requested result type. The {@code ContextVariableTypes} * parameter is used to find the appropriate converter for the input value and the requested * result type. - * - * @param the type of the requested result - * @param the type of the input value - * @param it the input value - * @param requestedResultType the requested result type + * + * @param the type of the requested result + * @param the type of the input value + * @param it the input value + * @param requestedResultType the requested result type * @param contextVariableTypes the context variable types * @return the converted value - * @throws SKException if a type converter cannot be found, or the input value - * cannot be converted to the requested result type + * @throws SKException if a type converter cannot be found, or the input value cannot be + * converted to the requested result type */ public static ContextVariable convert( @Nullable U it, @@ -144,7 +147,7 @@ public class ContextVariable { return requestedResultTypeVariable.of(result); } - if (requestedResultType.equals(String.class)) { + if (it.getClass().equals(String.class)) { // Try using from prompt string return requestedResultTypeVariable.of( requestedResultTypeVariable.getConverter().fromPromptString((String) it)); @@ -156,7 +159,7 @@ public class ContextVariable { /** * Creates a new instance of the {@link ContextVariable} class without using strong typing. - * + * * @param value the value * @param clazz the class * @param types the types @@ -173,8 +176,9 @@ public class ContextVariable { } /** - * Convenience method for creating a {@code ContextVariable} from the - * given {@code CompletionsUsage} instance. + * Convenience method for creating a {@code ContextVariable} from the given + * {@code CompletionsUsage} instance. + * * @param x the value * @return the new instance */ @@ -183,8 +187,9 @@ public class ContextVariable { } /** - * Convenience method for creating a {@code ContextVariable} from the - * given {@code OffsetDateTime} instance. + * Convenience method for creating a {@code ContextVariable} from the given + * {@code OffsetDateTime} instance. + * * @param x the value * @return the new instance */ @@ -193,8 +198,9 @@ public class ContextVariable { } /** - * Convenience method for creating a {@code ContextVariable} from the - * given {@code String} instance. + * Convenience method for creating a {@code ContextVariable} from the given {@code String} + * instance. + * * @param value the value * @return the new instance */ @@ -203,8 +209,8 @@ public class ContextVariable { } /** - * Convenience method for creating a {@code ContextVariable} from the - * given object. + * Convenience method for creating a {@code ContextVariable} from the given object. + * * @param x the object * @return the new instance */ @@ -212,69 +218,6 @@ public class ContextVariable { return ofValue(x); } - /** - * Get the value of the context variable. - * @return the value - */ - @Nullable - public T getValue() { - return value; - } - - /** - * Get the value of the context variable. - * @param clazz the class - * @param the type of the value - * @return the value - * @throws SKException if the value cannot be cast to the requested type - */ - @Nullable - public U getValue(Class clazz) { - try { - return clazz.cast(value); - } catch (ClassCastException e) { - throw new SKException( - "Cannot cast " + (value != null ? value.getClass() : "null") + " to " + clazz, e); - } - } - - /** - * Get the type of the context variable. - * @return the type - */ - public ContextVariableType getType() { - return type; - } - - /** - * Use the given {@code ContextVariableTypeConverter} to convert the - * value of this {@code ContextVariable} to a prompt string. This method - * is useful when the convert of this {@code ContextVariableType} does - * not create the expected prompt string. - * @param converter the converter to use when converting the value - * @return the value of this {@code ContextVariable} as a prompt string - */ - public String toPromptString(ContextVariableTypeConverter converter) { - return converter.toPromptString(value); - } - - /** - * Use the convert of the type of this {@code ContextVariable} to convert - * the value of this {@code ContextVariable} to a prompt string. - * @return the value of this {@code ContextVariable} as a prompt string - */ - public String toPromptString() { - return toPromptString(type.getConverter()); - } - - /** - * Returns true if the value of this {@code ContextVariable} is {@code null} or empty. - * @return true if the value is {@code null} or empty - */ - public boolean isEmpty() { - return value == null || value.toString().isEmpty(); - } - @SuppressWarnings("unchecked") private static ContextVariable ofValue(T value) { Objects.requireNonNull(value, "value cannot be null"); @@ -290,9 +233,10 @@ public class ContextVariable { /** * Creates a new instance of the {@link ContextVariable} class. - * @param value the value + * + * @param value the value * @param converter the converter - * @param the type of the value + * @param the type of the value * @return the new instance */ public static ContextVariable of(T value, ContextVariableTypeConverter converter) { @@ -301,4 +245,72 @@ public class ContextVariable { ContextVariableType type = new ContextVariableType<>(converter, converter.getType()); return new ContextVariable<>(type, value); } + + /** + * Get the value of the context variable. + * + * @return the value + */ + @Nullable + public T getValue() { + return value; + } + + /** + * Get the value of the context variable. + * + * @param clazz the class + * @param the type of the value + * @return the value + * @throws SKException if the value cannot be cast to the requested type + */ + @Nullable + public U getValue(Class clazz) { + try { + return clazz.cast(value); + } catch (ClassCastException e) { + throw new SKException( + "Cannot cast " + (value != null ? value.getClass() : "null") + " to " + clazz, e); + } + } + + /** + * Get the type of the context variable. + * + * @return the type + */ + public ContextVariableType getType() { + return type; + } + + /** + * Use the given {@code ContextVariableTypeConverter} to convert the value of this + * {@code ContextVariable} to a prompt string. This method is useful when the convert of this + * {@code ContextVariableType} does not create the expected prompt string. + * + * @param converter the converter to use when converting the value + * @return the value of this {@code ContextVariable} as a prompt string + */ + public String toPromptString(ContextVariableTypeConverter converter) { + return converter.toPromptString(value); + } + + /** + * Use the convert of the type of this {@code ContextVariable} to convert the value of this + * {@code ContextVariable} to a prompt string. + * + * @return the value of this {@code ContextVariable} as a prompt string + */ + public String toPromptString() { + return toPromptString(type.getConverter()); + } + + /** + * Returns true if the value of this {@code ContextVariable} is {@code null} or empty. + * + * @return true if the value is {@code null} or empty + */ + public boolean isEmpty() { + return value == null || value.toString().isEmpty(); + } } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariableType.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariableType.java index 6423737ed0..523361e23f 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariableType.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariableType.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables; import javax.annotation.Nullable; @@ -16,7 +17,7 @@ public class ContextVariableType { * Create a new context variable type. * * @param contextVariableTypeConverter The converter to convert objects to the type. - * @param clazz The class of the type + * @param clazz The class of the type */ public ContextVariableType(ContextVariableTypeConverter contextVariableTypeConverter, Class clazz) { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariableTypeConverter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariableTypeConverter.java index 9ee09ac462..139a19986e 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariableTypeConverter.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariableTypeConverter.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables; import java.util.ArrayList; @@ -12,6 +13,7 @@ import org.slf4j.LoggerFactory; /** * A converter for a context variable type. This class is used to convert objects to and from a * prompt string, and to convert objects to the type of the context variable. + * * @param the type of the context variable */ public class ContextVariableTypeConverter { @@ -25,77 +27,12 @@ public class ContextVariableTypeConverter { private final Function fromPromptString; private final List> toObjects; - /** - * A converter from one type to another. - * @param the source type - * @param the target type - */ - public interface Converter { - - /** - * Convert the object to the target type. - * @param t the object to convert - * @return the converted object - */ - U toObject(T t); - - /** - * Get the class of the target type. - * @return the class of the target type - */ - Class getTargetType(); - } - - /** - * A converter that does no conversion. This converter is often used as a default when no - * other conveter can be found for the type. - * @param the type of the context variable - */ - public static class NoopConverter extends ContextVariableTypeConverter { - - /** - * Create a new noop converter. - * @param clazz the class of the type - */ - public NoopConverter(Class clazz) { - super( - clazz, - x -> { - return (T) x; - }, - x -> { - throw new RuntimeException("Noop converter should not be called"); - }, - x -> { - throw new RuntimeException("Noop converter should not be called"); - }); - } - } - - /** - * A base class for concrete implementations of {@link ContextVariableTypeConverter.Converter}. - * @param the source type - * @param the target type - */ - public static abstract class DefaultConverter implements Converter { - - private final Class targetType; - - protected DefaultConverter(Class sourceType, Class targetType) { - this.targetType = targetType; - } - - @Override - public Class getTargetType() { - return targetType; - } - } - /** * Create a new context variable type converter. - * @param clazz the class of the type - * @param fromObject a function to convert an object to the type - * @param toPromptString a function to convert the type to a prompt string + * + * @param clazz the class of the type + * @param fromObject a function to convert an object to the type + * @param toPromptString a function to convert the type to a prompt string * @param fromPromptString a function to convert a prompt string to the type */ public ContextVariableTypeConverter( @@ -108,11 +45,12 @@ public class ContextVariableTypeConverter { /** * Create a new context variable type converter. - * @param clazz the class of the type - * @param fromObject a function to convert an object to the type - * @param toPromptString a function to convert the type to a prompt string + * + * @param clazz the class of the type + * @param fromObject a function to convert an object to the type + * @param toPromptString a function to convert the type to a prompt string * @param fromPromptString a function to convert a prompt string to the type - * @param toObjects a list of converters to convert the type to other types + * @param toObjects a list of converters to convert the type to other types */ public ContextVariableTypeConverter( Class clazz, @@ -129,8 +67,9 @@ public class ContextVariableTypeConverter { /** * Use this converter to convert the object to the type of the context variable. - * @param the type to convert to - * @param t the object to convert + * + * @param the type to convert to + * @param t the object to convert * @param clazz the class of the type to convert to * @return the converted object */ @@ -166,6 +105,7 @@ public class ContextVariableTypeConverter { /** * Convert the object to the type of the context variable using the {@code fromObject} function * provided to the constructor. + * * @param s the object to convert * @return the converted object */ @@ -174,12 +114,16 @@ public class ContextVariableTypeConverter { if (s == null) { return null; } + if (s instanceof ContextVariable) { + return fromObject.apply(((ContextVariable) s).getValue()); + } return fromObject.apply(s); } /** * Convert the type to a prompt string using the {@code toPromptString} function provided to the * constructor. + * * @param t the type to convert * @return the prompt string */ @@ -193,6 +137,7 @@ public class ContextVariableTypeConverter { /** * Convert the prompt string to the type using the {@code fromPromptString} function provided to * the constructor. + * * @param t the prompt string to convert * @return the type */ @@ -206,9 +151,82 @@ public class ContextVariableTypeConverter { /** * Get the class of the type. + * * @return the class of the type */ public Class getType() { return clazz; } + + /** + * A converter from one type to another. + * + * @param the source type + * @param the target type + */ + public interface Converter { + + /** + * Convert the object to the target type. + * + * @param t the object to convert + * @return the converted object + */ + U toObject(T t); + + /** + * Get the class of the target type. + * + * @return the class of the target type + */ + Class getTargetType(); + } + + /** + * A converter that does no conversion. This converter is often used as a default when no other + * conveter can be found for the type. + * + * @param the type of the context variable + */ + public static class NoopConverter extends ContextVariableTypeConverter { + + /** + * Create a new noop converter. + * + * @param clazz the class of the type + */ + public NoopConverter(Class clazz) { + super( + clazz, + x -> { + return (T) x; + }, + x -> { + throw new RuntimeException("Noop converter should not be called"); + }, + x -> { + throw new RuntimeException("Noop converter should not be called"); + }); + } + } + + /** + * A base class for concrete implementations of {@link ContextVariableTypeConverter.Converter}. + * + * @param the source type + * @param the target type + */ + public static abstract class DefaultConverter implements Converter { + + private final Class targetType; + + protected DefaultConverter(Class sourceType, Class targetType) { + this.targetType = targetType; + } + + @Override + public Class getTargetType() { + return targetType; + } + } } \ No newline at end of file diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariableTypes.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariableTypes.java index e7ae2c9fe8..4b4ed52bc1 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariableTypes.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariableTypes.java @@ -1,6 +1,6 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables; -import com.microsoft.semantickernel.exceptions.SKException; import com.microsoft.semantickernel.contextvariables.converters.BooleanVariableContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.converters.CharacterVariableContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.converters.ChatHistoryVariableContextVariableTypeConverter; @@ -9,7 +9,9 @@ import com.microsoft.semantickernel.contextvariables.converters.DateTimeContextV import com.microsoft.semantickernel.contextvariables.converters.InstantContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.converters.NumberVariableContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.converters.StringVariableContextVariableTypeConverter; +import com.microsoft.semantickernel.contextvariables.converters.TextContentVariableContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.converters.VoidVariableContextVariableTypeConverter; +import com.microsoft.semantickernel.exceptions.SKException; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -28,6 +30,7 @@ public class ContextVariableTypes { new CharacterVariableContextVariableTypeConverter(), new BooleanVariableContextVariableTypeConverter(), new ChatHistoryVariableContextVariableTypeConverter(), + new TextContentVariableContextVariableTypeConverter(), new StringVariableContextVariableTypeConverter(), new VoidVariableContextVariableTypeConverter(), new ContextVariableTypeConverter<>(void.class, s -> null, s -> null, s -> null), @@ -97,6 +100,7 @@ public class ContextVariableTypes { /** * Add a converter to the global collection of context variable type converters. + * * @param conveter The converter to add. * @see #getGlobalVariableTypeForClass(Class) */ @@ -107,8 +111,9 @@ public class ContextVariableTypes { /** * Get the global context variable type for the given class. + * * @param aClass The class to get the context variable type for. - * @param The type of the context variable. + * @param The type of the context variable. * @return The context variable type for the given class. * @see #addGlobalConverter(ContextVariableTypeConverter) */ @@ -116,22 +121,11 @@ public class ContextVariableTypes { return DEFAULT_TYPES.getVariableTypeForClass(aClass); } - /** - * Add a converter to this {@code ContextVariableTypes} instance. - * @param The type of the context variable. - * @param contextVariableTypeConverter the converter to add. - */ - public void putConverter( - ContextVariableTypeConverter contextVariableTypeConverter) { - variableTypes.put(contextVariableTypeConverter.getType(), - new ContextVariableType<>(contextVariableTypeConverter, - contextVariableTypeConverter.getType())); - } - /** * Convert the given object to the given class, if possible. - * @param the type to convert to - * @param s the object to convert + * + * @param the type to convert to + * @param s the object to convert * @param clazz the class of the type to convert to * @return the converted object, or {@code null} if the object cannot be converted */ @@ -149,10 +143,24 @@ public class ContextVariableTypes { } } + /** + * Add a converter to this {@code ContextVariableTypes} instance. + * + * @param The type of the context variable. + * @param contextVariableTypeConverter the converter to add. + */ + public void putConverter( + ContextVariableTypeConverter contextVariableTypeConverter) { + variableTypes.put(contextVariableTypeConverter.getType(), + new ContextVariableType<>(contextVariableTypeConverter, + contextVariableTypeConverter.getType())); + } + /** * Get the context variable type for the given class. + * * @param aClass The class to get the context variable type for. - * @param The type of the context variable. + * @param The type of the context variable. * @return The context variable type for the given class * @throws SKException if the type cannot be found. */ @@ -166,10 +174,11 @@ public class ContextVariableTypes { } /** - * Get the context variable type for the given class or for a type that is assignable - * from the given class. its super class. + * Get the context variable type for the given class or for a type that is assignable from the + * given class. its super class. + * * @param aClass The class to get the context variable type for. - * @param The type of the context variable. + * @param The type of the context variable. * @return The context variable type for the given class. * @throws SKException if the type cannot be found. */ @@ -222,6 +231,7 @@ public class ContextVariableTypes { /** * Add all the converters from the given collection to this collection. + * * @param contextVariableTypes The collection of converters to add. */ public void putConverters(ContextVariableTypes contextVariableTypes) { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/BooleanVariableContextVariableTypeConverter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/BooleanVariableContextVariableTypeConverter.java index eeca3d9963..4769064a19 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/BooleanVariableContextVariableTypeConverter.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/BooleanVariableContextVariableTypeConverter.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import static com.microsoft.semantickernel.contextvariables.ContextVariableTypes.convert; @@ -6,10 +7,10 @@ import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverte import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; /** - * A {@link ContextVariableTypeConverter} - * for {@link Boolean} variables. Use - * {@code ContextVariableTypes.getDefaultVariableTypeForClass(Boolean.class)} - * to get an instance of this class. + * A {@link ContextVariableTypeConverter} for {@link Boolean} variables. Use + * {@code ContextVariableTypes.getDefaultVariableTypeForClass(Boolean.class)} to get an instance of + * this class. + * * @see ContextVariableTypes#getGlobalVariableTypeForClass(Class) */ public class BooleanVariableContextVariableTypeConverter extends diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/CharacterVariableContextVariableTypeConverter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/CharacterVariableContextVariableTypeConverter.java index 02523ac775..c6787f9087 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/CharacterVariableContextVariableTypeConverter.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/CharacterVariableContextVariableTypeConverter.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import static com.microsoft.semantickernel.contextvariables.ContextVariableTypes.convert; @@ -6,17 +7,18 @@ import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverte import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; /** - * A {@link ContextVariableTypeConverter} - * for {@code java.lang.Character} variables. Use - * {@code ContextVariableTypes.getGlobalVariableTypeForClass(Character.class)} - * to get an instance of this class. + * A {@link ContextVariableTypeConverter} for {@code java.lang.Character} variables. Use + * {@code ContextVariableTypes.getGlobalVariableTypeForClass(Character.class)} to get an instance of + * this class. + * * @see ContextVariableTypes#getGlobalVariableTypeForClass(Class) */ public class CharacterVariableContextVariableTypeConverter extends ContextVariableTypeConverter { /** - * Initializes a new instance of the {@link CharacterVariableContextVariableTypeConverter} class. + * Initializes a new instance of the {@link CharacterVariableContextVariableTypeConverter} + * class. */ public CharacterVariableContextVariableTypeConverter() { super( diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/ChatHistoryVariableContextVariableTypeConverter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/ChatHistoryVariableContextVariableTypeConverter.java index b4532a36f5..ffc6ef9583 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/ChatHistoryVariableContextVariableTypeConverter.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/ChatHistoryVariableContextVariableTypeConverter.java @@ -1,23 +1,26 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import static com.microsoft.semantickernel.contextvariables.ContextVariableTypes.convert; -import com.microsoft.semantickernel.services.chatcompletion.ChatHistory; import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; +import com.microsoft.semantickernel.services.chatcompletion.ChatHistory; /** - * A {@link ContextVariableTypeConverter} - * for {@code com.microsoft.semantickernel.chathistory.ChatHistory} variables. Use - * {@code ContextVariableTypes.getGlobalVariableTypeForClass(ChatHistory.class)} - * to get an instance of this class. + * A {@link ContextVariableTypeConverter} for + * {@code com.microsoft.semantickernel.chathistory.ChatHistory} variables. Use + * {@code ContextVariableTypes.getGlobalVariableTypeForClass(ChatHistory.class)} to get an instance + * of this class. + * * @see ContextVariableTypes#getGlobalVariableTypeForClass(Class) */ public class ChatHistoryVariableContextVariableTypeConverter extends ContextVariableTypeConverter { /** - * Initializes a new instance of the {@link ChatHistoryVariableContextVariableTypeConverter} class. + * Initializes a new instance of the {@link ChatHistoryVariableContextVariableTypeConverter} + * class. */ public ChatHistoryVariableContextVariableTypeConverter() { super( diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/CompletionUsageContextVariableTypeConverter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/CompletionUsageContextVariableTypeConverter.java index f9d4e3ad44..048afc19e6 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/CompletionUsageContextVariableTypeConverter.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/CompletionUsageContextVariableTypeConverter.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import com.azure.ai.openai.models.CompletionsUsage; @@ -5,10 +6,10 @@ import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverte import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; /** - * A {@link ContextVariableTypeConverter} - * for {@code com.azure.ai.openai.models.CompletionsUsage} variables. Use - * {@code ContextVariableTypes.getGlobalVariableTypeForClass(CompletionsUsage.class)} + * A {@link ContextVariableTypeConverter} for {@code com.azure.ai.openai.models.CompletionsUsage} + * variables. Use {@code ContextVariableTypes.getGlobalVariableTypeForClass(CompletionsUsage.class)} * to get an instance of this class. + * * @see ContextVariableTypes#getGlobalVariableTypeForClass(Class) */ public class CompletionUsageContextVariableTypeConverter extends diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/DateTimeContextVariableTypeConverter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/DateTimeContextVariableTypeConverter.java index 7416ad8eca..6a64ccd298 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/DateTimeContextVariableTypeConverter.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/DateTimeContextVariableTypeConverter.java @@ -1,18 +1,18 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; - import java.time.Instant; import java.time.OffsetDateTime; import java.time.ZonedDateTime; import java.util.Arrays; /** - * A {@link ContextVariableTypeConverter} - * for {@code java.time.OffsetDateTime} variables. Use - * {@code ContextVariableTypes.getGlobalVariableTypeForClass(OffsetDateTime.class)} - * to get an instance of this class. + * A {@link ContextVariableTypeConverter} for {@code java.time.OffsetDateTime} variables. Use + * {@code ContextVariableTypes.getGlobalVariableTypeForClass(OffsetDateTime.class)} to get an + * instance of this class. + * * @see ContextVariableTypes#getGlobalVariableTypeForClass(Class) */ public class DateTimeContextVariableTypeConverter extends diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/InstantContextVariableTypeConverter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/InstantContextVariableTypeConverter.java index 2eb492a881..13fbfb4e19 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/InstantContextVariableTypeConverter.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/InstantContextVariableTypeConverter.java @@ -1,16 +1,16 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; - import java.time.Instant; import java.time.OffsetDateTime; /** - * A {@link ContextVariableTypeConverter} - * for {@code java.time.Instant} variables. Use - * {@code ContextVariableTypes.getGlobalVariableTypeForClass(Instant.class)} - * to get an instance of this class. + * A {@link ContextVariableTypeConverter} for {@code java.time.Instant} variables. Use + * {@code ContextVariableTypes.getGlobalVariableTypeForClass(Instant.class)} to get an instance of + * this class. + * * @see ContextVariableTypes#getGlobalVariableTypeForClass(Class) */ public class InstantContextVariableTypeConverter extends diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/NumberVariableContextVariableTypeConverter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/NumberVariableContextVariableTypeConverter.java index bbdcdca6b6..1e4fb45727 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/NumberVariableContextVariableTypeConverter.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/NumberVariableContextVariableTypeConverter.java @@ -1,18 +1,19 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import static com.microsoft.semantickernel.contextvariables.ContextVariableTypes.convert; import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; - import java.util.function.Function; import javax.annotation.Nullable; /** - * A {@link ContextVariableTypeConverter} - * for {@code java.lang.Number} type variables. Use, for example, - * {@code ContextVariableTypes.getGlobalVariableTypeForClass(Integer.class)} - * to get an instance of this class that works with the {@code Integer} type. + * A {@link ContextVariableTypeConverter} for {@code java.lang.Number} type variables. Use, for + * example, {@code ContextVariableTypes.getGlobalVariableTypeForClass(Integer.class)} to get an + * instance of this class that works with the {@code Integer} type. + * + * @param the type of the number * @see ContextVariableTypes#getGlobalVariableTypeForClass(Class) */ public class NumberVariableContextVariableTypeConverter extends @@ -22,9 +23,10 @@ public class NumberVariableContextVariableTypeConverter extend /** * Creates a new instance of the {@link NumberVariableContextVariableTypeConverter} class. - * @param clazz the class + * + * @param clazz the class * @param fromPromptString the function to convert from a prompt string - * @param fromNumber the function to convert from a number + * @param fromNumber the function to convert from a number */ public NumberVariableContextVariableTypeConverter( Class clazz, diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/StringVariableContextVariableTypeConverter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/StringVariableContextVariableTypeConverter.java index 0269f4be41..f7096b0747 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/StringVariableContextVariableTypeConverter.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/StringVariableContextVariableTypeConverter.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import static com.microsoft.semantickernel.contextvariables.ContextVariableTypes.convert; @@ -6,10 +7,10 @@ import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverte import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; /** - * A {@link ContextVariableTypeConverter} - * for {@code java.lang.String} variables. Use - * {@code ContextVariableTypes.getGlobalVariableTypeForClass(String.class)} - * to get an instance of this class. + * A {@link ContextVariableTypeConverter} for {@code java.lang.String} variables. Use + * {@code ContextVariableTypes.getGlobalVariableTypeForClass(String.class)} to get an instance of + * this class. + * * @see ContextVariableTypes#getGlobalVariableTypeForClass(Class) */ public class StringVariableContextVariableTypeConverter extends diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/TextContentVariableContextVariableTypeConverter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/TextContentVariableContextVariableTypeConverter.java new file mode 100644 index 0000000000..f38d334761 --- /dev/null +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/TextContentVariableContextVariableTypeConverter.java @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft. All rights reserved. +package com.microsoft.semantickernel.contextvariables.converters; + +import static com.microsoft.semantickernel.contextvariables.ContextVariableTypes.convert; + +import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; +import com.microsoft.semantickernel.services.textcompletion.TextContent; + +/** + * A converter for a context variable type. This class is used to convert objects to and from a + * prompt string, and to convert objects to the type of the context variable. + */ +public class TextContentVariableContextVariableTypeConverter extends + ContextVariableTypeConverter { + + /** + * Initializes a new instance of the {@link TextContentVariableContextVariableTypeConverter} + * class. + */ + public TextContentVariableContextVariableTypeConverter() { + super( + TextContent.class, + s -> convert(s, TextContent.class), + TextContent::getContent, + x -> { + throw new UnsupportedOperationException( + "TextContentVariableContextVariableTypeConverter does not support fromPromptString"); + }); + } +} diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/VoidVariableContextVariableTypeConverter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/VoidVariableContextVariableTypeConverter.java index 59a4f945ee..d3d602c1cc 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/VoidVariableContextVariableTypeConverter.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/VoidVariableContextVariableTypeConverter.java @@ -1,13 +1,14 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; /** - * A {@link ContextVariableTypeConverter} - * for {@code java.lang.Void} types. Use - * {@code ContextVariableTypes.getGlobalVariableTypeForClass(Void.class)} - * to get an instance of this class. + * A {@link ContextVariableTypeConverter} for {@code java.lang.Void} types. Use + * {@code ContextVariableTypes.getGlobalVariableTypeForClass(Void.class)} to get an instance of this + * class. + * * @see ContextVariableTypes#getGlobalVariableTypeForClass(Class) */ public class VoidVariableContextVariableTypeConverter extends diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/AIException.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/AIException.java index ad4560ac40..17416a5b65 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/AIException.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/AIException.java @@ -4,9 +4,14 @@ package com.microsoft.semantickernel.exceptions; import javax.annotation.Nonnull; import javax.annotation.Nullable; -/** AI logic exception */ +/** + * AI logic exception + */ public class AIException extends SKException { + /** + * Error code + */ @Nonnull private final ErrorCodes errorCode; @@ -23,7 +28,7 @@ public class AIException extends SKException { * Initializes a new instance of the {@link AIException} class. * * @param errorCode The error code. - * @param message The message. + * @param message The message. */ public AIException(@Nonnull ErrorCodes errorCode, @Nullable String message) { this(errorCode, message, null); @@ -32,8 +37,8 @@ public class AIException extends SKException { /** * Initializes a new instance of the {@link AIException} class. * - * @param errorCode The error code. - * @param message The message. + * @param errorCode The error code. + * @param message The message. * @param innerException The cause of the exception. */ public AIException( @@ -53,35 +58,59 @@ public class AIException extends SKException { return errorCode; } - /** Error codes */ + /** + * Error codes + */ public enum ErrorCodes { - /** Unknown error. */ + /** + * Unknown error. + */ UNKNOWN_ERROR("Unknown error"), - /** No response. */ + /** + * No response. + */ NO_RESPONSE("No response"), - /** Access denied. */ + /** + * Access denied. + */ ACCESS_DENIED("Access is denied"), - /** Invalid request. */ + /** + * Invalid request. + */ INVALID_REQUEST("The request was invalid"), - /** Invalid response. */ + /** + * Invalid response. + */ INVALID_RESPONSE_CONTENT("The content of the response was invalid"), - /** Throttling. */ + /** + * Throttling. + */ THROTTLING("The request was throttled"), - /** Request timeout. */ + /** + * Request timeout. + */ REQUEST_TIMEOUT("The request timed out"), - /** Service error. */ + /** + * Service error. + */ SERVICE_ERROR("There was an error in the service"), - /** Model not available. */ + /** + * Model not available. + */ MODEL_NOT_AVAILABLE("The requested model is not available"), - /** Invalid configuration. */ + /** + * Invalid configuration. + */ INVALID_CONFIGURATION("The supplied configuration was invalid"), - /** Function type not supported. */ + /** + * Function type not supported. + */ FUNCTION_TYPE_NOT_SUPPORTED("The function is not supported"); private final String message; diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/ConfigurationException.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/ConfigurationException.java index 8771ee4a3d..1784ee8249 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/ConfigurationException.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/ConfigurationException.java @@ -5,16 +5,19 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; /** - * An exception that is thrown when there is an error with the - * Semantic Kernel configuration. + * An exception that is thrown when there is an error with the Semantic Kernel configuration. */ public class ConfigurationException extends SKCheckedException { + /** + * Error code. + */ @Nonnull private final ErrorCodes errorCode; /** * Creates a new instance of the {@link ConfigurationException} class. + * * @param error the error code */ public ConfigurationException(@Nonnull ErrorCodes error) { @@ -23,8 +26,9 @@ public class ConfigurationException extends SKCheckedException { /** * Creates a new instance of the {@link ConfigurationException} class. + * * @param errorCode the error code - * @param message the message + * @param message the message */ public ConfigurationException(@Nonnull ErrorCodes errorCode, @Nullable String message) { this(errorCode, message, null); @@ -32,8 +36,9 @@ public class ConfigurationException extends SKCheckedException { /** * Creates a new instance of the {@link ConfigurationException} class. - * @param errorCode the error code - * @param message the message + * + * @param errorCode the error code + * @param message the message * @param innerException the inner exception */ public ConfigurationException( @@ -46,6 +51,7 @@ public class ConfigurationException extends SKCheckedException { /** * Gets the error code. + * * @return the error code */ public ErrorCodes getErrorCode() { @@ -56,19 +62,29 @@ public class ConfigurationException extends SKCheckedException { * ErrorCodes for this exception. */ public enum ErrorCodes { - /** Unknown error */ + /** + * Unknown error + */ UNKNOWN_ERROR("Unknown error"), - /** Could not find configuration file */ + /** + * Could not find configuration file + */ CONFIGURATION_NOT_FOUND("Could not find configuration file"), - /** Could not parse or load configuration file */ + /** + * Could not parse or load configuration file + */ COULD_NOT_READ_CONFIGURATION("Could not parse or load configuration file"), - /** Could not find any valid configuration settings */ + /** + * Could not find any valid configuration settings + */ NO_VALID_CONFIGURATIONS_FOUND("Could not find any valid configuration settings"), - /** Could not find value for configuration key */ + /** + * Could not find value for configuration key + */ VALUE_NOT_FOUND("Could not find value for configuration key"); private final String message; @@ -79,6 +95,7 @@ public class ConfigurationException extends SKCheckedException { /** * Gets the message for the error code. + * * @return the message for the error code */ public String getMessage() { @@ -87,6 +104,7 @@ public class ConfigurationException extends SKCheckedException { /** * Format the message with the given parameter. + * * @param param helpful information * @return the formatted message */ diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/SKCheckedException.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/SKCheckedException.java index 8119fde62c..9506b41055 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/SKCheckedException.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/SKCheckedException.java @@ -4,7 +4,9 @@ package com.microsoft.semantickernel.exceptions; import javax.annotation.Nonnull; import javax.annotation.Nullable; -/** Provides the base exception from which all CHECKED Semantic Kernel exceptions derive. */ +/** + * Provides the base exception from which all CHECKED Semantic Kernel exceptions derive. + */ public class SKCheckedException extends Exception { /** @@ -29,7 +31,7 @@ public class SKCheckedException extends Exception { * {@code message}. * * @param message A string that describes the error. - * @param cause The exception that is the cause of the current exception. + * @param cause The exception that is the cause of the current exception. */ protected SKCheckedException(@Nullable String message, @Nullable Throwable cause) { super(message, cause); @@ -39,7 +41,7 @@ public class SKCheckedException extends Exception { * Translate the error code into a default message format. * * @param errorMessage The error message from an error code - * @param message The message from the code which throws the exception + * @param message The message from the code which throws the exception * @return A formatted message */ protected static String formatDefaultMessage( diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/SKException.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/SKException.java index 1a637ffabe..ee2f027bf7 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/SKException.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/SKException.java @@ -4,17 +4,21 @@ package com.microsoft.semantickernel.exceptions; import javax.annotation.Nonnull; import javax.annotation.Nullable; -/** Provides the base exception from which all Semantic Kernel exceptions derive. */ +/** + * Provides the base exception from which all Semantic Kernel exceptions derive. + */ public class SKException extends RuntimeException { - /** Initializes a new instance of the {@code SKException} class with a default message. */ + /** + * Initializes a new instance of the {@code SKException} class with a default message. + */ protected SKException() { super(); } /** - * Initializes a new instance of the {@code SKException} class with its message set to {@code - * message}. + * Initializes a new instance of the {@code SKException} class with its message set to + * {@code message}. * * @param message A string that describes the error. */ @@ -23,11 +27,11 @@ public class SKException extends RuntimeException { } /** - * Initializes a new instance of the {@code SKException} class with its message set to {@code - * message}. + * Initializes a new instance of the {@code SKException} class with its message set to + * {@code message}. * * @param message A string that describes the error. - * @param cause The exception that is the cause of the current exception. + * @param cause The exception that is the cause of the current exception. */ public SKException(@Nullable String message, @Nullable Throwable cause) { super(message, cause); @@ -37,7 +41,7 @@ public class SKException extends RuntimeException { * Translate the error code into a default message format. * * @param errorMessage The error message from an error code - * @param message The message from the code which throws the exception + * @param message The message from the code which throws the exception * @return A formatted message */ protected static String formatDefaultMessage( diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/FunctionInvokedEvent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/FunctionInvokedEvent.java index e09714cb07..495a374253 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/FunctionInvokedEvent.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/FunctionInvokedEvent.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.hooks; import com.microsoft.semantickernel.orchestration.FunctionResult; @@ -8,6 +9,7 @@ import javax.annotation.Nullable; /** * Represents a KernelHookEvent that is raised after a function is invoked. + * * @param The type of the function result */ public class FunctionInvokedEvent implements KernelHookEvent { @@ -19,9 +21,10 @@ public class FunctionInvokedEvent implements KernelHookEvent { /** * Creates a new instance of the {@link FunctionInvokedEvent} class. - * @param function the function + * + * @param function the function * @param arguments the arguments - * @param result the result + * @param result the result */ public FunctionInvokedEvent( KernelFunction function, @@ -35,6 +38,7 @@ public class FunctionInvokedEvent implements KernelHookEvent { /** * Gets the function that was invoked. + * * @return the function */ public KernelFunction getFunction() { @@ -43,6 +47,7 @@ public class FunctionInvokedEvent implements KernelHookEvent { /** * Gets the arguments that were passed to the function. + * * @return the arguments */ @SuppressFBWarnings("EI_EXPOSE_REP") @@ -53,6 +58,7 @@ public class FunctionInvokedEvent implements KernelHookEvent { /** * Gets the result of the function invocation. + * * @return the result */ @SuppressFBWarnings("EI_EXPOSE_REP") diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/FunctionInvokingEvent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/FunctionInvokingEvent.java index 1c1f92a8b4..31f2b63092 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/FunctionInvokingEvent.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/FunctionInvokingEvent.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.hooks; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; @@ -6,9 +7,10 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import javax.annotation.Nullable; /** - * Represents a KernelHookEvent that is raised before a function is invoked. - * This event is raised before the function is invoked, and can be used to - * by a {@code KernelHook} to modify the arguments before the function is invoked. + * Represents a KernelHookEvent that is raised before a function is invoked. This event is raised + * before the function is invoked, and can be used to by a {@code KernelHook} to modify the + * arguments before the function is invoked. + * * @param The type of the KernelFunction being invoked */ public class FunctionInvokingEvent implements KernelHookEvent { @@ -18,7 +20,8 @@ public class FunctionInvokingEvent implements KernelHookEvent { /** * Creates a new instance of the FunctionInvokingEvent class. - * @param function The function that is being invoked + * + * @param function The function that is being invoked * @param arguments The arguments that are being passed to the function */ public FunctionInvokingEvent(KernelFunction function, @@ -30,6 +33,7 @@ public class FunctionInvokingEvent implements KernelHookEvent { /** * Gets the function that is being invoked. + * * @return the function */ public KernelFunction getFunction() { @@ -38,6 +42,7 @@ public class FunctionInvokingEvent implements KernelHookEvent { /** * Gets the arguments that are being passed to the function. + * * @return the arguments */ @SuppressFBWarnings("EI_EXPOSE_REP") diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/KernelHook.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/KernelHook.java index 169fddc6a0..a1e8850573 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/KernelHook.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/KernelHook.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.hooks; import com.azure.ai.openai.models.ChatCompletionsOptions; @@ -8,8 +9,9 @@ import java.util.function.Predicate; /** * Represents a hook that can be used to intercept and modify arguments to {@code KernelFunction}s. - * A {@code KernelHook} implements a {@code Predicate} that determines if the hook is interested - * in a particular event, and a {@code Function} that can be used to modify the event. The + * A {@code KernelHook} implements a {@code Predicate} that determines if the hook is interested in + * a particular event, and a {@code Function} that can be used to modify the event. The + * * @param The type of the event that the hook is interested in */ public interface KernelHook extends Predicate, @@ -17,8 +19,8 @@ public interface KernelHook extends Predicate extends Predicate> { @@ -38,7 +40,7 @@ public interface KernelHook extends Predicate> { @@ -49,7 +51,7 @@ public interface KernelHook extends Predicate { @@ -60,7 +62,7 @@ public interface KernelHook extends Predicate { @@ -71,18 +73,14 @@ public interface KernelHook extends Predicate { - @Override - default boolean test(KernelHookEvent arguments) { - return PreChatCompletionEvent.class.isAssignableFrom(arguments.getClass()); - } - /** * A convenience method to clone the options with the messages from the event. - * @param options the options to clone + * + * @param options the options to clone * @param messages the messages to use * @return the new options */ @@ -114,5 +112,10 @@ public interface KernelHook extends Predicate function, @@ -27,6 +29,7 @@ public class PromptRenderingEvent implements KernelHookEvent { /** * Gets the function that was invoked. + * * @return the function */ public KernelFunction getFunction() { @@ -35,6 +38,7 @@ public class PromptRenderingEvent implements KernelHookEvent { /** * Gets the arguments that were passed to the function. + * * @return the arguments */ @SuppressFBWarnings("EI_EXPOSE_REP") diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/EmbeddedResourceLoader.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/EmbeddedResourceLoader.java index 29b7bc8817..3813068a3d 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/EmbeddedResourceLoader.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/EmbeddedResourceLoader.java @@ -19,29 +19,11 @@ import java.util.stream.Collectors; */ public class EmbeddedResourceLoader { - /** - * Enum for specifying the location of the resource - */ - public enum ResourceLocation { - /** - * Load from the classpath - */ - CLASSPATH, - /** - * Load from the filesystem - */ - FILESYSTEM, - /** - * Load from the classpath root - */ - CLASSPATH_ROOT - } - /** * Loads a file to a string from the classpath using getResourceAsStream * * @param fileName Filename to read - * @param clazz Class to use for classpath loading + * @param clazz Class to use for classpath loading * @return File content * @throws FileNotFoundException Error in case the file doesn't exist */ @@ -52,8 +34,8 @@ public class EmbeddedResourceLoader { /** * Loads a file to a string from the classpath, classpath root or filesystem * - * @param fileName Filename to read - * @param clazz Class to use for classpath loading + * @param fileName Filename to read + * @param clazz Class to use for classpath loading * @param locations Locations to search for the file * @return File content * @throws FileNotFoundException Error in case the file doesn't exist @@ -120,4 +102,22 @@ public class EmbeddedResourceLoader { .lines() .collect(Collectors.joining("\n")); } + + /** + * Enum for specifying the location of the resource + */ + public enum ResourceLocation { + /** + * Load from the classpath + */ + CLASSPATH, + /** + * Load from the filesystem + */ + FILESYSTEM, + /** + * Load from the classpath root + */ + CLASSPATH_ROOT + } } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/ServiceLoadUtil.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/ServiceLoadUtil.java index fe5c7d3356..ede5424621 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/ServiceLoadUtil.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/ServiceLoadUtil.java @@ -12,9 +12,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * This class is used for loading services that are not directly referenced - * in the code, but are instead loaded using the ServiceLoader pattern. - * + * This class is used for loading services that are not directly referenced in the code, but are + * instead loaded using the ServiceLoader pattern. */ public class ServiceLoadUtil { @@ -26,10 +25,10 @@ public class ServiceLoadUtil { /** * Finds a service loader for the given class and returns a supplier for it. * - * @param clazz The class to find a service loader for. - * @param The type of the class to find a service loader for. + * @param clazz The class to find a service loader for. + * @param The type of the class to find a service loader for. * @param alternativeClassName The name of the alternative class to load if the service loader - * is not found. + * is not found. * @return A {@code java.util.function.Supplier} for the service loader. */ public static Supplier findServiceLoader(Class clazz, String alternativeClassName) { @@ -37,7 +36,7 @@ public class ServiceLoadUtil { T impl = null; - if (services.size() > 0) { + if (!services.isEmpty()) { impl = services.get(0); } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/Todo.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/Todo.java index bfcfa85f0c..fe7113b0b3 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/Todo.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/Todo.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.implementation; /** diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/Verify.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/Verify.java index afe441310d..6e6d002b35 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/Verify.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/Verify.java @@ -4,13 +4,13 @@ package com.microsoft.semantickernel.implementation; import javax.annotation.Nullable; /** - * Provides methods for verifying the state of objects and strings in - * a consistent manner. + * Provides methods for verifying the state of objects and strings in a consistent manner. */ public class Verify { /** * Verifies that the given object is not {@code null}. + * * @param object The object to verify. */ public static void notNull(Object object) { @@ -19,6 +19,7 @@ public class Verify { /** * Verifies that the given object is {@code null} or empty. + * * @param s The String to verify. * @return true if the object is {@code null} or empty; otherwise, false. */ @@ -28,6 +29,7 @@ public class Verify { /** * Verifies that the given object is {@code null} or contains only whitespace. + * * @param s The String to verify. * @return true if the object is {@code null} or whitespace; otherwise, false. */ diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/CodeTokenizer.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/CodeTokenizer.java index 7f56277ee9..3fad53bfc1 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/CodeTokenizer.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/CodeTokenizer.java @@ -3,12 +3,12 @@ package com.microsoft.semantickernel.implementation.templateengine.tokenizer; import com.microsoft.semantickernel.exceptions.SKException; import com.microsoft.semantickernel.implementation.Verify; -import com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks.ValBlock; -import com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks.VarBlock; import com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks.Block; import com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks.FunctionIdBlock; import com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks.NamedArgBlock; import com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks.Symbols; +import com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks.ValBlock; +import com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks.VarBlock; import com.microsoft.semantickernel.templateengine.semantickernel.TemplateException; import java.util.ArrayList; import java.util.Collections; @@ -17,45 +17,67 @@ import javax.annotation.Nullable; /** * Simple tokenizer used for default SK template code language. - * - * BNF parsed by TemplateTokenizer: - * [template] ::= "" | [block] | [block] [template] - * [block] ::= [sk-block] | [text-block] - * [sk-block] ::= "{{" [variable] "}}" | "{{" [value] "}}" | "{{" [function-call] "}}" - * [text-block] ::= [any-char] | [any-char] [text-block] - * [any-char] ::= any char - * - * BNF parsed by CodeTokenizer: - * [template] ::= "" | [variable] " " [template] | [value] " " [template] | [function-call] " - * [variable] ::= "$" [valid-name] - * [value] ::= "'" [text] "'" | '"' [text] '"' - * [function-call] ::= [function-id] | [function-id] [parameter] + *

+ * BNF parsed by TemplateTokenizer: [template] ::= "" | [block] | [block] [template] [block] + * ::= [sk-block] | [text-block] [sk-block] ::= "{{" [variable] "}}" | "{{" [value] "}}" | + * "{{" [function-call] "}}" [text-block] ::= [any-char] | [any-char] [text-block] [any-char] + * ::= any char + *

+ * BNF parsed by CodeTokenizer: [template] ::= "" | [variable] " " [template] | [value] " " + * [template] | [function-call] " [variable] ::= "$" [valid-name] [value] ::= "'" + * [text] "'" | '"' [text] '"' [function-call] ::= [function-id] | [function-id] [parameter] * [parameter] ::= [variable] | [value] - * - * BNF parsed by dedicated blocks - * [function-id] ::= [valid-name] | [valid-name] "." [valid-name] - * [valid-name] ::= [valid-symbol] | [valid-symbol] [valid-name] - * [valid-symbol] ::= [letter] | [digit] | "_" - * [letter] ::= "a" | "b" ... | "z" | "A" | "B" ... | "Z" - * [digit] ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" + *

+ * BNF parsed by dedicated blocks [function-id] ::= [valid-name] | [valid-name] "." [valid-name] + * [valid-name] ::= [valid-symbol] | [valid-symbol] [valid-name] [valid-symbol] ::= [letter] | + * [digit] | "_" [letter] ::= "a" | "b" ... | "z" | "A" | "B" ... | "Z" [digit] ::= + * "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" */ public class CodeTokenizer { - private enum TokenTypes { - None(0), Value(1), Variable(2), FunctionId(3), NamedArg(4); - - TokenTypes(int i) { - } - } - /** * Initializes a new instance of the {@link CodeTokenizer} class. */ public CodeTokenizer() { } + private static boolean isVarPrefix(char c) { + return (c == Symbols.VarPrefix); + } + + private static boolean IsBlankSpace(char c) { + return Character.isWhitespace(c); + } + + private static boolean isQuote(char c) { + return c == Symbols.DblQuote || c == Symbols.SglQuote; + } + + private static boolean CanBeEscaped(char c) { + return c == Symbols.DblQuote || c == Symbols.SglQuote || c == Symbols.EscapeChar; + } + + @SuppressWarnings("NullAway") + @Nullable + private static NamedArgBlock getNamedArg(String tokenContent) { + + String name = NamedArgBlock.tryGetName(tokenContent); + String value = NamedArgBlock.tryGetValue(tokenContent); + + if (Verify.isNullOrEmpty(name) || Verify.isNullOrEmpty(value)) { + return null; + } + NamedArgBlock block = new NamedArgBlock(tokenContent, name, value); + if (block.isValid()) { + return block; + } + + return null; + } + /** * Tokenize a code block, without checking for syntax errors + * * @param text Text to parse * @return A list of blocks */ @@ -288,37 +310,10 @@ public class CodeTokenizer { return blocks; } - private static boolean isVarPrefix(char c) { - return (c == Symbols.VarPrefix); - } + private enum TokenTypes { + None(0), Value(1), Variable(2), FunctionId(3), NamedArg(4); - private static boolean IsBlankSpace(char c) { - return Character.isWhitespace(c); - } - - private static boolean isQuote(char c) { - return c == Symbols.DblQuote || c == Symbols.SglQuote; - } - - private static boolean CanBeEscaped(char c) { - return c == Symbols.DblQuote || c == Symbols.SglQuote || c == Symbols.EscapeChar; - } - - @SuppressWarnings("NullAway") - @Nullable - private static NamedArgBlock getNamedArg(String tokenContent) { - - String name = NamedArgBlock.tryGetName(tokenContent); - String value = NamedArgBlock.tryGetValue(tokenContent); - - if (Verify.isNullOrEmpty(name) || Verify.isNullOrEmpty(value)) { - return null; + TokenTypes(int i) { } - NamedArgBlock block = new NamedArgBlock(tokenContent, name, value); - if (block.isValid()) { - return block; - } - - return null; } } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/DefaultPromptTemplate.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/DefaultPromptTemplate.java index 8ff9ae486a..6ac63c3ce9 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/DefaultPromptTemplate.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/DefaultPromptTemplate.java @@ -2,6 +2,7 @@ package com.microsoft.semantickernel.implementation.templateengine.tokenizer; import com.microsoft.semantickernel.Kernel; +import com.microsoft.semantickernel.exceptions.SKException; import com.microsoft.semantickernel.implementation.Verify; import com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks.Block; import com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks.BlockTypes; @@ -10,12 +11,13 @@ import com.microsoft.semantickernel.implementation.templateengine.tokenizer.bloc import com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks.TextRendering; import com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks.VarBlock; import com.microsoft.semantickernel.orchestration.InvocationContext; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.InputVariable; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.PromptTemplate; import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig; import com.microsoft.semantickernel.templateengine.semantickernel.TemplateException; import com.microsoft.semantickernel.templateengine.semantickernel.TemplateException.ErrorCodes; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -31,25 +33,49 @@ import reactor.core.publisher.Mono; */ public class DefaultPromptTemplate implements PromptTemplate { - private final PromptTemplateConfig promptTemplate; + private final PromptTemplateConfig promptTemplateConfig; + private final List blocks; /** * Create a new prompt template. + * * @param promptTemplateConfig The prompt template configuration. */ - public DefaultPromptTemplate( - @Nonnull PromptTemplateConfig promptTemplateConfig) { - this.promptTemplate = new PromptTemplateConfig(promptTemplateConfig); + private DefaultPromptTemplate( + @Nonnull PromptTemplateConfig promptTemplateConfig, + @Nonnull List blocks) { + this.promptTemplateConfig = promptTemplateConfig; + this.blocks = Collections.unmodifiableList(blocks); + } + + /** + * Build a new prompt template from the given prompt template configuration. + * + * @param promptTemplateConfig The prompt template configuration. + * @return The new prompt template. + */ + public static DefaultPromptTemplate build(@Nonnull PromptTemplateConfig promptTemplateConfig) { + + List blocks = extractBlocks(promptTemplateConfig); + promptTemplateConfig = addMissingInputVariables(promptTemplateConfig, blocks); + + return new DefaultPromptTemplate(promptTemplateConfig, blocks); } /* * Given a prompt template string, extract all the blocks (text, variables, function calls) - * + * * @return A list of all the blocks, ie the template tokenized in text, variables and function * calls */ - private List extractBlocks() { - String templateText = promptTemplate.getTemplate(); + private static List extractBlocks(PromptTemplateConfig promptTemplateConfig) { + String templateText = promptTemplateConfig.getTemplate(); + + if (templateText == null) { + throw new SKException( + String.format("No prompt template was provided for the prompt %s.", + promptTemplateConfig.getName())); + } List blocks = new TemplateTokenizer().tokenize(templateText); @@ -67,23 +93,28 @@ public class DefaultPromptTemplate implements PromptTemplate { } /** - * Augments the prompt template with any variables - * not already contained there but that are referenced in the prompt template. + * Augments the prompt template with any variables not already contained there but that are + * referenced in the prompt template. + * * @param blocks The blocks to search for input variables. + * @return The augmented prompt template. */ @SuppressWarnings("NullAway") - private void addMissingInputVariables(List blocks) { + private static PromptTemplateConfig addMissingInputVariables( + PromptTemplateConfig promptTemplateConfig, List blocks) { // Add all of the existing input variables to our known set. We'll avoid adding any // dynamically discovered input variables with the same name. Set seen = new HashSet<>(); seen.addAll( - promptTemplate + promptTemplateConfig .getInputVariables() .stream() .map(InputVariable::getName) .collect(Collectors.toList())); + PromptTemplateConfig.Builder promptTemplateConfigBuilder = promptTemplateConfig.copy(); + blocks.forEach(block -> { String name = null; if (block.getType() == BlockTypes.VARIABLE) { @@ -95,9 +126,11 @@ public class DefaultPromptTemplate implements PromptTemplate { if (!Verify.isNullOrEmpty(name) && !seen.contains(name)) { seen.add(name); - promptTemplate.addInputVariable(new InputVariable(name)); + promptTemplateConfigBuilder.addInputVariable(new InputVariable(name)); } }); + + return promptTemplateConfigBuilder.build(); } @Override @@ -106,9 +139,6 @@ public class DefaultPromptTemplate implements PromptTemplate { @Nullable KernelFunctionArguments arguments, @Nullable InvocationContext context) { - List blocks = this.extractBlocks(); - addMissingInputVariables(blocks); - return Flux .fromIterable(blocks) .concatMap(block -> { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/TemplateTokenizer.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/TemplateTokenizer.java index b1e95749c4..d0a1653880 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/TemplateTokenizer.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/TemplateTokenizer.java @@ -11,34 +11,50 @@ import java.util.Collections; import java.util.List; /** - * Simple tokenizer used for default SK template language. - * - * BNF parsed by TemplateTokenizer: - * [template] ::= "" | [block] | [block] [template] - * [block] ::= [sk-block] | [text-block] - * [sk-block] ::= "{{" [variable] "}}" | "{{" [value] "}}" | "{{" [function-call] "}}" - * [text-block] ::= [any-char] | [any-char] [text-block] - * [any-char] ::= any char - * - * BNF parsed by CodeTokenizer: - * [template] ::= "" | [variable] " " [template] | [value] " " [template] | [function-call] " - * - * [variable] ::= "$" [valid-name] - * [value] ::= "'" [text] "'" | '"' [text] '"' - * [function-call] ::= [function-id] | [function-id] [parameter] - * [parameter] ::= [variable] | [value] - * - * BNF parsed by dedicated blocks - * [function-id] ::= [valid-name] | [valid-name] "." [valid-name] - * [valid-name] ::= [valid-symbol] | [valid-symbol] [valid-name] - * [valid-symbol] ::= [letter] | [digit] | "_" - * [letter] ::= "a" | "b" ... | "z" | "A" | "B" ... | "Z" - * [digit] ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" + * Simple tokenizer used for default SK template language. + *

+ * BNF parsed by TemplateTokenizer: [template] ::= "" | [block] | [block] [template] [block] + * ::= [sk-block] | [text-block] [sk-block] ::= "{{" [variable] "}}" | "{{" [value] "}}" | + * "{{" [function-call] "}}" [text-block] ::= [any-char] | [any-char] [text-block] [any-char] + * ::= any char + *

+ * BNF parsed by CodeTokenizer: [template] ::= "" | [variable] " " [template] | [value] " " + * [template] | [function-call] " + *

+ * [variable] ::= "$" [valid-name] [value] ::= "'" [text] "'" | '"' [text] '"' + * [function-call] ::= [function-id] | [function-id] [parameter] [parameter] ::= [variable] | + * [value] + *

+ * BNF parsed by dedicated blocks [function-id] ::= [valid-name] | [valid-name] "." [valid-name] + * [valid-name] ::= [valid-symbol] | [valid-symbol] [valid-name] [valid-symbol] ::= [letter] | + * [digit] | "_" [letter] ::= "a" | "b" ... | "z" | "A" | "B" ... | "Z" [digit] ::= + * "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" */ public class TemplateTokenizer { + /* + * #region private + * ================================================================================ + * + * private readonly ILogger _log; + */ + private final CodeTokenizer codeTokenizer = new CodeTokenizer(); + + private static String subStr(String text, int startIndex, int stopIndex) { + return text.substring(startIndex, stopIndex); + } + + private static boolean isQuote(char c) { + return c == Symbols.DblQuote || c == Symbols.SglQuote; + } + + private static boolean canBeEscaped(char c) { + return c == Symbols.DblQuote || c == Symbols.SglQuote || c == Symbols.EscapeChar; + } + /** - * Extract blocks from the given text + * Extract blocks from the given text + * * @param text Text to parse * @return List of blocks found in the text */ @@ -126,7 +142,7 @@ public class TemplateTokenizer { .substring(2, contentWithDelimiters.length() - 2) .trim(); - if (contentWithoutDelimiters.length() == 0) { + if (contentWithoutDelimiters.isEmpty()) { // If what is left is empty, consider the raw block a Text Block blocks.add(new TextBlock(contentWithDelimiters)); } else { @@ -185,24 +201,4 @@ public class TemplateTokenizer { return Collections.unmodifiableList(blocks); } - - /* - * #region private - * ================================================================================ - * - * private readonly ILogger _log; - */ - private final CodeTokenizer codeTokenizer = new CodeTokenizer(); - - private static String subStr(String text, int startIndex, int stopIndex) { - return text.substring(startIndex, stopIndex); - } - - private static boolean isQuote(char c) { - return c == Symbols.DblQuote || c == Symbols.SglQuote; - } - - private static boolean canBeEscaped(char c) { - return c == Symbols.DblQuote || c == Symbols.SglQuote || c == Symbols.EscapeChar; - } } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/CodeBlock.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/CodeBlock.java index 888194b5ff..ac81c2edfa 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/CodeBlock.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/CodeBlock.java @@ -2,14 +2,14 @@ package com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks; import com.microsoft.semantickernel.Kernel; +import com.microsoft.semantickernel.contextvariables.ContextVariable; +import com.microsoft.semantickernel.contextvariables.ContextVariableType; +import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; import com.microsoft.semantickernel.exceptions.SKException; import com.microsoft.semantickernel.orchestration.FunctionResult; import com.microsoft.semantickernel.orchestration.InvocationContext; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionMetadata; -import com.microsoft.semantickernel.contextvariables.ContextVariable; -import com.microsoft.semantickernel.contextvariables.ContextVariableType; -import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; import com.microsoft.semantickernel.templateengine.semantickernel.TemplateException; import com.microsoft.semantickernel.templateengine.semantickernel.TemplateException.ErrorCodes; import java.util.Collections; @@ -47,7 +47,7 @@ public final class CodeBlock extends Block implements CodeRendering { return false; } - if (this.tokens.size() > 0 && this.tokens.get(0).getType() == BlockTypes.NAMED_ARG) { + if (!this.tokens.isEmpty() && this.tokens.get(0).getType() == BlockTypes.NAMED_ARG) { LOGGER.error("Unexpected named argument found. Expected function name first."); return false; } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/CodeRendering.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/CodeRendering.java index ff597f3bea..7a411a0956 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/CodeRendering.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/CodeRendering.java @@ -17,8 +17,8 @@ public interface CodeRendering { * * @param kernel Kernel to use for rendering * @param arguments Optional arguments used to render the block - * @param context Optional context used to render the block, - * typically used to pass {code KernelHooks} to the render method. + * @param context Optional context used to render the block, typically used to pass {code + * KernelHooks} to the render method. * @return Rendered content * @see com.microsoft.semantickernel.hooks.KernelHooks */ diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/FunctionIdBlock.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/FunctionIdBlock.java index 305a0c632b..25f58c42fd 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/FunctionIdBlock.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/FunctionIdBlock.java @@ -8,6 +8,7 @@ import javax.annotation.Nullable; * Represents a function identifier block. */ public final class FunctionIdBlock extends Block implements TextRendering { + private final String skillName; private final String functionName; @@ -37,6 +38,14 @@ public final class FunctionIdBlock extends Block implements TextRendering { this.skillName = ""; } + private static boolean hasMoreThanOneDot(String value) { + if (value == null || value.length() < 2) { + return false; + } + + return value.matches("^.*\\..*\\..*$"); + } + @Override @Nullable public String render(@Nullable KernelFunctionArguments variables) { @@ -60,14 +69,6 @@ public final class FunctionIdBlock extends Block implements TextRendering { return true; } - private static boolean hasMoreThanOneDot(String value) { - if (value == null || value.length() < 2) { - return false; - } - - return value.matches("^.*\\..*\\..*$"); - } - /** * Get the plugin name. * diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/NamedArgBlock.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/NamedArgBlock.java index e2dac6e0ca..7a27d0aefb 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/NamedArgBlock.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/NamedArgBlock.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks; import static com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks.BlockTypes.NAMED_ARG; @@ -79,6 +80,31 @@ public class NamedArgBlock extends Block implements TextRendering { return new NamedArgBlock(content, name, value, argNameAsVarBlock, varBlock, valBlock); } + @Nullable + public static String tryGetName(String text) { + return splitAndGetPart(text, 0); + } + + @Nullable + public static String tryGetValue(String text) { + return splitAndGetPart(text, 1); + } + + @SuppressWarnings("StringSplitter") + @Nullable + private static String splitAndGetPart(String text, int x) { + if (Verify.isNullOrEmpty(text)) { + return null; + } + + String[] argBlockParts = text.split(String.valueOf(Symbols.NamedArgBlockSeparator)); + + if (argBlockParts.length == 2) { + return argBlockParts[x].trim(); + } + return null; + } + @Override public boolean isValid() { if (Verify.isNullOrEmpty(this.name)) { @@ -106,6 +132,14 @@ public class NamedArgBlock extends Block implements TextRendering { return getContent(); } + ///

+ /// Attempts to extract the name and value of a named argument block from a string + /// + /// String from which to extract a name and value + /// Name extracted from argument block, when successful. Empty string otherwise. + /// Value extracted from argument block, when successful. Empty string otherwise. + /// true when a name and value are successfully extracted from the given text, false otherwise + @Nullable public VarBlock getVarBlock() { return varBlock; @@ -130,37 +164,4 @@ public class NamedArgBlock extends Block implements TextRendering { return ""; } - - /// - /// Attempts to extract the name and value of a named argument block from a string - /// - /// String from which to extract a name and value - /// Name extracted from argument block, when successful. Empty string otherwise. - /// Value extracted from argument block, when successful. Empty string otherwise. - /// true when a name and value are successfully extracted from the given text, false otherwise - - @Nullable - public static String tryGetName(String text) { - return splitAndGetPart(text, 0); - } - - @Nullable - public static String tryGetValue(String text) { - return splitAndGetPart(text, 1); - } - - @SuppressWarnings("StringSplitter") - @Nullable - private static String splitAndGetPart(String text, int x) { - if (Verify.isNullOrEmpty(text)) { - return null; - } - - String[] argBlockParts = text.split(String.valueOf(Symbols.NamedArgBlockSeparator)); - - if (argBlockParts.length == 2) { - return argBlockParts[x].trim(); - } - return null; - } } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/TextBlock.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/TextBlock.java index 5ca24bf754..006e902180 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/TextBlock.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/TextBlock.java @@ -10,6 +10,10 @@ public final class TextBlock extends Block implements TextRendering { super(text, BlockTypes.TEXT); } + public TextBlock(String text, int startIndex, int stopIndex) { + super(text.substring(startIndex, stopIndex), BlockTypes.TEXT); + } + @Override public boolean isValid() { return true; @@ -19,8 +23,4 @@ public final class TextBlock extends Block implements TextRendering { public String render(@Nullable KernelFunctionArguments variables) { return super.getContent(); } - - public TextBlock(String text, int startIndex, int stopIndex) { - super(text.substring(startIndex, stopIndex), BlockTypes.TEXT); - } } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/TextRendering.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/TextRendering.java index aadd1c8659..f59b1f79fc 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/TextRendering.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/TextRendering.java @@ -11,6 +11,7 @@ public interface TextRendering { /** * Render the block using only the given variables. + * * @param variables Optional variables used to render the block * @return Rendered content */ diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/ValBlock.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/ValBlock.java index f98f257cfe..b251b6bb4e 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/ValBlock.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/ValBlock.java @@ -30,6 +30,12 @@ public final class ValBlock extends Block implements TextRendering { this.value = this.getContent().substring(1, this.getContent().length() - 1); } + public static boolean hasValPrefix(@Nullable String text) { + return text != null + && !text.isEmpty() + && (text.charAt(0) == Symbols.DblQuote || text.charAt(0) == Symbols.SglQuote); + } + @Override @Nullable public String render(@Nullable KernelFunctionArguments variables) { @@ -54,10 +60,4 @@ public final class ValBlock extends Block implements TextRendering { return true; } - - public static boolean hasValPrefix(@Nullable String text) { - return text != null - && text.length() > 0 - && (text.charAt(0) == Symbols.DblQuote || text.charAt(0) == Symbols.SglQuote); - } } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/VarBlock.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/VarBlock.java index bb5a202afe..eedb03f79a 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/VarBlock.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/VarBlock.java @@ -1,8 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.implementation.templateengine.tokenizer.blocks; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.contextvariables.ContextVariable; +import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; import com.microsoft.semantickernel.templateengine.semantickernel.TemplateException; import javax.annotation.Nullable; import org.slf4j.Logger; diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionInvocation.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionInvocation.java index f7e5eca7c5..350e775a25 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionInvocation.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionInvocation.java @@ -1,8 +1,10 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.orchestration; import com.microsoft.semantickernel.Kernel; import com.microsoft.semantickernel.contextvariables.ContextVariable; import com.microsoft.semantickernel.contextvariables.ContextVariableType; +import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; import com.microsoft.semantickernel.exceptions.SKException; import com.microsoft.semantickernel.hooks.KernelHook; @@ -20,8 +22,9 @@ import reactor.core.CoreSubscriber; import reactor.core.publisher.Mono; import reactor.core.publisher.SynchronousSink; -/** +/** * {@code FunctionInvocation} supports fluent invocation of a function in the kernel. + * * @param The type of the result of the function invocation. */ public class FunctionInvocation extends Mono> { @@ -33,7 +36,7 @@ public class FunctionInvocation extends Mono> { protected final Kernel kernel; @Nullable protected final ContextVariableType resultType; - + protected final ContextVariableTypes contextVariableTypes = new ContextVariableTypes(); @Nullable protected KernelFunctionArguments arguments; @Nullable @@ -42,11 +45,11 @@ public class FunctionInvocation extends Mono> { protected PromptExecutionSettings promptExecutionSettings; @Nullable protected UnmodifiableToolCallBehavior toolCallBehavior; - protected final ContextVariableTypes contextVariableTypes = new ContextVariableTypes(); /** * Create a new function invocation. - * @param kernel The kernel to invoke the function on. + * + * @param kernel The kernel to invoke the function on. * @param function The function to invoke. */ @SuppressFBWarnings("EI_EXPOSE_REP2") @@ -61,8 +64,9 @@ public class FunctionInvocation extends Mono> { /** * Create a new function invocation. - * @param kernel The kernel to invoke the function on. - * @param function The function to invoke. + * + * @param kernel The kernel to invoke the function on. + * @param function The function to invoke. * @param resultType The type of the result of the function invocation. */ @SuppressFBWarnings("EI_EXPOSE_REP2") @@ -79,145 +83,6 @@ public class FunctionInvocation extends Mono> { this.addKernelHooks(kernel.getGlobalKernelHooks()); } - /** - * Supply arguments to the function invocation. - * @param arguments The arguments to supply to the function invocation. - * @return this {@code FunctionInvocation} for fluent chaining. - */ - public FunctionInvocation withArguments( - @Nullable KernelFunctionArguments arguments) { - if (arguments == null) { - this.arguments = null; - } else { - this.arguments = new KernelFunctionArguments(arguments); - } - return this; - } - - /** - * Supply the result type of function invocation. - * @param resultType The arguments to supply to the function invocation. - * @param The type of the result of the function invocation. - * @return A new {@code FunctionInvocation} for fluent chaining. - */ - public FunctionInvocation withResultType(ContextVariableType resultType) { - return new FunctionInvocation<>( - kernel, - function, - resultType) - .withArguments(arguments) - .addKernelHooks(hooks) - .withPromptExecutionSettings(promptExecutionSettings) - .withToolCallBehavior(toolCallBehavior); - } - - /** - * Add a kernel hook to the function invocation. - * @param hook The kernel hook to add. - * @return this {@code FunctionInvocation} for fluent chaining. - */ - public FunctionInvocation addKernelHook(@Nullable KernelHook hook) { - if (hook == null) { - return this; - } - KernelHooks clone = new KernelHooks(this.hooks); - clone.addHook(hook); - this.hooks = unmodifiableClone(clone); - return this; - } - - /** - * Add kernel hooks to the function invocation. - * @param hooks The kernel hooks to add. - * @return this {@code FunctionInvocation} for fluent chaining. - */ - public FunctionInvocation addKernelHooks( - @Nullable KernelHooks hooks) { - if (hooks == null) { - return this; - } - this.hooks = unmodifiableClone(new KernelHooks(this.hooks).addHooks(hooks)); - return this; - } - - /** - * Supply prompt execution settings to the function invocation. - * @param promptExecutionSettings The prompt execution settings to supply to the function invocation. - * @return this {@code FunctionInvocation} for fluent chaining. - */ - public FunctionInvocation withPromptExecutionSettings( - @Nullable PromptExecutionSettings promptExecutionSettings) { - this.promptExecutionSettings = promptExecutionSettings; - return this; - } - - /** - * Supply tool call behavior to the function invocation. - * @param toolCallBehavior The tool call behavior to supply to the function invocation. - * @return this {@code FunctionInvocation} for fluent chaining. - */ - public FunctionInvocation withToolCallBehavior(@Nullable ToolCallBehavior toolCallBehavior) { - this.toolCallBehavior = unmodifiableClone(toolCallBehavior); - return this; - } - - /** - * Supply a type converter to the function invocation. - * @param typeConverter The type converter to supply to the function invocation. - * @return this {@code FunctionInvocation} for fluent chaining. - */ - public FunctionInvocation withTypeConverter(ContextVariableType typeConverter) { - contextVariableTypes.putConverter(typeConverter.getConverter()); - return this; - } - - /** - * Supply a context variable type to the function invocation. - * @param contextVariableTypes The context variable types to supply to the function invocation. - * @return this {@code FunctionInvocation} for fluent chaining. - */ - public FunctionInvocation withTypes(ContextVariableTypes contextVariableTypes) { - this.contextVariableTypes.putConverters(contextVariableTypes); - return this; - } - - /** - * Use an invocation context variable to supply the types, tool call behavior, - * prompt execution settings, and kernel hooks to the function invocation. - * @param invocationContext The invocation context to supply to the function invocation. - * @return this {@code FunctionInvocation} for fluent chaining. - */ - public FunctionInvocation withInvocationContext( - @Nullable InvocationContext invocationContext) { - if (invocationContext == null) { - return this; - } - withTypes(invocationContext.getContextVariableTypes()); - withToolCallBehavior(invocationContext.getToolCallBehavior()); - withPromptExecutionSettings(invocationContext.getPromptExecutionSettings()); - addKernelHooks(invocationContext.getKernelHooks()); - return this; - } - - /** - * This method hanldes the reactive stream when the KernelFunciton is invoked. - * @param coreSubscriber The subscriber to subscribe to the function invocation. - */ - @Override - public void subscribe(CoreSubscriber> coreSubscriber) { - performSubscribe( - coreSubscriber, - kernel, - function, - arguments, - resultType, - new InvocationContext( - hooks, - promptExecutionSettings, - toolCallBehavior, - contextVariableTypes)); - } - // Extracted to static to ensure mutable state is not used private static void performSubscribe( CoreSubscriber> coreSubscriber, @@ -289,4 +154,154 @@ public class FunctionInvocation extends Mono> { } } + /** + * Supply arguments to the function invocation. + * + * @param arguments The arguments to supply to the function invocation. + * @return this {@code FunctionInvocation} for fluent chaining. + */ + public FunctionInvocation withArguments( + @Nullable KernelFunctionArguments arguments) { + if (arguments == null) { + this.arguments = null; + } else { + this.arguments = new KernelFunctionArguments(arguments); + } + return this; + } + + /** + * Supply the result type of function invocation. + * + * @param resultType The arguments to supply to the function invocation. + * @param The type of the result of the function invocation. + * @return A new {@code FunctionInvocation} for fluent chaining. + */ + public FunctionInvocation withResultType(ContextVariableType resultType) { + return new FunctionInvocation<>( + kernel, + function, + resultType) + .withArguments(arguments) + .addKernelHooks(hooks) + .withPromptExecutionSettings(promptExecutionSettings) + .withToolCallBehavior(toolCallBehavior); + } + + /** + * Add a kernel hook to the function invocation. + * + * @param hook The kernel hook to add. + * @return this {@code FunctionInvocation} for fluent chaining. + */ + public FunctionInvocation addKernelHook(@Nullable KernelHook hook) { + if (hook == null) { + return this; + } + KernelHooks clone = new KernelHooks(this.hooks); + clone.addHook(hook); + this.hooks = unmodifiableClone(clone); + return this; + } + + /** + * Add kernel hooks to the function invocation. + * + * @param hooks The kernel hooks to add. + * @return this {@code FunctionInvocation} for fluent chaining. + */ + public FunctionInvocation addKernelHooks( + @Nullable KernelHooks hooks) { + if (hooks == null) { + return this; + } + this.hooks = unmodifiableClone(new KernelHooks(this.hooks).addHooks(hooks)); + return this; + } + + /** + * Supply prompt execution settings to the function invocation. + * + * @param promptExecutionSettings The prompt execution settings to supply to the function + * invocation. + * @return this {@code FunctionInvocation} for fluent chaining. + */ + public FunctionInvocation withPromptExecutionSettings( + @Nullable PromptExecutionSettings promptExecutionSettings) { + this.promptExecutionSettings = promptExecutionSettings; + return this; + } + + /** + * Supply tool call behavior to the function invocation. + * + * @param toolCallBehavior The tool call behavior to supply to the function invocation. + * @return this {@code FunctionInvocation} for fluent chaining. + */ + public FunctionInvocation withToolCallBehavior(@Nullable ToolCallBehavior toolCallBehavior) { + this.toolCallBehavior = unmodifiableClone(toolCallBehavior); + return this; + } + + /** + * Supply a type converter to the function invocation. + * + * @param typeConverter The type converter to supply to the function invocation. + * @return this {@code FunctionInvocation} for fluent chaining. + */ + public FunctionInvocation withTypeConverter(ContextVariableTypeConverter typeConverter) { + contextVariableTypes.putConverter(typeConverter); + return this; + } + + /** + * Supply a context variable type to the function invocation. + * + * @param contextVariableTypes The context variable types to supply to the function invocation. + * @return this {@code FunctionInvocation} for fluent chaining. + */ + public FunctionInvocation withTypes(ContextVariableTypes contextVariableTypes) { + this.contextVariableTypes.putConverters(contextVariableTypes); + return this; + } + + /** + * Use an invocation context variable to supply the types, tool call behavior, prompt execution + * settings, and kernel hooks to the function invocation. + * + * @param invocationContext The invocation context to supply to the function invocation. + * @return this {@code FunctionInvocation} for fluent chaining. + */ + public FunctionInvocation withInvocationContext( + @Nullable InvocationContext invocationContext) { + if (invocationContext == null) { + return this; + } + withTypes(invocationContext.getContextVariableTypes()); + withToolCallBehavior(invocationContext.getToolCallBehavior()); + withPromptExecutionSettings(invocationContext.getPromptExecutionSettings()); + addKernelHooks(invocationContext.getKernelHooks()); + return this; + } + + /** + * This method hanldes the reactive stream when the KernelFunciton is invoked. + * + * @param coreSubscriber The subscriber to subscribe to the function invocation. + */ + @Override + public void subscribe(CoreSubscriber> coreSubscriber) { + performSubscribe( + coreSubscriber, + kernel, + function, + arguments, + resultType, + new InvocationContext( + hooks, + promptExecutionSettings, + toolCallBehavior, + contextVariableTypes)); + } + } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionResult.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionResult.java index dfb5218626..480121e455 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionResult.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionResult.java @@ -1,6 +1,8 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.orchestration; import com.microsoft.semantickernel.contextvariables.ContextVariable; +import com.microsoft.semantickernel.contextvariables.ContextVariableType; import javax.annotation.Nullable; /** @@ -39,10 +41,10 @@ public class FunctionResult { } /** - * Get the result of the function invocation. - * NOTE: If you get a ClassCastException from this method, - * try adding a result type with - * {@link FunctionInvocation#withResultType(ContextVariableType)} + * Get the result of the function invocation. + * NOTE: If you get a ClassCastException from this method, + * try adding a result type with {@link FunctionInvocation#withResultType(ContextVariableType)} + * )} * * @return The result of the function invocation. * @throws ClassCastException If the result is not of the expected type. diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionResultMetadata.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionResultMetadata.java index a5e7a00a57..8295f9514f 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionResultMetadata.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionResultMetadata.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.orchestration; import com.azure.ai.openai.models.CompletionsUsage; @@ -13,13 +14,19 @@ import javax.annotation.Nullable; */ public class FunctionResultMetadata { - /** The key for id metadata. */ + /** + * The key for id metadata. + */ public static final String ID = "id"; - /** The key for usage metadata. */ + /** + * The key for usage metadata. + */ public static final String USAGE = "usage"; - /** The key for createdAt metadata. */ + /** + * The key for createdAt metadata. + */ public static final String CREATED_AT = "createdAt"; private final CaseInsensitiveMap> metadata; @@ -43,8 +50,8 @@ public class FunctionResultMetadata { /** * Create a new instance of FunctionResultMetadata. * - * @param id The id of the result of the function invocation. - * @param usage The usage of the result of the function invocation. + * @param id The id of the result of the function invocation. + * @param usage The usage of the result of the function invocation. * @param createdAt The time the result was created. * @return A new instance of FunctionResultMetadata. */ diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/InvocationContext.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/InvocationContext.java index bb87903c5c..4e94be080e 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/InvocationContext.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/InvocationContext.java @@ -1,19 +1,20 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.orchestration; import com.microsoft.semantickernel.builders.Buildable; import com.microsoft.semantickernel.builders.SemanticKernelBuilder; +import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; +import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; import com.microsoft.semantickernel.hooks.KernelHooks; import com.microsoft.semantickernel.hooks.KernelHooks.UnmodifiableKernelHooks; import com.microsoft.semantickernel.orchestration.ToolCallBehavior.UnmodifiableToolCallBehavior; -import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; -import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import javax.annotation.Nullable; /** - * Context passed to a Kernel or KernelFunction invoke. This class is primarily for - * internal use. The preferred way to supply a context is to use the discrete "with" - * methods in {@link FunctionInvocation}. + * Context passed to a Kernel or KernelFunction invoke. This class is primarily for internal use. + * The preferred way to supply a context is to use the discrete "with" methods in + * {@link FunctionInvocation}. */ public class InvocationContext implements Buildable { @@ -77,45 +78,9 @@ public class InvocationContext implements Buildable { } } - /** - * Get the hooks to use for the invocation. - * @return The hooks to use for the invocation. - */ - @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "returns UnmodifiableKernelHooks") - @Nullable - public UnmodifiableKernelHooks getKernelHooks() { - return hooks; - } - - /** - * Get the settings for prompt execution. - * @return The settings for prompt execution. - */ - @Nullable - public PromptExecutionSettings getPromptExecutionSettings() { - return promptExecutionSettings; - } - - /** - * Get the behavior for tool calls. - * @return The behavior for tool calls. - */ - @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "returns UnmodifiableToolCallBehavior") - @Nullable - public UnmodifiableToolCallBehavior getToolCallBehavior() { - return toolCallBehavior; - } - - /** - * Get the types of context variables. - * @return The types of context variables. - */ - public ContextVariableTypes getContextVariableTypes() { - return new ContextVariableTypes(contextVariableTypes); - } - /** * Create a new {@link Builder} for building an instance of {@code InvocationContext}. + * * @return the new Builder. */ public static Builder builder() { @@ -146,24 +111,63 @@ public class InvocationContext implements Buildable { } } + /** + * Get the hooks to use for the invocation. + * + * @return The hooks to use for the invocation. + */ + @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "returns UnmodifiableKernelHooks") + @Nullable + public UnmodifiableKernelHooks getKernelHooks() { + return hooks; + } + + /** + * Get the settings for prompt execution. + * + * @return The settings for prompt execution. + */ + @Nullable + public PromptExecutionSettings getPromptExecutionSettings() { + return promptExecutionSettings; + } + + /** + * Get the behavior for tool calls. + * + * @return The behavior for tool calls. + */ + @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "returns UnmodifiableToolCallBehavior") + @Nullable + public UnmodifiableToolCallBehavior getToolCallBehavior() { + return toolCallBehavior; + } + + /** + * Get the types of context variables. + * + * @return The types of context variables. + */ + public ContextVariableTypes getContextVariableTypes() { + return new ContextVariableTypes(contextVariableTypes); + } + /** * Builder for {@link InvocationContext}. */ public static class Builder implements SemanticKernelBuilder { + private final ContextVariableTypes contextVariableTypes = new ContextVariableTypes(); @Nullable private UnmodifiableKernelHooks hooks; - @Nullable private PromptExecutionSettings promptExecutionSettings; - @Nullable private UnmodifiableToolCallBehavior toolCallBehavior; - private final ContextVariableTypes contextVariableTypes = new ContextVariableTypes(); - /** * Add kernel hooks to the builder. + * * @param hooks the hooks to add. * @return this {@link Builder} */ @@ -175,6 +179,7 @@ public class InvocationContext implements Buildable { /** * Add prompt execution settings to the builder. + * * @param promptExecutionSettings the settings to add. * @return this {@link Builder} */ @@ -186,6 +191,7 @@ public class InvocationContext implements Buildable { /** * Add tool call behavior to the builder. + * * @param toolCallBehavior the behavior to add. * @return this {@link Builder} */ @@ -197,6 +203,7 @@ public class InvocationContext implements Buildable { /** * Add a context variable type converter to the builder. + * * @param converter the converter to add. * @return this {@link Builder} */ diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/PromptExecutionSettings.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/PromptExecutionSettings.java index 4bf7df4fc0..96ff677ee8 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/PromptExecutionSettings.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/PromptExecutionSettings.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.orchestration; import com.fasterxml.jackson.annotation.JsonCreator; @@ -15,13 +16,13 @@ import javax.annotation.Nullable; public class PromptExecutionSettings { public static final String DEFAULT_SERVICE_ID = "default"; - public static final int DEFAULT_MAX_TOKENS = 256; - public static final double DEFAULT_TEMPERATURE = 1.0; - public static final double DEFAULT_TOP_P = 1.0; - public static final double DEFAULT_PRESENCE_PENALTY = 0.0; - public static final double DEFAULT_FREQUENCY_PENALTY = 0.0; - public static final int DEFAULT_BEST_OF = 1; - public static final int DEFAULT_RESULTS_PER_PROMPT = 1; + public static final Integer DEFAULT_MAX_TOKENS = 256; + public static final Double DEFAULT_TEMPERATURE = 1.0; + public static final Double DEFAULT_TOP_P = 1.0; + public static final Double DEFAULT_PRESENCE_PENALTY = 0.0; + public static final Double DEFAULT_FREQUENCY_PENALTY = 0.0; + public static final Integer DEFAULT_BEST_OF = 1; + public static final Integer DEFAULT_RESULTS_PER_PROMPT = 1; private static final String SERVICE_ID = "service_id"; private static final String MODEL_ID = "model_id"; @@ -48,34 +49,35 @@ public class PromptExecutionSettings { private final String user; @Nullable private final List stopSequences; - private Map tokenSelectionBiases; + private final Map tokenSelectionBiases; /** * Create a new instance of PromptExecutionSettings. - * @param serviceId The id of the AI service to use for prompt execution. - * @param modelId The id of the model to use for prompt execution. - * @param temperature The temperature setting for prompt execution. - * @param topP The topP setting for prompt execution. - * @param presencePenalty The presence penalty setting for prompt execution. - * @param frequencyPenalty The frequency penalty setting for prompt execution. - * @param maxTokens The maximum number of tokens to generate in the output. - * @param resultsPerPrompt The number of results to generate for each prompt. - * @param bestOf The best of setting for prompt execution. - * @param user The user to associate with the prompt execution. - * @param stopSequences The stop sequences to use for prompt execution. + * + * @param serviceId The id of the AI service to use for prompt execution. + * @param modelId The id of the model to use for prompt execution. + * @param temperature The temperature setting for prompt execution. + * @param topP The topP setting for prompt execution. + * @param presencePenalty The presence penalty setting for prompt execution. + * @param frequencyPenalty The frequency penalty setting for prompt execution. + * @param maxTokens The maximum number of tokens to generate in the output. + * @param resultsPerPrompt The number of results to generate for each prompt. + * @param bestOf The best of setting for prompt execution. + * @param user The user to associate with the prompt execution. + * @param stopSequences The stop sequences to use for prompt execution. * @param tokenSelectionBiases The token selection biases to use for prompt execution. */ @JsonCreator public PromptExecutionSettings( @JsonProperty(SERVICE_ID) String serviceId, @JsonProperty(MODEL_ID) String modelId, - @JsonProperty(TEMPERATURE) double temperature, - @JsonProperty(TOP_P) double topP, - @JsonProperty(PRESENCE_PENALTY) double presencePenalty, - @JsonProperty(FREQUENCY_PENALTY) double frequencyPenalty, - @JsonProperty(MAX_TOKENS) int maxTokens, - @JsonProperty(RESULTS_PER_PROMPT) int resultsPerPrompt, - @JsonProperty(BEST_OF) int bestOf, + @JsonProperty(TEMPERATURE) Double temperature, + @JsonProperty(TOP_P) Double topP, + @JsonProperty(PRESENCE_PENALTY) Double presencePenalty, + @JsonProperty(FREQUENCY_PENALTY) Double frequencyPenalty, + @JsonProperty(MAX_TOKENS) Integer maxTokens, + @JsonProperty(RESULTS_PER_PROMPT) Integer resultsPerPrompt, + @JsonProperty(BEST_OF) Integer bestOf, @JsonProperty(USER) String user, @Nullable @JsonProperty(STOP_SEQUENCES) List stopSequences, @Nullable @JsonProperty(TOKEN_SELECTION_BIASES) Map tokenSelectionBiases) { @@ -85,21 +87,44 @@ public class PromptExecutionSettings { this.topP = clamp(topP, 0d, 1d, DEFAULT_TOP_P); this.presencePenalty = clamp(presencePenalty, -2d, 2d, DEFAULT_PRESENCE_PENALTY); this.frequencyPenalty = clamp(frequencyPenalty, -2d, 2d, DEFAULT_FREQUENCY_PENALTY); - this.maxTokens = clamp(maxTokens, 1, Integer.MAX_VALUE); - this.resultsPerPrompt = clamp(resultsPerPrompt, 1, Integer.MAX_VALUE); - this.bestOf = clamp(bestOf, 1, Integer.MAX_VALUE); - ; + this.maxTokens = clamp(maxTokens, 1, Integer.MAX_VALUE, DEFAULT_MAX_TOKENS); + this.resultsPerPrompt = clamp(resultsPerPrompt, 1, Integer.MAX_VALUE, + DEFAULT_RESULTS_PER_PROMPT); + this.bestOf = clamp(bestOf, 1, Integer.MAX_VALUE, DEFAULT_BEST_OF); this.user = user; this.stopSequences = stopSequences != null ? new ArrayList<>(stopSequences) : Collections.emptyList(); this.tokenSelectionBiases = tokenSelectionBiases != null ? new HashMap<>(tokenSelectionBiases) : Collections.emptyMap(); - this.tokenSelectionBiases.replaceAll((k, v) -> clamp(v, -100, 100)); + this.tokenSelectionBiases.replaceAll((k, v) -> clamp(v, -100, 100, 0)); + } + + /** + * Create a new builder for PromptExecutionSettings. + * + * @return A new builder for PromptExecutionSettings. + */ + public static Builder builder() { + return new Builder(); + } + + private static T clamp(T value, T min, T max, T defaultValue) { + if (value == null) { + return defaultValue; + } + if (value.doubleValue() < min.doubleValue()) { + return min; + } + if (value.doubleValue() > max.doubleValue()) { + return max; + } + return value; } /** * Get the id of the AI service to use for prompt execution. + * * @return The id of the AI service to use for prompt execution. */ @JsonProperty(SERVICE_ID) @@ -109,6 +134,7 @@ public class PromptExecutionSettings { /** * Get the id of the model to use for prompt execution. + * * @return The id of the model to use for prompt execution. */ @JsonProperty(MODEL_ID) @@ -119,6 +145,7 @@ public class PromptExecutionSettings { /** * The temperature setting controls the randomness of the output. Lower values produce more * deterministic outputs, while higher values produce more random outputs. + * * @return The temperature setting. */ @JsonProperty(TEMPERATURE) @@ -132,6 +159,7 @@ public class PromptExecutionSettings { * tokens whose cumulative probability mass is greater than the threshold. For example, if the * value is 0.1, the model considers only the tokens that make up the top 10% of the cumulative * probability mass. + * * @return The topP setting. */ @JsonProperty(TOP_P) @@ -140,9 +168,10 @@ public class PromptExecutionSettings { } /** - * Presence penalty encourages the model to use a more or less diverse range of tokens in the output. - * A higher value means that the model will try to use a greater variety of tokens - * in the ouput. + * Presence penalty encourages the model to use a more or less diverse range of tokens in the + * output. A higher value means that the model will try to use a greater variety of tokens in + * the ouput. + * * @return The presence penalty setting. */ @JsonProperty(PRESENCE_PENALTY) @@ -151,9 +180,9 @@ public class PromptExecutionSettings { } /** - * Frequency penalty encourages the model to avoid repeating the same token in the output. - * A higher value means that the model will be less likely to repeat a token. - * + * Frequency penalty encourages the model to avoid repeating the same token in the output. A + * higher value means that the model will be less likely to repeat a token. + * * @return The frequency penalty setting. */ @JsonProperty(FREQUENCY_PENALTY) @@ -163,6 +192,7 @@ public class PromptExecutionSettings { /** * The maximum number of tokens to generate in the output. + * * @return The maximum number of tokens to generate in the output. */ @JsonProperty(MAX_TOKENS) @@ -171,7 +201,8 @@ public class PromptExecutionSettings { } /** - * The number of results to generate for each prompt. + * The number of results to generate for each prompt. + * * @return The number of results to generate for each prompt. */ @JsonProperty(RESULTS_PER_PROMPT) @@ -180,7 +211,8 @@ public class PromptExecutionSettings { } /** - * The log probability threshold for a result to be considered. + * The log probability threshold for a result to be considered. + * * @return The log probability threshold for a result to be considered. */ @JsonProperty(BEST_OF) @@ -191,6 +223,7 @@ public class PromptExecutionSettings { /** * The user to associate with the prompt execution. + * * @return The user to associate with the prompt execution. */ @JsonProperty(USER) @@ -200,6 +233,7 @@ public class PromptExecutionSettings { /** * The stop sequences to use for prompt execution. + * * @return The stop sequences to use for prompt execution. */ @JsonProperty(STOP_SEQUENCES) @@ -212,9 +246,10 @@ public class PromptExecutionSettings { } /** - * The token selection biases to use for prompt execution. The key is the token id - * from the tokenizer, and the value is the bias. A negative bias will make the model less likely - * to use the token, and a positive bias will make the model more likely to use the token. + * The token selection biases to use for prompt execution. The key is the token id from the + * tokenizer, and the value is the bias. A negative bias will make the model less likely to use + * the token, and a positive bias will make the model more likely to use the token. + * * @return The token selection biases to use for prompt execution. */ @JsonProperty(TOKEN_SELECTION_BIASES) @@ -226,14 +261,6 @@ public class PromptExecutionSettings { return null; } - /** - * Create a new builder for PromptExecutionSettings. - * @return A new builder for PromptExecutionSettings. - */ - public static Builder builder() { - return new Builder(); - } - /** * Builder for PromptExecutionSettings. */ @@ -243,6 +270,7 @@ public class PromptExecutionSettings { /** * Set the id of the AI service to use for prompt execution. + * * @param serviceId The id of the AI service to use for prompt execution. * @return This builder. */ @@ -253,6 +281,7 @@ public class PromptExecutionSettings { /** * Set the id of the model to use for prompt execution. + * * @param modelId The id of the model to use for prompt execution. * @return This builder. */ @@ -262,8 +291,9 @@ public class PromptExecutionSettings { } /** - * Set the temperature setting for prompt execution. The value is - * clamped to the range [0.0, 2.0], and the default is 1.0. + * Set the temperature setting for prompt execution. The value is clamped to the range [0.0, + * 2.0], and the default is 1.0. + * * @param temperature The temperature setting for prompt execution. * @return This builder. */ @@ -277,6 +307,7 @@ public class PromptExecutionSettings { /** * Set the topP setting for prompt execution. The value is clamped to the range [0.0, 1.0], * and the default is 1.0. + * * @param topP The topP setting for prompt execution. * @return This builder. */ @@ -290,6 +321,7 @@ public class PromptExecutionSettings { /** * Set the presence penalty setting for prompt execution. The value is clamped to the range * [-2.0, 2.0], and the default is 0.0. + * * @param presencePenalty The presence penalty setting for prompt execution. * @return This builder. */ @@ -303,6 +335,7 @@ public class PromptExecutionSettings { /** * Set the frequency penalty setting for prompt execution. The value is clamped to the range * [-2.0, 2.0], and the default is 0.0. + * * @param frequencyPenalty The frequency penalty setting for prompt execution. * @return This builder. */ @@ -316,6 +349,7 @@ public class PromptExecutionSettings { /** * Set the maximum number of tokens to generate in the output. The value is clamped to the * range [1, Integer.MAX_VALUE], and the default is 256. + * * @param maxTokens The maximum number of tokens to generate in the output. * @return This builder. */ @@ -325,8 +359,9 @@ public class PromptExecutionSettings { } /** - * Set the number of results to generate for each prompt. The value is clamped to the - * range [1, Integer.MAX_VALUE], and the default is 1. + * Set the number of results to generate for each prompt. The value is clamped to the range + * [1, Integer.MAX_VALUE], and the default is 1. + * * @param resultsPerPrompt The number of results to generate for each prompt. * @return This builder. */ @@ -336,8 +371,9 @@ public class PromptExecutionSettings { } /** - * Set the best of setting for prompt execution. The value is clamped to the - * range [1, Integer.MAX_VALUE], and the default is 1. + * Set the best of setting for prompt execution. The value is clamped to the range [1, + * Integer.MAX_VALUE], and the default is 1. + * * @param bestOf The best of setting for prompt execution. * @return This builder. */ @@ -348,6 +384,7 @@ public class PromptExecutionSettings { /** * Set the user to associate with the prompt execution. + * * @param user The user to associate with the prompt execution. * @return This builder. */ @@ -358,6 +395,7 @@ public class PromptExecutionSettings { /** * Set the stop sequences to use for prompt execution. + * * @param stopSequences The stop sequences to use for prompt execution. * @return This builder. */ @@ -371,8 +409,9 @@ public class PromptExecutionSettings { } /** - * Set the token selection biases to use for prompt execution. The bias values - * are clamped to the range [-100, 100]. + * Set the token selection biases to use for prompt execution. The bias values are clamped + * to the range [-100, 100]. + * * @param tokenSelectionBiases The token selection biases to use for prompt execution. * @return This builder. */ @@ -387,6 +426,7 @@ public class PromptExecutionSettings { /** * Build the PromptExecutionSettings. + * * @return A new PromptExecutionSettings from this builder. */ @SuppressWarnings("unchecked") @@ -394,28 +434,17 @@ public class PromptExecutionSettings { return new PromptExecutionSettings( (String) settings.getOrDefault(SERVICE_ID, ""), (String) settings.getOrDefault(MODEL_ID, ""), - (double) settings.getOrDefault(TEMPERATURE, DEFAULT_TEMPERATURE), - (double) settings.getOrDefault(TOP_P, DEFAULT_TOP_P), - (double) settings.getOrDefault(PRESENCE_PENALTY, DEFAULT_PRESENCE_PENALTY), - (double) settings.getOrDefault(FREQUENCY_PENALTY, DEFAULT_FREQUENCY_PENALTY), - (int) settings.getOrDefault(MAX_TOKENS, DEFAULT_MAX_TOKENS), - (int) settings.getOrDefault(RESULTS_PER_PROMPT, DEFAULT_RESULTS_PER_PROMPT), - (int) settings.getOrDefault(BEST_OF, DEFAULT_BEST_OF), + (Double) settings.getOrDefault(TEMPERATURE, DEFAULT_TEMPERATURE), + (Double) settings.getOrDefault(TOP_P, DEFAULT_TOP_P), + (Double) settings.getOrDefault(PRESENCE_PENALTY, DEFAULT_PRESENCE_PENALTY), + (Double) settings.getOrDefault(FREQUENCY_PENALTY, DEFAULT_FREQUENCY_PENALTY), + (Integer) settings.getOrDefault(MAX_TOKENS, DEFAULT_MAX_TOKENS), + (Integer) settings.getOrDefault(RESULTS_PER_PROMPT, DEFAULT_RESULTS_PER_PROMPT), + (Integer) settings.getOrDefault(BEST_OF, DEFAULT_BEST_OF), (String) settings.getOrDefault(USER, ""), (List) settings.getOrDefault(STOP_SEQUENCES, Collections.emptyList()), (Map) settings.getOrDefault(TOKEN_SELECTION_BIASES, Collections.emptyMap())); } } - - private static double clamp(double value, double min, double max, double defaultValue) { - if (Double.isNaN(value)) { - return defaultValue; - } - return Math.max(min, Math.min(max, value)); - } - - private static int clamp(int value, int min, int max) { - return Math.max(min, Math.min(max, value)); - } } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/ToolCallBehavior.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/ToolCallBehavior.java index 4fd2c7903e..f6709cb532 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/ToolCallBehavior.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/ToolCallBehavior.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.orchestration; import com.microsoft.semantickernel.exceptions.SKException; @@ -13,20 +14,12 @@ public class ToolCallBehavior { private static final int DEFAULT_MAXIMUM_AUTO_INVOKE_ATTEMPTS = 5; private static final String FUNCTION_NAME_SEPARATOR = "-"; - - static String getKey(@Nullable String pluginName, String functionName) { - if (pluginName == null) { - pluginName = ""; - } - return String.format("%s%s%s", pluginName, FUNCTION_NAME_SEPARATOR, functionName); - } - + private final Set enabledFunctions = new HashSet<>(); private int maximumAutoInvokeAttempts; private boolean kernelFunctionsEnabled; @Nullable private KernelFunction requiredFunction; - private final Set enabledFunctions = new HashSet<>(); /** * Create a new instance of ToolCallBehavior with defaults. @@ -49,6 +42,13 @@ public class ToolCallBehavior { enabledFunctions.addAll(toolCallBehavior.enabledFunctions); } + static String getKey(@Nullable String pluginName, String functionName) { + if (pluginName == null) { + pluginName = ""; + } + return String.format("%s%s%s", pluginName, FUNCTION_NAME_SEPARATOR, functionName); + } + /** * Create an unmodifiable copy of this ToolCallBehavior. * @@ -119,28 +119,6 @@ public class ToolCallBehavior { return this; } - /** - * Set the maximum number of times that auto-invocation will be attempted. If auto-invocation is - * enabled, the model may request that the Semantic Kernel invoke functions and return the value - * to the model. If the maximum number of attempts is reached, the model will be notified that - * the function could not be invoked. The default maximum number of attempts is 5. - * - * @param maximumAutoInvokeAttempts The maximum number of attempts. - * @return This ToolCallBehavior. - */ - public ToolCallBehavior setMaximumAutoInvokeAttempts(int maximumAutoInvokeAttempts) { - if (maximumAutoInvokeAttempts < 0) { - throw new SKException( - "The maximum auto-invoke attempts should be greater than or equal to zero."); - } - if (requiredFunction == null) { - this.maximumAutoInvokeAttempts = maximumAutoInvokeAttempts; - } else { - this.maximumAutoInvokeAttempts = Math.min(1, maximumAutoInvokeAttempts); - } - return this; - } - /** * Check whether kernel functions are enabled. * @@ -200,6 +178,28 @@ public class ToolCallBehavior { return this.maximumAutoInvokeAttempts; } + /** + * Set the maximum number of times that auto-invocation will be attempted. If auto-invocation is + * enabled, the model may request that the Semantic Kernel invoke functions and return the value + * to the model. If the maximum number of attempts is reached, the model will be notified that + * the function could not be invoked. The default maximum number of attempts is 5. + * + * @param maximumAutoInvokeAttempts The maximum number of attempts. + * @return This ToolCallBehavior. + */ + public ToolCallBehavior setMaximumAutoInvokeAttempts(int maximumAutoInvokeAttempts) { + if (maximumAutoInvokeAttempts < 0) { + throw new SKException( + "The maximum auto-invoke attempts should be greater than or equal to zero."); + } + if (requiredFunction == null) { + this.maximumAutoInvokeAttempts = maximumAutoInvokeAttempts; + } else { + this.maximumAutoInvokeAttempts = Math.min(1, maximumAutoInvokeAttempts); + } + return this; + } + /** * An unmodifiable instance of ToolCallBehavior. */ diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/KernelPlugin.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/KernelPlugin.java index 3ace22bd99..e234958138 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/KernelPlugin.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/KernelPlugin.java @@ -1,7 +1,8 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.plugin; -import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.contextvariables.CaseInsensitiveMap; +import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import java.util.Collections; import java.util.Iterator; import java.util.Map; @@ -20,9 +21,10 @@ public class KernelPlugin implements Iterable> { /** * Creates a new instance of the {@link KernelPlugin} class. - * @param name The name of the plugin. + * + * @param name The name of the plugin. * @param description The description of the plugin. - * @param plugins The functions in the plugin. + * @param plugins The functions in the plugin. */ public KernelPlugin( String name, @@ -38,6 +40,7 @@ public class KernelPlugin implements Iterable> { /** * Adds a function to the plugin. + * * @param function The function to add. */ public void addFunction(KernelFunction function) { @@ -46,6 +49,7 @@ public class KernelPlugin implements Iterable> { /** * Gets the functions in the plugin. + * * @return The functions in the plugin. */ public Map> getFunctions() { @@ -54,8 +58,9 @@ public class KernelPlugin implements Iterable> { /** * Gets a function by name. + * * @param functionName The name of the function. - * @param The return type of the function. + * @param The return type of the function. * @return The function with the specified name, or {@code null} if no such function exists. */ @Nullable @@ -66,6 +71,7 @@ public class KernelPlugin implements Iterable> { /** * Get an {@code Iterator} that iterates over the functions of this plugin. + * * @return An {@code Iterator} that iterates over the functions of this plugin. */ @Override @@ -75,6 +81,7 @@ public class KernelPlugin implements Iterable> { /** * Gets the name of the plugin. + * * @return The name of the plugin. */ public String getName() { @@ -83,6 +90,7 @@ public class KernelPlugin implements Iterable> { /** * Gets the description of the plugin. + * * @return The description of the plugin. */ @Nullable diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/KernelPluginFactory.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/KernelPluginFactory.java index 1ec977f98b..56787870d4 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/KernelPluginFactory.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/KernelPluginFactory.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.plugin; import com.fasterxml.jackson.databind.ObjectMapper; @@ -33,9 +34,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Factory for creating {@link KernelPlugin} instances. {@code KernelPlugin}s can be - * created from a Java object, from loading a directory of plugins, or from loading plugins - * from a resource. + * Factory for creating {@link KernelPlugin} instances. {@code KernelPlugin}s can be created from a + * Java object, from loading a directory of plugins, or from loading plugins from a resource. */ public class KernelPluginFactory { @@ -44,11 +44,13 @@ public class KernelPluginFactory { private static final String PROMPT_FILE = "skprompt.txt"; /** - * Creates a plugin that wraps the specified target object. Methods decorated with + * Creates a plugin that wraps the specified target object. Methods decorated with * {@code {@literal @}DefineSKFunction} will be included in the plugin. - * - * @param target The instance of the class to be wrapped. - * @param pluginName Name of the plugin for function collection and prompt templates. If the value is {@code null}, a plugin name is derived from the type of the target. + * + * @param target The instance of the class to be wrapped. + * @param pluginName Name of the plugin for function collection and prompt templates. If the + * value is {@code null}, a plugin name is derived from the type of the + * target. * @return The new plugin. */ public static KernelPlugin createFromObject(Object target, String pluginName) { @@ -113,8 +115,9 @@ public class KernelPluginFactory { /** * Creates a plugin from the provided name and function collection. + * * @param pluginName The name for the plugin. - * @param functions The initial functions to be available as part of the plugin. + * @param functions The initial functions to be available as part of the plugin. * @return The new plugin. */ public static KernelPlugin createFromFunctions( @@ -125,9 +128,10 @@ public class KernelPluginFactory { /** * Initializes the new plugin from the provided name, description, and function collection. - * @param pluginName The name for the plugin. + * + * @param pluginName The name for the plugin. * @param description A description of the plugin. - * @param functions The initial functions to be available as part of the plugin. + * @param functions The initial functions to be available as part of the plugin. * @return The new plugin. */ public static KernelPlugin createFromFunctions(String pluginName, @Nullable String description, @@ -159,8 +163,9 @@ public class KernelPluginFactory { * Imports a plugin from a directory. The directory should contain subdirectories, each of which * contains a prompt template and a configuration file. The configuration file should be named * "config.json" and the prompt template should be named "skprompt.txt". - * @param parentDirectory The parent directory containing the plugin directories. - * @param pluginDirectoryName The name of the plugin directory. + * + * @param parentDirectory The parent directory containing the plugin directories. + * @param pluginDirectoryName The name of the plugin directory. * @param promptTemplateFactory The factory to use for creating prompt templates. * @return The imported plugin. */ @@ -238,6 +243,8 @@ public class KernelPluginFactory { String template) { PromptTemplate promptTemplate; + config = config.copy().withTemplate(template).build(); + if (promptTemplateFactory != null) { promptTemplate = promptTemplateFactory.tryCreate(config); } else { @@ -258,15 +265,16 @@ public class KernelPluginFactory { } /** - * Imports a plugin from a resource directory, which may be on the classpath or filesystem. - * The directory should contain subdirectories, each of which - * contains a prompt template and a configuration file. The configuration file should be named - * "config.json" and the prompt template should be named "skprompt.txt". - * @param parentDirectory The parent directory containing the plugin directories. - * @param pluginDirectoryName The name of the plugin directory. - * @param functionName The name of the function to import. + * Imports a plugin from a resource directory, which may be on the classpath or filesystem. The + * directory should contain subdirectories, each of which contains a prompt template and a + * configuration file. The configuration file should be named "config.json" and the prompt + * template should be named "skprompt.txt". + * + * @param parentDirectory The parent directory containing the plugin directories. + * @param pluginDirectoryName The name of the plugin directory. + * @param functionName The name of the function to import. * @param promptTemplateFactory The factory to use for creating prompt templates. - * @param clazz The class to use for loading resources. + * @param clazz The class to use for loading resources. * @return The imported plugin. */ @Nullable diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/KernelReturnParameterMetadata.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/KernelReturnParameterMetadata.java index b76d669fdf..3bd812143a 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/KernelReturnParameterMetadata.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/KernelReturnParameterMetadata.java @@ -1,7 +1,7 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.plugin; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; - import javax.annotation.Nullable; /** @@ -18,7 +18,7 @@ public class KernelReturnParameterMetadata { /** * Creates a new instance of {@link KernelReturnParameterMetadata}. * - * @param description the description of the return parameter + * @param description the description of the return parameter * @param parameterType the type of the return parameter */ public KernelReturnParameterMetadata( diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/Plugin.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/Plugin.java index 50589412c0..b2746ef004 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/Plugin.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/plugin/Plugin.java @@ -17,7 +17,7 @@ public class Plugin { /** * Creates a new instance of {@link Plugin}. * - * @param name the name of the plugin + * @param name the name of the plugin * @param functions the functions of the plugin */ public Plugin(String name, KernelFunction... functions) { @@ -29,7 +29,7 @@ public class Plugin { /** * Creates a new instance of {@link Plugin}. * - * @param name the name of the plugin + * @param name the name of the plugin * @param functions the functions of the plugin */ public Plugin(String name, List> functions) { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/AggregatorPromptTemplateFactory.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/AggregatorPromptTemplateFactory.java index 0c78715260..2c4bf5912d 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/AggregatorPromptTemplateFactory.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/AggregatorPromptTemplateFactory.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import java.util.ArrayList; @@ -5,9 +6,8 @@ import java.util.List; import reactor.util.annotation.NonNull; /** - * An collection of {@link PromptTemplateFactory} instances. The - * factory will try to create a {@link PromptTemplate} using each - * factory in the collection until one is successful. + * An collection of {@link PromptTemplateFactory} instances. The factory will try to create a + * {@link PromptTemplate} using each factory in the collection until one is successful. */ public class AggregatorPromptTemplateFactory implements PromptTemplateFactory { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/HandlebarsPromptTemplateFactory.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/HandlebarsPromptTemplateFactory.java index 8004f8cf1a..f988c13fc4 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/HandlebarsPromptTemplateFactory.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/HandlebarsPromptTemplateFactory.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import com.microsoft.semantickernel.templateengine.handlebars.HandlebarsPromptTemplate; @@ -5,8 +6,8 @@ import java.util.Locale; import reactor.util.annotation.NonNull; /** - * A factory for creating a {@link HandlebarsPromptTemplate} instance for - * a {@code PromptTemplateConfig} that uses the handlebars template format. + * A factory for creating a {@link HandlebarsPromptTemplate} instance for a + * {@code PromptTemplateConfig} that uses the handlebars template format. */ public class HandlebarsPromptTemplateFactory implements PromptTemplateFactory { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/InputConfig.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/InputConfig.java index 16ff4c8af2..34e492e937 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/InputConfig.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/InputConfig.java @@ -6,16 +6,28 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Collections; import java.util.List; -/** Input configuration (list of all input parameters for a semantic function). */ +/** + * Input configuration (list of all input parameters for a semantic function). + */ public class InputConfig { - public final List parameters; + private final List parameters; + /** + * Creates a new instance of the {@link InputConfig} class. + * + * @param parameters the list of input parameters + */ @JsonCreator public InputConfig(@JsonProperty("parameters") List parameters) { this.parameters = Collections.unmodifiableList(parameters); } + /** + * Gets the list of input parameters. + * + * @return the list of input parameters + */ public List getParameters() { return parameters; } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/InputParameter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/InputParameter.java index 6d290ff29d..7dbb23694a 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/InputParameter.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/InputParameter.java @@ -4,13 +4,22 @@ package com.microsoft.semantickernel.semanticfunctions; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -/** Input parameter for semantic functions */ +/** + * Input parameter for semantic functions + */ public class InputParameter { private final String name; private final String description; private final String defaultValue; + /** + * Creates a new instance of the {@link InputParameter} class. + * + * @param name name of the parameter + * @param description description of the parameter + * @param defaultValue default value of the parameter + */ @JsonCreator public InputParameter( @JsonProperty("name") String name, diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/InputVariable.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/InputVariable.java index 14a7d1bd89..dfdb04522b 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/InputVariable.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/InputVariable.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import com.fasterxml.jackson.annotation.JsonCreator; @@ -34,11 +35,11 @@ public class InputVariable { /** * Creates a new instance of {@link InputVariable}. * - * @param name the name of the input variable - * @param type the type of the input variable - * @param description the description of the input variable + * @param name the name of the input variable + * @param type the type of the input variable + * @param description the description of the input variable * @param defaultValue the default value of the input variable - * @param isRequired whether the input variable is required + * @param isRequired whether the input variable is required */ @JsonCreator public InputVariable( @@ -60,6 +61,7 @@ public class InputVariable { /** * Gets the name of the input variable. + * * @return the name of the input variable */ public String getName() { @@ -68,6 +70,7 @@ public class InputVariable { /** * Gets the type of the input variable. + * * @return the type of the input variable */ public String getType() { @@ -76,6 +79,7 @@ public class InputVariable { /** * Gets the description of the input variable. + * * @return the description of the input variable */ @Nullable @@ -85,6 +89,7 @@ public class InputVariable { /** * Gets the default value of the input variable. + * * @return the default value of the input variable */ @Nullable @@ -94,6 +99,7 @@ public class InputVariable { /** * Gets whether the input variable is required. + * * @return whether the input variable is required */ public boolean isRequired() { @@ -102,6 +108,7 @@ public class InputVariable { /** * Gets the class of the type of the input variable. + * * @return the class of the type of the input variable */ public Class getTypeClass() { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunction.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunction.java index 5a0c500324..f3fcf4b29b 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunction.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunction.java @@ -27,7 +27,7 @@ import reactor.core.publisher.Mono; * @param The type of the result of the function * @see com.microsoft.semantickernel.semanticfunctions * @see com.microsoft.semantickernel.plugin - * @see com.microsoft.semantickernel.plugin.annotations + * @see com.microsoft.semantickernel.semanticfunctions.annotations */ public abstract class KernelFunction implements Buildable { @@ -54,6 +54,51 @@ public abstract class KernelFunction implements Buildable { } } + /** + * Creates a {@link KernelFunction} instance for a method, specified via a {@link Method} + * instance + * + * @param The return type of the method. + * @param method The method to be represented via the created {@link KernelFunction}. + * @param target The target object for the {@code method} if it represents an instance method. + * This should be {@code null} if and only if {@code method} is a static method. + * @return The created {@link KernelFunction} wrapper for {@code method}. + */ + + public static KernelFunctionFromMethod.Builder createFromMethod( + Method method, + Object target) { + return KernelFunctionFromMethod.builder() + .withMethod(method) + .withTarget(target); + } + + /** + * Creates a {@link KernelFunction} instance based on a given prompt + * + * @param prompt The prompt to be used for the created {@link KernelFunction}. + * @param The return type of the method + * @return The builder for creating a {@link KernelFunction} instance. + */ + public static FromPromptBuilder createFromPrompt(String prompt) { + return KernelFunctionFromPrompt.builder() + .withTemplate(prompt); + } + + /** + * Builder for creating a {@link KernelFunction} instance for a given + * {@link PromptTemplateConfig}. + * + * @param promptTemplateConfiguration The configuration for the prompt template. + * @param The return type of the method + * @return The builder for creating a {@link KernelFunction} instance. + */ + public static FromPromptBuilder createFromPrompt( + PromptTemplateConfig promptTemplateConfiguration) { + return KernelFunctionFromPrompt.builder() + .withPromptTemplateConfig(promptTemplateConfiguration); + } + /** * @return The name of the plugin that this function is within */ @@ -127,9 +172,9 @@ public abstract class KernelFunction implements Buildable { * {@link ToolCallBehavior}. *

* The difference between calling the {@code KernelFunction.invokeAsync} method directly and - * calling the {@code Kernel.invokeAsync} method is that the latter adds the - * {@link KernelHooks#getHooks()} global KernelHooks} (if any) to the {@link InvocationContext}. - * Calling {@code KernelFunction.invokeAsync} directly does not add the global hooks. + * calling the {@code Kernel.invokeAsync} method is that the latter adds the global KernelHooks + * (if any) to the {@link InvocationContext}. Calling {@code KernelFunction.invokeAsync} + * directly does not add the global hooks. * * @param kernel The Kernel containing services, plugins, and other state for use * throughout the operation. @@ -157,51 +202,6 @@ public abstract class KernelFunction implements Buildable { return new FunctionInvocation<>(kernel, this); } - /** - * Creates a {@link KernelFunction} instance for a method, specified via a {@link Method} - * instance - * - * @param The return type of the method. - * @param method The method to be represented via the created {@link KernelFunction}. - * @param target The target object for the {@code method} if it represents an instance method. - * This should be {@code null} if and only if {@code method} is a static method. - * @return The created {@link KernelFunction} wrapper for {@code method}. - */ - - public static KernelFunctionFromMethod.Builder createFromMethod( - Method method, - Object target) { - return KernelFunctionFromMethod.builder() - .withMethod(method) - .withTarget(target); - } - - /** - * Creates a {@link KernelFunction} instance based on a given prompt - * - * @param prompt The prompt to be used for the created {@link KernelFunction}. - * @param The return type of the method - * @return The builder for creating a {@link KernelFunction} instance. - */ - public static FromPromptBuilder createFromPrompt(String prompt) { - return KernelFunctionFromPrompt.builder() - .withTemplate(prompt); - } - - /** - * Builder for creating a {@link KernelFunction} instance for a given - * {@link PromptTemplateConfig}. - * - * @param promptTemplateConfiguration The configuration for the prompt template. - * @param The return type of the method - * @return The builder for creating a {@link KernelFunction} instance. - */ - public static FromPromptBuilder createFromPrompt( - PromptTemplateConfig promptTemplateConfiguration) { - return KernelFunctionFromPrompt.builder() - .withPromptTemplateConfig(promptTemplateConfiguration); - } - /** * Builder for creating a {@link KernelFunction} from a prompt. * diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionArguments.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionArguments.java index 0bde8308d6..99d26764df 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionArguments.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionArguments.java @@ -3,11 +3,11 @@ package com.microsoft.semantickernel.semanticfunctions; import com.microsoft.semantickernel.builders.Buildable; import com.microsoft.semantickernel.builders.SemanticKernelBuilder; -import com.microsoft.semantickernel.exceptions.SKException; import com.microsoft.semantickernel.contextvariables.CaseInsensitiveMap; import com.microsoft.semantickernel.contextvariables.ContextVariable; import com.microsoft.semantickernel.contextvariables.ContextVariableType; import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; +import com.microsoft.semantickernel.exceptions.SKException; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -16,7 +16,7 @@ import javax.annotation.Nullable; import reactor.util.annotation.NonNull; /** - * Arguments to a kernel function. + * Arguments to a kernel function. */ public class KernelFunctionArguments implements Buildable, Map> { @@ -58,6 +58,15 @@ public class KernelFunctionArguments implements Buildable, Map(); } + /** + * Create a new instance of Builder. + * + * @return Builder + */ + public static Builder builder() { + return new KernelFunctionArguments.Builder(); + } + /** * Get the input (entry in the MAIN_KEY slot) * @@ -119,6 +128,7 @@ public class KernelFunctionArguments implements Buildable, Map Type of the value + * @param Type of the value * @return {$code this} Builder for fluent coding */ public Builder withInput(ContextVariable content) { @@ -266,7 +267,7 @@ public class KernelFunctionArguments implements Buildable, Map Type of the value + * @param Type of the value * @return {$code this} Builder for fluent coding */ public Builder withVariable(String key, ContextVariable value) { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionFactory.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionFactory.java deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionFromMethod.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionFromMethod.java index 9b7059f137..d7b356d3ab 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionFromMethod.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionFromMethod.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import static com.microsoft.semantickernel.semanticfunctions.annotations.KernelFunctionParameter.NO_DEFAULT_VALUE; @@ -19,9 +20,11 @@ import com.microsoft.semantickernel.orchestration.InvocationContext; import com.microsoft.semantickernel.plugin.KernelReturnParameterMetadata; import com.microsoft.semantickernel.semanticfunctions.annotations.DefineKernelFunction; import com.microsoft.semantickernel.semanticfunctions.annotations.KernelFunctionParameter; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Parameter; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.function.Function; @@ -65,41 +68,6 @@ public class KernelFunctionFromMethod extends KernelFunction implements Bu this.function = implementationFunc; } - /** - * Concrete implementation of the abstract method in KernelFunction. {@inheritDoc} - */ - @Override - public Mono> invokeAsync( - Kernel kernel, - @Nullable KernelFunctionArguments arguments, - @Nullable ContextVariableType variableType, - @Nullable InvocationContext invocationContext) { - return function.invoke(kernel, this, arguments, variableType, invocationContext); - } - - /** - * Concrete implementation of the abstract method in KernelFunction. - */ - public interface ImplementationFunc { - - /** - * Invokes the function. - * - * @param kernel the kernel to invoke the function on - * @param function the function to invoke - * @param arguments the arguments to the function - * @param variableType the variable type of the function - * @param invocationContext the invocation context - * @return a {@link Mono} that emits the result of the function invocation - */ - Mono> invoke( - Kernel kernel, - KernelFunction function, - @Nullable KernelFunctionArguments arguments, - @Nullable ContextVariableType variableType, - @Nullable InvocationContext invocationContext); - } - /** * Creates a new instance of {@link KernelFunctionFromMethod} from a method. * @@ -292,7 +260,7 @@ public class KernelFunctionFromMethod extends KernelFunction implements Bu return type; } catch (ClassCastException | SKException e) { // SKException is thrown from ContextVariableTypes.getDefaultVariableTypeForClass - // if there is no default variable type for the class. + // if there is no default variable type for the class. // Fallthrough. Let the caller handle a null return. } } @@ -576,10 +544,54 @@ public class KernelFunctionFromMethod extends KernelFunction implements Bu isRequired); } + /** + * A builder for {@link KernelFunction}. + * + * @param the return type of the function + * @return a new instance of {@link Builder} + */ public static Builder builder() { return new Builder<>(); } + /** + * Concrete implementation of the abstract method in KernelFunction. {@inheritDoc} + */ + @Override + public Mono> invokeAsync( + Kernel kernel, + @Nullable KernelFunctionArguments arguments, + @Nullable ContextVariableType variableType, + @Nullable InvocationContext invocationContext) { + return function.invoke(kernel, this, arguments, variableType, invocationContext); + } + + /** + * Concrete implementation of the abstract method in KernelFunction. + */ + public interface ImplementationFunc { + + /** + * Invokes the function. + * + * @param kernel the kernel to invoke the function on + * @param function the function to invoke + * @param arguments the arguments to the function + * @param variableType the variable type of the function + * @param invocationContext the invocation context + * @return a {@link Mono} that emits the result of the function invocation + */ + Mono> invoke( + Kernel kernel, + KernelFunction function, + @Nullable KernelFunctionArguments arguments, + @Nullable ContextVariableType variableType, + @Nullable InvocationContext invocationContext); + } + + /** + * A builder for {@link KernelFunction}. + */ public static class Builder { @Nullable @@ -597,41 +609,89 @@ public class KernelFunctionFromMethod extends KernelFunction implements Bu @Nullable private KernelReturnParameterMetadata returnParameter; + /** + * Sets the method to use to build the function. + * + * @param method the method to use + * @return this instance of the {@link Builder} class + */ + @SuppressFBWarnings("EI_EXPOSE_REP2") public Builder withMethod(Method method) { this.method = method; return this; } + /** + * Sets the target to use to build the function. + * + * @param target the target to use + * @return this instance of the {@link Builder} class + */ public Builder withTarget(Object target) { this.target = target; return this; } + /** + * Sets the plugin name to use to build the function. + * + * @param pluginName the plugin name to use + * @return this instance of the {@link Builder} class + */ public Builder withPluginName(String pluginName) { this.pluginName = pluginName; return this; } + /** + * Sets the function name to use to build the function. + * + * @param functionName the function name to use + * @return this instance of the {@link Builder} class + */ public Builder withFunctionName(String functionName) { this.functionName = functionName; return this; } + /** + * Sets the description to use to build the function. + * + * @param description the description to use + * @return this instance of the {@link Builder} class + */ public Builder withDescription(String description) { this.description = description; return this; } + /** + * Sets the parameters to use to build the function. + * + * @param parameters the parameters to use + * @return this instance of the {@link Builder} class + */ public Builder withParameters(List> parameters) { - this.parameters = parameters; + this.parameters = new ArrayList<>(parameters); return this; } + /** + * Sets the return parameter to use to build the function. + * + * @param returnParameter the return parameter to use + * @return this instance of the {@link Builder} class + */ public Builder withReturnParameter(KernelReturnParameterMetadata returnParameter) { this.returnParameter = returnParameter; return this; } + /** + * Builds a new instance of {@link KernelFunction}. + * + * @return a new instance of {@link KernelFunction} + */ public KernelFunction build() { if (method == null) { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionFromPrompt.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionFromPrompt.java index c7435066e7..aeec1ca6eb 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionFromPrompt.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionFromPrompt.java @@ -1,10 +1,10 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import com.azure.core.exception.HttpResponseException; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.services.TextAIService; -import com.microsoft.semantickernel.services.chatcompletion.AuthorRole; -import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; +import com.microsoft.semantickernel.contextvariables.ContextVariable; +import com.microsoft.semantickernel.contextvariables.ContextVariableType; import com.microsoft.semantickernel.hooks.FunctionInvokedEvent; import com.microsoft.semantickernel.hooks.FunctionInvokingEvent; import com.microsoft.semantickernel.hooks.KernelHooks; @@ -13,10 +13,11 @@ import com.microsoft.semantickernel.hooks.PromptRenderingEvent; import com.microsoft.semantickernel.orchestration.FunctionResult; import com.microsoft.semantickernel.orchestration.InvocationContext; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; -import com.microsoft.semantickernel.contextvariables.ContextVariable; -import com.microsoft.semantickernel.contextvariables.ContextVariableType; import com.microsoft.semantickernel.services.AIService; import com.microsoft.semantickernel.services.AIServiceSelection; +import com.microsoft.semantickernel.services.TextAIService; +import com.microsoft.semantickernel.services.chatcompletion.AuthorRole; +import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService; import com.microsoft.semantickernel.services.textcompletion.TextGenerationService; import java.util.ArrayList; import java.util.HashMap; @@ -71,57 +72,13 @@ public class KernelFunctionFromPrompt extends KernelFunction { } /** - * Creates a new instance of {@link KernelFunctionFromPrompt} from a - * {@code PromptTemplateConfig}. + * Creates a new instance of {@link Builder}. * - * @param promptConfig the configuration for the prompt - * @param the type of the return value of the function - * @return a new instance of {@link KernelFunction} + * @param The type of the return value of the function + * @return a new instance of {@link Builder} */ - public static KernelFunction create( - PromptTemplateConfig promptConfig) { - return create( - promptConfig, - null); - } - - /** - * Creates a new instance of {@link KernelFunctionFromPrompt} from a - * {@code PromptTemplateConfig}, using the {@code PropmptTemplateFactory} to create the prompt - * template. If {@code promptTemplateFactory} is {@code null}, a default factory will be used. - * - * @param promptConfig the configuration for the prompt - * @param promptTemplateFactory the prompt template factory to use for creating the prompt - * template - * @param the type of the return value of the function - * @return a new instance of {@link KernelFunction} - */ - public static KernelFunction create( - PromptTemplateConfig promptConfig, - @Nullable PromptTemplateFactory promptTemplateFactory) { - if (promptTemplateFactory == null) { - promptTemplateFactory = new KernelPromptTemplateFactory(); - } - - return create(promptTemplateFactory.tryCreate(promptConfig), promptConfig); - } - - /** - * Creates a new instance of {@link KernelFunctionFromPrompt} from a - * {@code PromptTemplateConfig}, using the provided prompt template. - * - * @param promptTemplate the prompt template to use for the function - * @param promptConfig the configuration for the prompt - * @param the type of the return value of the function - * @return a new instance of {@link KernelFunction} - */ - public static KernelFunction create( - PromptTemplate promptTemplate, - PromptTemplateConfig promptConfig) { - return new KernelFunctionFromPrompt<>( - promptTemplate, - promptConfig, - null); + public static Builder builder() { + return new Builder<>(); } private Flux> invokeInternalAsync( @@ -298,68 +255,10 @@ public class KernelFunctionFromPrompt extends KernelFunction { @Nullable KernelFunctionArguments arguments, @Nullable ContextVariableType variableType, @Nullable InvocationContext invocationContext) { - return invokeInternalAsync(kernel, arguments, variableType, invocationContext) .take(1).single(); } - public static KernelFunction create( - String promptTemplate) { - return create(promptTemplate, null, null, null, null, null); - } - - /** - * Creates a {@link KernelFunction} instance for a prompt specified via a prompt template. If - * any of the optional parameters are {@code null}, default values will be used. - * - * @param promptTemplate the prompt template for the function - * @param executionSettings the default execution settings to use when invoking this prompt - * function - * @param functionName the name of the function - * @param description the description of the function - * @param templateFormat the format of the template - * @param promptTemplateFactory the prompt template factory to use for creating the prompt - * template - * @param the type of the return value of the function - * @return a new instance of {@link KernelFunction} - */ - @SuppressWarnings("unchecked") - public static KernelFunction create( - String promptTemplate, - @Nullable Map executionSettings, - @Nullable String functionName, - @Nullable String description, - @Nullable String templateFormat, - @Nullable PromptTemplateFactory promptTemplateFactory) { - - if (templateFormat == null) { - templateFormat = PromptTemplateConfig.SEMANTIC_KERNEL_TEMPLATE_FORMAT; - } - - if (functionName == null) { - functionName = UUID.randomUUID().toString(); - } - - return (KernelFunction) new KernelFunctionFromPrompt.Builder<>() - .withName(functionName) - .withDescription(description) - .withPromptTemplateFactory(promptTemplateFactory) - .withTemplate(promptTemplate) - .withTemplateFormat(templateFormat) - .withExecutionSettings(executionSettings) - .build(); - } - - /** - * Creates a new instance of {@link Builder}. - * - * @param The type of the return value of the function - * @return a new instance of {@link Builder} - */ - public static Builder builder() { - return new Builder<>(); - } - /** * A builder for creating a {@link KernelFunction} from a prompt template. * @@ -511,10 +410,6 @@ public class KernelFunctionFromPrompt extends KernelFunction { executionSettings); } - if (template == null) { - throw new IllegalStateException("Template must be provided"); - } - PromptTemplateConfig config = new PromptTemplateConfig( name, template, @@ -527,8 +422,6 @@ public class KernelFunctionFromPrompt extends KernelFunction { PromptTemplate temp; if (promptTemplate != null) { temp = promptTemplate; - } else if (promptTemplateFactory != null) { - temp = promptTemplateFactory.tryCreate(config); } else { temp = new KernelPromptTemplateFactory().tryCreate(config); } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionMetadata.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionMetadata.java index 9cd9ac6871..52d15b11e1 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionMetadata.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionMetadata.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import com.microsoft.semantickernel.plugin.KernelReturnParameterMetadata; @@ -24,10 +25,10 @@ public class KernelFunctionMetadata { /** * Create a new instance of KernelFunctionMetadata. * - * @param pluginName The name of the plugin to which the function belongs - * @param name The name of the function. - * @param description The description of the function. - * @param parameters The parameters of the function. + * @param pluginName The name of the plugin to which the function belongs + * @param name The name of the function. + * @param description The description of the function. + * @param parameters The parameters of the function. * @param returnParameter The return parameter of the function. */ public KernelFunctionMetadata( @@ -50,6 +51,7 @@ public class KernelFunctionMetadata { /** * Get the name of the plugin to which the function belongs + * * @return The name of the function. */ @Nullable @@ -59,6 +61,7 @@ public class KernelFunctionMetadata { /** * Get the name of the function. + * * @return The name of the function. */ public String getName() { @@ -67,6 +70,7 @@ public class KernelFunctionMetadata { /** * Get the parameters of the function. + * * @return The parameters of the function. */ public List> getParameters() { @@ -75,6 +79,7 @@ public class KernelFunctionMetadata { /** * Get the description of the function. + * * @return The description of the function. */ @Nullable @@ -84,6 +89,7 @@ public class KernelFunctionMetadata { /** * Get the return parameter of the function. + * * @return The return parameter of the function. */ public KernelReturnParameterMetadata getReturnParameter() { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionYaml.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionYaml.java index 0776575102..0e14fb7073 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionYaml.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionYaml.java @@ -1,13 +1,8 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.microsoft.semantickernel.semanticfunctions.KernelFunction; -import com.microsoft.semantickernel.semanticfunctions.KernelFunctionFromPrompt; -import com.microsoft.semantickernel.semanticfunctions.PromptTemplate; -import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig; -import com.microsoft.semantickernel.semanticfunctions.PromptTemplateFactory; -import com.microsoft.semantickernel.templateengine.handlebars.HandlebarsPromptTemplate; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -16,15 +11,18 @@ import java.nio.file.Path; import javax.annotation.Nullable; /** - * A class for creating a {@link KernelFunction} instance from a YAML representation of a prompt function. + * A class for creating a {@link KernelFunction} instance from a YAML representation of a prompt + * function. */ public class KernelFunctionYaml { /** * Create a KernelFunction instance for a prompt function using the specified markdown text. - * @param yaml YAML representation of the PromptTemplateConfig to use to create the prompt function + * + * @param yaml YAML representation of the PromptTemplateConfig to use to create + * the prompt function * @param promptTemplateFactory Prompt template factory. - * @param The return type of the function. + * @param The return type of the function. * @return The created KernelFunction. * @throws IOException If an error occurs while reading the YAML. */ @@ -37,8 +35,10 @@ public class KernelFunctionYaml { /** * Create a KernelFunction instance for a prompt function using the specified markdown text. - * @param yaml YAML representation of the PromptTemplateConfig to use to create the prompt function - * @param The return type of the function. + * + * @param yaml YAML representation of the PromptTemplateConfig to use to create the prompt + * function + * @param The return type of the function. * @return The created KernelFunction. * @throws IOException If an error occurs while reading the YAML. */ @@ -50,8 +50,10 @@ public class KernelFunctionYaml { /** * Create a KernelFunction instance for a prompt function using the specified markdown text. - * @param filePath Path to the YAML representation of the PromptTemplateConfig to use to create the prompt function - * @param The return type of the function. + * + * @param filePath Path to the YAML representation of the PromptTemplateConfig to use to create + * the prompt function + * @param The return type of the function. * @return The created KernelFunction. * @throws IOException If an error occurs while reading the YAML. */ @@ -71,7 +73,7 @@ public class KernelFunctionYaml { PromptTemplate promptTemplate; if (promptTemplateFactory == null) { - promptTemplate = new HandlebarsPromptTemplate(functionModel); + promptTemplate = PromptTemplateFactory.build(functionModel); } else { promptTemplate = promptTemplateFactory.tryCreate(functionModel); } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelParameterMetadata.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelParameterMetadata.java index 1139f7517f..c04bf38748 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelParameterMetadata.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelParameterMetadata.java @@ -1,11 +1,12 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import javax.annotation.Nullable; /** - * Metadata for a parameter to a kernel function. The Semantic Kernel creates - * this metadata from the annotations on the method that defines the function, - * or by introspection of a Java method. + * Metadata for a parameter to a kernel function. The Semantic Kernel creates this metadata from the + * annotations on the method that defines the function, or by introspection of a Java method. + * * @param The type of the parameter. */ public class KernelParameterMetadata { @@ -20,11 +21,12 @@ public class KernelParameterMetadata { /** * Creates a new instance of the {@link KernelParameterMetadata} class. - * @param name The name of the parameter. - * @param description The description of the parameter. + * + * @param name The name of the parameter. + * @param description The description of the parameter. * @param parameterType The type of the parameter. - * @param defaultValue The default value of the parameter. - * @param isRequired Whether the parameter is required. + * @param defaultValue The default value of the parameter. + * @param isRequired Whether the parameter is required. */ public KernelParameterMetadata( String name, @@ -41,6 +43,7 @@ public class KernelParameterMetadata { /** * Gets the name of the parameter. + * * @return The name of the parameter. */ public String getName() { @@ -49,6 +52,7 @@ public class KernelParameterMetadata { /** * Gets the description of the parameter. + * * @return The description of the parameter. */ @Nullable @@ -58,6 +62,7 @@ public class KernelParameterMetadata { /** * Gets the default value of the parameter. + * * @return The default value of the parameter. */ @Nullable @@ -67,6 +72,7 @@ public class KernelParameterMetadata { /** * Gets whether the parameter is required. + * * @return Whether the parameter is required. */ public boolean isRequired() { @@ -75,6 +81,7 @@ public class KernelParameterMetadata { /** * Gets the type of the parameter. + * * @return The type of the parameter. */ public Class getType() { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelPromptTemplateFactory.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelPromptTemplateFactory.java index 4fc33024c7..b10c6fb93d 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelPromptTemplateFactory.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelPromptTemplateFactory.java @@ -1,24 +1,32 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import static com.microsoft.semantickernel.semanticfunctions.HandlebarsPromptTemplateFactory.HANDLEBARS_TEMPLATE_FORMAT; import static com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig.SEMANTIC_KERNEL_TEMPLATE_FORMAT; +import com.microsoft.semantickernel.exceptions.SKException; import com.microsoft.semantickernel.implementation.templateengine.tokenizer.DefaultPromptTemplate; import com.microsoft.semantickernel.templateengine.handlebars.HandlebarsPromptTemplate; import java.util.Locale; import javax.annotation.Nonnull; /** - * Factory for creating prompt templates. This factory creates the appropriate - * prompt template based on the template format. + * Factory for creating prompt templates. This factory creates the appropriate prompt template based + * on the template format. */ public class KernelPromptTemplateFactory implements PromptTemplateFactory { @Override public PromptTemplate tryCreate(@Nonnull PromptTemplateConfig templateConfig) { + if (templateConfig.getTemplate() == null) { + throw new SKException( + String.format("No prompt template was provided for the prompt %s.", + templateConfig.getName())); + } + switch (templateConfig.getTemplateFormat().toLowerCase(Locale.ROOT)) { case SEMANTIC_KERNEL_TEMPLATE_FORMAT: - return new DefaultPromptTemplate(templateConfig); + return DefaultPromptTemplate.build(templateConfig); case HANDLEBARS_TEMPLATE_FORMAT: return new HandlebarsPromptTemplate(templateConfig); default: diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/MethodDetails.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/MethodDetails.java index bdc391b61a..f7dc9aa9f3 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/MethodDetails.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/MethodDetails.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import com.microsoft.semantickernel.plugin.KernelReturnParameterMetadata; @@ -43,6 +44,7 @@ public class MethodDetails { /** * Get the name of the method. + * * @return The name of the method. */ public String getName() { @@ -51,6 +53,7 @@ public class MethodDetails { /** * Get the description of the method. + * * @return The description of the method. */ @Nullable @@ -60,6 +63,7 @@ public class MethodDetails { /** * Get the function that implements the method. This is an internal detail. + * * @return The function that implements the method. */ public ImplementationFunc getFunction() { @@ -68,6 +72,7 @@ public class MethodDetails { /** * Get the parameters of the method. + * * @return The parameters of the method. */ public List> getParameters() { @@ -76,6 +81,7 @@ public class MethodDetails { /** * Get the return parameter of the method. + * * @return The return parameter of the method. */ public KernelReturnParameterMetadata getReturnParameter() { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/OutputVariable.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/OutputVariable.java index a7c418b26c..b67f3be851 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/OutputVariable.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/OutputVariable.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import com.fasterxml.jackson.annotation.JsonCreator; @@ -25,13 +26,17 @@ public class OutputVariable { public OutputVariable( @Nullable @JsonProperty("description") String description, - @JsonProperty("type") String type) { + @Nullable @JsonProperty(value = "type", defaultValue = "java.lang.String") String type) { this.description = description; + if (type == null || type.isEmpty()) { + type = "java.lang.String"; + } this.type = type; } /** * Get the description of the output variable. + * * @return The description of the output variable. */ @Nullable @@ -41,6 +46,7 @@ public class OutputVariable { /** * Get the type of the output variable. + * * @return The type of the output variable. */ public Class getType() { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplate.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplate.java index 3c20cb0560..683daaccc1 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplate.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplate.java @@ -13,10 +13,14 @@ import reactor.core.publisher.Mono; public interface PromptTemplate extends Buildable { /** - * Renders the template using the supplied {@code Kernel}, {@code KernelFunctionArguments}, and {@code InvocationContext}. - * @param kernel The {@link Kernel} containing services, plugins, and other state for use throughout the operation. + * Renders the template using the supplied {@code Kernel}, {@code KernelFunctionArguments}, and + * {@code InvocationContext}. + * + * @param kernel The {@link Kernel} containing services, plugins, and other state for use + * throughout the operation. * @param arguments The arguments to use to satisfy any input variables in the prompt template. - * @param context The {@link InvocationContext} which carries optional information for the prompt rendering. + * @param context The {@link InvocationContext} which carries optional information for the + * prompt rendering. * @return The rendered prompt. */ Mono renderAsync( diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplateConfig.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplateConfig.java index 4c46939fe7..fcde2da7aa 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplateConfig.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplateConfig.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.microsoft.semantickernel.builders.Buildable; import com.microsoft.semantickernel.exceptions.SKException; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; import com.microsoft.semantickernel.plugin.KernelReturnParameterMetadata; @@ -21,7 +22,7 @@ import javax.annotation.Nullable; * Metadata for a prompt template. */ @JsonIgnoreProperties(ignoreUnknown = true) -public class PromptTemplateConfig { +public class PromptTemplateConfig implements Buildable { /** * The current prompt template config schema version. @@ -39,15 +40,16 @@ public class PromptTemplateConfig { public static final String SEMANTIC_KERNEL_TEMPLATE_FORMAT = "semantic-kernel"; @Nullable - private String name; - private String template; - private String templateFormat; + private final String name; @Nullable - private String description; - private List inputVariables; + private final String template; + private final String templateFormat; @Nullable - private OutputVariable outputVariable; - private Map executionSettings; + private final String description; + private final List inputVariables; + @Nullable + private final OutputVariable outputVariable; + private final Map executionSettings; /** * Constructor for a prompt template config @@ -69,20 +71,20 @@ public class PromptTemplateConfig { /** * Constructor for a prompt template config * - * @param schema Schema version - * @param name Name of the template - * @param template Template string - * @param templateFormat Template format - * @param description Description of the template - * @param inputVariables Input variables - * @param outputVariable Output variable + * @param schema Schema version + * @param name Name of the template + * @param template Template string + * @param templateFormat Template format + * @param description Description of the template + * @param inputVariables Input variables + * @param outputVariable Output variable * @param executionSettings Execution settings */ @JsonCreator public PromptTemplateConfig( @JsonProperty("schema") int schema, @Nullable @JsonProperty("name") String name, - @JsonProperty("template") String template, + @Nullable @JsonProperty("template") String template, @Nullable @JsonProperty(value = "template_format", defaultValue = SEMANTIC_KERNEL_TEMPLATE_FORMAT) String templateFormat, @Nullable @JsonProperty("description") String description, @Nullable @JsonProperty("input_variables") List inputVariables, @@ -121,7 +123,7 @@ public class PromptTemplateConfig { */ public PromptTemplateConfig( @Nullable String name, - String template, + @Nullable String template, @Nullable String templateFormat, @Nullable String description, @Nullable List inputVariables, @@ -154,6 +156,41 @@ public class PromptTemplateConfig { promptTemplate.executionSettings); } + /** + * Deserialize the JSON string to a PromptTemplateConfig. + * + * @param json The JSON string to parse + * @return The PromptTemplateConfig object + * @throws SKException If the prompt template config cannot be deserialized. + */ + public static PromptTemplateConfig parseFromJson(String json) throws SKException { + try { + return new ObjectMapper().readValue(json, PromptTemplateConfig.class); + } catch (JsonProcessingException e) { + throw new SKException("Unable to parse prompt template config", e); + } + } + + /** + * Create a builder for a prompt template config. + * + * @return The prompt template config builder. + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Create a builder for a prompt template config, where the constructed template will be + * considered the default to be used if no other config is selected. + * + * @return The default prompt template config. + */ + public static Builder defaultTemplateBuilder() { + return new Builder() + .withName(DEFAULT_CONFIG_NAME); + } + /** * Get the parameters metadata. * @@ -188,19 +225,9 @@ public class PromptTemplateConfig { outputVariable.getType()); } - /** - * Add an input variable to the prompt template config. - * - * @param inputVariable The input variable to add. - * @return {@code this} prompt template config. - */ - public PromptTemplateConfig addInputVariable(InputVariable inputVariable) { - inputVariables.add(inputVariable); - return this; - } - /** * Get the name of the prompt template config. + * * @return The name of the prompt template config. */ @Nullable @@ -208,54 +235,19 @@ public class PromptTemplateConfig { return name; } - /** - * Set the name of the prompt template config. - * @param name The name of the prompt template config. - * @return {@code this} prompt template config. - */ - public PromptTemplateConfig setName(String name) { - this.name = name; - return this; - } - /** * Get the template of the prompt template config. + * * @return The template of the prompt template config. */ + @Nullable public String getTemplate() { return template; } - /** - * Set the template of the prompt template config. - * @param template The template of the prompt template config. - * @return {@code this} prompt template config. - */ - public PromptTemplateConfig setTemplate(String template) { - this.template = template; - return this; - } - - /** - * Get the template format of the prompt template config. - * @return The template format of the prompt template config. - */ - public String getTemplateFormat() { - return templateFormat; - } - - /** - * Set the template format of the prompt template config. - * @param templateFormat The template format of the prompt template config. - * @return {@code this} prompt template config. - */ - public PromptTemplateConfig setTemplateFormat(String templateFormat) { - this.templateFormat = templateFormat; - return this; - } - /** * Get the description of the prompt template config. + * * @return The description of the prompt template config. */ @Nullable @@ -263,36 +255,18 @@ public class PromptTemplateConfig { return description; } - /** - * Set the description of the prompt template config. - * @param description The description of the prompt template config. - * @return {@code this} prompt template config. - */ - public PromptTemplateConfig setDescription(String description) { - this.description = description; - return this; - } - /** * Get the inputVariables of the prompt template config. + * * @return The input variables of the prompt template config. */ public List getInputVariables() { return Collections.unmodifiableList(inputVariables); } - /** - * Set the inputVariables of the prompt template config. - * @param inputVariables The input variables of the prompt template config. - * @return {@code this} prompt template config. - */ - public PromptTemplateConfig setInputVariables(List inputVariables) { - this.inputVariables = new ArrayList<>(inputVariables); - return this; - } - /** * Get the output variable of the prompt template config. + * * @return The output variable of the prompt template config. */ @Nullable @@ -300,18 +274,9 @@ public class PromptTemplateConfig { return outputVariable; } - /** - * Set the output variable of the prompt template config. - * @param outputVariable The output variable of the prompt template config. - * @return {@code this} prompt template config. - */ - public PromptTemplateConfig setOutputVariable(OutputVariable outputVariable) { - this.outputVariable = outputVariable; - return this; - } - /** * Get the prompt execution settings of the prompt template config. + * * @return The prompt execution settings of the prompt template config. */ @Nullable @@ -323,28 +288,156 @@ public class PromptTemplateConfig { } /** - * Set the prompt execution settings of the prompt template config. - * @param executionSettings The prompt execution settings of the prompt template config. - * @return {@code this} prompt template config. + * Get the template format of the prompt template config. + * + * @return The template format of the prompt template config. */ - public PromptTemplateConfig setExecutionSettings( - Map executionSettings) { - this.executionSettings = new HashMap<>(executionSettings); - return this; + public String getTemplateFormat() { + return templateFormat; } /** - * Deserialize the JSON string to a PromptTemplateConfig. - * @param json The JSON string to parse - * @return The PromptTemplateConfig object - * @throws SKException If the prompt template config cannot be deserialized. + * Create a builder for a prompt template config which is a clone of the current object. + * + * @return The prompt template config builder. */ - public static PromptTemplateConfig parseFromJson(String json) throws SKException { - try { - return new ObjectMapper().readValue(json, PromptTemplateConfig.class); - } catch (JsonProcessingException e) { - throw new SKException("Unable to parse prompt template config", e); - } + public Builder copy() { + return new Builder(this); } + /** + * Builder for a prompt template config. + */ + public static class Builder { + + @Nullable + private String name; + @Nullable + private String template; + private String templateFormat = SEMANTIC_KERNEL_TEMPLATE_FORMAT; + @Nullable + private String description = null; + private List inputVariables = new ArrayList<>(); + @Nullable + private OutputVariable outputVariable = new OutputVariable("out", String.class.getName()); + private Map executionSettings = new HashMap<>(); + + private Builder() { + } + + private Builder(PromptTemplateConfig promptTemplateConfig) { + this.name = promptTemplateConfig.name; + this.template = promptTemplateConfig.template; + this.templateFormat = promptTemplateConfig.templateFormat; + this.description = promptTemplateConfig.description; + this.inputVariables = new ArrayList<>(promptTemplateConfig.inputVariables); + this.outputVariable = promptTemplateConfig.outputVariable; + this.executionSettings = new HashMap<>(promptTemplateConfig.executionSettings); + } + + /** + * Set the name of the prompt template config. + * + * @param name The name of the prompt template config. + * @return {@code this} prompt template config. + */ + public Builder withName(String name) { + this.name = name; + return this; + } + + /** + * Add an input variable to the prompt template config. + * + * @param inputVariable The input variable to add. + * @return {@code this} prompt template config. + */ + public Builder addInputVariable(InputVariable inputVariable) { + inputVariables.add(inputVariable); + return this; + } + + /** + * Set the template of the prompt template config. + * + * @param template The template of the prompt template config. + * @return {@code this} prompt template config. + */ + public Builder withTemplate(String template) { + this.template = template; + return this; + } + + /** + * Set the description of the prompt template config. + * + * @param description The description of the prompt template config. + * @return {@code this} prompt template config. + */ + public Builder withDescription(String description) { + this.description = description; + return this; + } + + /** + * Set the template format of the prompt template config. + * + * @param templateFormat The template format of the prompt template config. + * @return {@code this} prompt template config. + */ + public Builder withTemplateFormat(String templateFormat) { + this.templateFormat = templateFormat; + return this; + } + + /** + * Set the inputVariables of the prompt template config. + * + * @param inputVariables The input variables of the prompt template config. + * @return {@code this} prompt template config. + */ + public Builder withInputVariables(List inputVariables) { + this.inputVariables = new ArrayList<>(inputVariables); + return this; + } + + /** + * Set the output variable of the prompt template config. + * + * @param outputVariable The output variable of the prompt template config. + * @return {@code this} prompt template config. + */ + public Builder withOutputVariable(OutputVariable outputVariable) { + this.outputVariable = outputVariable; + return this; + } + + /** + * Set the prompt execution settings of the prompt template config. + * + * @param executionSettings The prompt execution settings of the prompt template config. + * @return {@code this} prompt template config. + */ + public Builder withExecutionSettings( + Map executionSettings) { + this.executionSettings = new HashMap<>(executionSettings); + return this; + } + + /** + * Build the prompt template config. + * + * @return The prompt template config. + */ + public PromptTemplateConfig build() { + return new PromptTemplateConfig( + name, + template, + templateFormat, + description, + inputVariables, + outputVariable, + executionSettings); + } + } } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplateFactory.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplateFactory.java index c761346184..5546b8c9d1 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplateFactory.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplateFactory.java @@ -1,28 +1,16 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import javax.annotation.Nullable; /** - * The interface that a {@code PromptTemplateFactory} implementation must provide. + * The interface that a {@code PromptTemplateFactory} implementation must provide. */ public interface PromptTemplateFactory { /** - * Create a prompt template, if possible, from the given configuration. - * If the {@code PromptTemplateConfig} is not supported, the method should throw an - * {@code UnknownTemplateFormatException}. - * - * @param templateConfig The configuration for the prompt template. - * @return The prompt template. - * @throws UnknownTemplateFormatException If the template format is not supported. - * @see PromptTemplateConfig#getTemplateFormat() - */ - PromptTemplate tryCreate(PromptTemplateConfig templateConfig); - - /** - * Create a prompt template, if possible, from the given configuration. - * This is a convenience method that wraps the - * {@link KernelPromptTemplateFactory#tryCreate(PromptTemplateConfig)} + * Create a prompt template, if possible, from the given configuration. This is a convenience + * method that wraps the {@link KernelPromptTemplateFactory#tryCreate(PromptTemplateConfig)} * method. * * @param templateConfig The configuration for the prompt template. @@ -34,8 +22,21 @@ public interface PromptTemplateFactory { return new KernelPromptTemplateFactory().tryCreate(templateConfig); } + /** + * Create a prompt template, if possible, from the given configuration. If the + * {@code PromptTemplateConfig} is not supported, the method should throw an + * {@code UnknownTemplateFormatException}. + * + * @param templateConfig The configuration for the prompt template. + * @return The prompt template. + * @throws UnknownTemplateFormatException If the template format is not supported. + * @see PromptTemplateConfig#getTemplateFormat() + */ + PromptTemplate tryCreate(PromptTemplateConfig templateConfig); + /** * Exception thrown when the template format is not supported. + * * @see PromptTemplateConfig#getTemplateFormat() */ class UnknownTemplateFormatException extends IllegalArgumentException { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/annotations/DefineKernelFunction.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/annotations/DefineKernelFunction.java index 84a4422639..74d933af96 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/annotations/DefineKernelFunction.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/annotations/DefineKernelFunction.java @@ -6,43 +6,52 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -/** Annotation that defines a method that can be invoked as a native function */ +/** + * Annotation that defines a method that can be invoked as a native function + */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface DefineKernelFunction { /** - * The description of what the function does. The description should - * be short and concise. The model uses the description to - * determine whether the function is a good match for use to - * complete a prompt. If the model is not selecting a function - * when it should be, consider adding more detail to the description. - * @return the description of the function, or an empty string if no description is provided. + * The description of what the function does. The description should be short and concise. The + * model uses the description to determine whether the function is a good match for use to + * complete a prompt. If the model is not selecting a function when it should be, consider + * adding more detail to the description. + * + * @return the description of the function, or an empty string if no description is provided. */ String description() default ""; /** - * The name of the function. + * The name of the function. + * * @return the name of the function, or an empty string if no name is provided. */ String name() default ""; /** - * The fully qualified class name of the return value of the function, for example, "java.lang.String". - * If this parameter is not provided, the model will attempt to infer the return type from the method signature. + * The fully qualified class name of the return value of the function, for example, + * "java.lang.String". If this parameter is not provided, the model will attempt to infer the + * return type from the method signature. + * * @return the fully qualified class name of the return value of the function */ String returnType() default ""; /** - * The description of the return value of the function. The description should be short and concise. - * @return the description of the return value of the function, or an empty string if no description is provided. + * The description of the return value of the function. The description should be short and + * concise. + * + * @return the description of the return value of the function, or an empty string if no + * description is provided. */ String returnDescription() default ""; /** - * Examples of how to use the function. The examples should be short and concise. The Semantic Kernel - * can use the examples to help the model understand how the function is used. + * Examples of how to use the function. The examples should be short and concise. The Semantic + * Kernel can use the examples to help the model understand how the function is used. + * * @return Examples of how to use the function, or an empty array if no examples are provided. */ diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/annotations/KernelFunctionParameter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/annotations/KernelFunctionParameter.java index cfd7e6fd9f..25bbe83cde 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/annotations/KernelFunctionParameter.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/annotations/KernelFunctionParameter.java @@ -2,54 +2,61 @@ package com.microsoft.semantickernel.semanticfunctions.annotations; import com.microsoft.semantickernel.contextvariables.ContextVariableType; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -/** Annotates a parameter to a native function */ +/** + * Annotates a parameter to a native function + */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) public @interface KernelFunctionParameter { /** - * A special value that is used to indicate that no default value is provided. + * A special value that is used to indicate that no default value is provided. */ String NO_DEFAULT_VALUE = "SKFunctionParameters__NO_INPUT_PROVIDED"; /** - * The description of the parameter. The description should be short and concise. - * The model uses the description to determine what value to pass to the function. - * + * The description of the parameter. The description should be short and concise. The model uses + * the description to determine what value to pass to the function. + * * @return the description of the parameter, or an empty string if no description is provided. */ String description() default ""; /** - * The name of the parameter. This element is required. + * The name of the parameter. This element is required. + * * @return the name of the parameter, or an empty string if no name is provided. */ String name(); /** - * The default value of the parameter. If no value is set, {@code null} will be passed as the value to this argument. - * @return the default value of the parameter, or {@link NO_DEFAULT_VALUE} if no default value is provided. + * The default value of the parameter. If no value is set, {@code null} will be passed as the + * value to this argument. + * + * @return the default value of the parameter, or + * {@link KernelFunctionParameter#NO_DEFAULT_VALUE} if no default value is provided. */ String defaultValue() default NO_DEFAULT_VALUE; /** - * Whether a value is required for this argument. If required is false, the model is free to choose - * whether or not to provide a value. If the model does not provide a value, the default value is used. + * Whether a value is required for this argument. If required is false, the model is free to + * choose whether to provide a value. If the model does not provide a value, the default value + * is used. + * * @return whether a value is required for this argument. */ boolean required() default true; /** - * The type of the parameter. The Semantic Kernel will use the type to find a - * {@link ContextVariableType} - * to convert the value from a prompt string to the correct argument type. The type defaults to - * {@link String} if not provided. + * The type of the parameter. The Semantic Kernel will use the type to find a + * {@link ContextVariableType} to convert the value from a prompt string to the correct argument + * type. The type defaults to {@link String} if not provided. + * * @return the type of the parameter */ Class type() default String.class; diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/annotations/SKSample.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/annotations/SKSample.java index b2ed7433ac..5b3f5ea388 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/annotations/SKSample.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/annotations/SKSample.java @@ -7,8 +7,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Annotation that decorates an {@link DefineKernelFunction} annotation to provide examples of how to use the function. - * For example: + * Annotation that decorates an {@link DefineKernelFunction} annotation to provide examples of how + * to use the function. For example: *


  * {@literal @}DefineSKFunction(
  *    name = "add",
@@ -31,14 +31,17 @@ import java.lang.annotation.Target;
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.METHOD)
 public @interface SKSample {
+
     /**
      * An example of inputs to the function.
+     *
      * @return An example of inputs to the function.
      */
     String inputs();
 
     /**
      * An example output of the function given the inputs.
+     *
      * @return An example output of the function given the inputs.
      */
     String output();
diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceCollection.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceCollection.java
index 3499033d96..48d9def780 100644
--- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceCollection.java
+++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceCollection.java
@@ -1,3 +1,4 @@
+// Copyright (c) Microsoft. All rights reserved.
 package com.microsoft.semantickernel.services;
 
 import java.util.HashMap;
diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSelection.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSelection.java
index bd15df16c9..8e139b8721 100644
--- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSelection.java
+++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSelection.java
@@ -6,6 +6,7 @@ import javax.annotation.Nullable;
 
 /**
  * The result of an AI service selection.
+ *
  * @param  The type of AI service.
  */
 public class AIServiceSelection {
@@ -18,8 +19,8 @@ public class AIServiceSelection {
      * Creates a new AI service selection.
      *
      * @param service  The selected AI service.
-     * @param settings The settings associated with the selected service. This may be {@code null} even if a
-     *                 service is selected..
+     * @param settings The settings associated with the selected service. This may be {@code null}
+     *                 even if a service is selected..
      */
     public AIServiceSelection(T service, @Nullable PromptExecutionSettings settings) {
         this.service = service;
@@ -38,8 +39,8 @@ public class AIServiceSelection {
     /**
      * Gets the settings associated with the selected service.
      *
-     * @return The settings associated with the selected service. This may be {@code null} even if a service
-     * is selected.
+     * @return The settings associated with the selected service. This may be {@code null} even if a
+     * service is selected.
      */
     @Nullable
     public PromptExecutionSettings getSettings() {
diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSelector.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSelector.java
index 8302494295..3255d79e0a 100644
--- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSelector.java
+++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSelector.java
@@ -14,15 +14,17 @@ public interface AIServiceSelector {
 
     /**
      * Resolves an {@link AIService} and associated and
-     * {@link com.microsoft.semantickernel.orchestration.PromptExecutionSettings} based on the 
+     * {@link com.microsoft.semantickernel.orchestration.PromptExecutionSettings} based on the
      * associated {@link KernelFunction} and {@link KernelFunctionArguments}.
      *
      * @param serviceType The type of service to select.  This must be the same type with which the
      *                    service was registered in the {@link AIServiceSelection}
-     * @param function The KernelFunction to use to select the service, or {@code null}.
-     * @param arguments The KernelFunctionArguments to use to select the service, or {@code null}.
-     * @param  The type of service to select.
-     * @return An {@code AIServiceSelection} containing the selected service and associated PromptExecutionSettings.
+     * @param function    The KernelFunction to use to select the service, or {@code null}.
+     * @param arguments   The KernelFunctionArguments to use to select the service, or
+     *                    {@code null}.
+     * @param          The type of service to select.
+     * @return An {@code AIServiceSelection} containing the selected service and associated
+     * PromptExecutionSettings.
      */
     @Nullable
      AIServiceSelection trySelectAIService(
diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSupplier.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSupplier.java
deleted file mode 100644
index 9a1dc6e596..0000000000
--- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSupplier.java
+++ /dev/null
@@ -1,7 +0,0 @@
-// Copyright (c) Microsoft. All rights reserved.
-package com.microsoft.semantickernel.services;
-
-public interface AIServiceSupplier {
-
-     T get(String serviceId, Class clazz);
-}
diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/BaseAIServiceSelector.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/BaseAIServiceSelector.java
index 55cf8ddf6b..2eaa9404c1 100644
--- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/BaseAIServiceSelector.java
+++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/BaseAIServiceSelector.java
@@ -1,3 +1,4 @@
+// Copyright (c) Microsoft. All rights reserved.
 package com.microsoft.semantickernel.services;
 
 import com.microsoft.semantickernel.semanticfunctions.KernelFunction;
@@ -6,10 +7,10 @@ import java.util.Map;
 import javax.annotation.Nullable;
 
 /**
- * Base class for {@link AIServiceSelector} implementations which provides a 
- * {@code Map} based collection from which an {@link AIService} can be selected.
- * The {@link #trySelectAIService(Class, KernelFunction, KernelFunctionArguments)}
- * method has been implemented. Child classes must implement the method
+ * Base class for {@link AIServiceSelector} implementations which provides a {@code Map} based
+ * collection from which an {@link AIService} can be selected. The
+ * {@link #trySelectAIService(Class, KernelFunction, KernelFunctionArguments)} method has been
+ * implemented. Child classes must implement the method
  * {@link #trySelectAIService(Class, KernelFunction, KernelFunctionArguments, Map)}.
  */
 public abstract class BaseAIServiceSelector implements AIServiceSelector {
@@ -35,16 +36,17 @@ public abstract class BaseAIServiceSelector implements AIServiceSelector {
     }
 
     /**
-     * Resolves an {@link AIService} from the {@code services} argument using
-     * the specified {@code function} and {@code arguments} for selection.
+     * Resolves an {@link AIService} from the {@code services} argument using the specified
+     * {@code function} and {@code arguments} for selection.
      *
      * @param serviceType The type of service to select.  This must be the same type with which the
      *                    service was registered in the {@link AIServiceSelection}
-     * @param function The KernelFunction to use to select the service, or {@code null}.
-     * @param arguments The KernelFunctionArguments to use to select the service, or {@code null}.
-     * @param services The services to select from.
-     * @param  The type of service to select.
-     * @return
+     * @param function    The KernelFunction to use to select the service, or {@code null}.
+     * @param arguments   The KernelFunctionArguments to use to select the service, or
+     *                    {@code null}.
+     * @param services    The services to select from.
+     * @param          The type of service to select.
+     * @return The selected service, or {@code null} if no service could be selected.
      */
     @Nullable
     protected abstract  AIServiceSelection trySelectAIService(
diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/KernelContent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/KernelContent.java
index 0d886691fb..6e85f34e19 100644
--- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/KernelContent.java
+++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/KernelContent.java
@@ -1,3 +1,4 @@
+// Copyright (c) Microsoft. All rights reserved.
 package com.microsoft.semantickernel.services;
 
 import com.microsoft.semantickernel.orchestration.FunctionResultMetadata;
@@ -5,7 +6,8 @@ import javax.annotation.Nullable;
 
 /**
  * Base class which represents the content returned by an AI service.
- * @param  The type of the content. 
+ *
+ * @param  The type of the content.
  */
 public abstract class KernelContent {
 
@@ -17,7 +19,7 @@ public abstract class KernelContent {
     @Nullable
     private final T innerContent;
 
-    /** 
+    /**
      * The model ID used to generate the content.
      */
     @Nullable
@@ -31,9 +33,10 @@ public abstract class KernelContent {
 
     /**
      * Initializes a new instance of the {@link KernelContent} class.
+     *
      * @param innerContent The inner content representation.
-     * @param modelId The model identifier used to generate the content.
-     * @param metadata The metadata associated with the content.
+     * @param modelId      The model identifier used to generate the content.
+     * @param metadata     The metadata associated with the content.
      */
     public KernelContent(
         @Nullable T innerContent,
@@ -46,6 +49,7 @@ public abstract class KernelContent {
 
     /**
      * Gets the inner content representation.
+     *
      * @return The inner content representation.
      */
     @Nullable
@@ -55,6 +59,7 @@ public abstract class KernelContent {
 
     /**
      * Gets the model identifier used to generate the content.
+     *
      * @return The model identifier used to generate the content.
      */
     @Nullable
@@ -64,6 +69,7 @@ public abstract class KernelContent {
 
     /**
      * Gets the metadata associated with the content.
+     *
      * @return The metadata associated with the content.
      */
     @Nullable
@@ -73,6 +79,7 @@ public abstract class KernelContent {
 
     /**
      * Gets the content returned by the AI service.
+     *
      * @return The content.
      */
     @Nullable
diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/NamedServiceProvider.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/NamedServiceProvider.java
index 9e50965b5f..8745f054de 100644
--- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/NamedServiceProvider.java
+++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/NamedServiceProvider.java
@@ -5,15 +5,17 @@ import javax.annotation.Nullable;
 
 /**
  * A service provider for named services.
+ *
  * @param  The type of the service.
  */
 public interface NamedServiceProvider {
+
     /**
      * Gets the service of the specified type and name, or {@code null} if not found.
      *
-     * @param name The name of the service, or {@code null} for the default service.
+     * @param name  The name of the service, or {@code null} for the default service.
      * @param clazz The type of the service.
-     * @param  The specific type of the service
+     * @param    The specific type of the service
      * @return The service instance, or {@code null} if not found.
      */
     @Nullable
diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/OrderedAIServiceSelector.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/OrderedAIServiceSelector.java
index e8ee798afb..411ba9877e 100644
--- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/OrderedAIServiceSelector.java
+++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/OrderedAIServiceSelector.java
@@ -1,10 +1,11 @@
+// Copyright (c) Microsoft. All rights reserved.
 package com.microsoft.semantickernel.services;
 
-import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService;
 import com.microsoft.semantickernel.implementation.Verify;
+import com.microsoft.semantickernel.orchestration.PromptExecutionSettings;
 import com.microsoft.semantickernel.semanticfunctions.KernelFunction;
 import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments;
-import com.microsoft.semantickernel.orchestration.PromptExecutionSettings;
+import com.microsoft.semantickernel.services.chatcompletion.ChatCompletionService;
 import com.microsoft.semantickernel.services.textcompletion.TextGenerationService;
 import java.util.List;
 import java.util.Map;
@@ -15,26 +16,26 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Implementation of {@link com.microsoft.semantickernel.services.AIServiceSelector} that 
- * selects the AI service based on the order of the execution settings.
- * Uses the service id or model id to select the preferred service provider and then 
- * returns the service and associated execution settings.
+ * Implementation of {@link com.microsoft.semantickernel.services.AIServiceSelector} that selects
+ * the AI service based on the order of the execution settings. Uses the service id or model id to
+ * select the preferred service provider and then returns the service and associated execution
+ * settings.
  */
 public class OrderedAIServiceSelector extends BaseAIServiceSelector {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(OrderedAIServiceSelector.class);
 
     /**
-     * Initializes a new instance of the {@link OrderedAIServiceSelector} 
-     * class with an empty collection of services.
+     * Initializes a new instance of the {@link OrderedAIServiceSelector} class with an empty
+     * collection of services.
      */
     public OrderedAIServiceSelector() {
         super(new AIServiceCollection());
     }
 
     /**
-     * Initializes a new instance of the {@link OrderedAIServiceSelector} 
-     * class with the specified services.
+     * Initializes a new instance of the {@link OrderedAIServiceSelector} class with the specified
+     * services.
      *
      * @param services The services to select from.
      */
@@ -42,6 +43,28 @@ public class OrderedAIServiceSelector extends BaseAIServiceSelector {
         super(services);
     }
 
+    @SuppressWarnings("unchecked")
+    @Nullable
+    private static  AIServiceSelection castServiceSelection(
+        AIServiceSelection selection) {
+        try {
+            // unchecked cast
+            return (AIServiceSelection) selection;
+        } catch (ClassCastException e) {
+            LOGGER.debug("{}", e.getMessage());
+            return null;
+        }
+    }
+
+    @Nullable
+    private static Map settingsFromFunctionSettings(
+        @Nullable KernelFunction function) {
+        if (function != null) {
+            return function.getExecutionSettings();
+        }
+        return null;
+    }
+
     @Nullable
     @Override
     public  AIServiceSelection trySelectAIService(
@@ -136,28 +159,6 @@ public class OrderedAIServiceSelector extends BaseAIServiceSelector {
         return null;
     }
 
-    @SuppressWarnings("unchecked")
-    @Nullable
-    private static  AIServiceSelection castServiceSelection(
-        AIServiceSelection selection) {
-        try {
-            // unchecked cast
-            return (AIServiceSelection) selection;
-        } catch (ClassCastException e) {
-            LOGGER.debug("%s", e.getMessage());
-            return null;
-        }
-    }
-
-    @Nullable
-    private static Map settingsFromFunctionSettings(
-        @Nullable KernelFunction function) {
-        if (function != null) {
-            return function.getExecutionSettings();
-        }
-        return null;
-    }
-
     private AIService getServiceByModelId(String modelId) {
         return services
             .values()
@@ -188,7 +189,7 @@ public class OrderedAIServiceSelector extends BaseAIServiceSelector {
      * Gets the service of the specified type.
      *
      * @param clazz The type of service to get.
-     * @param  The type of service to get.
+     * @param    The type of service to get.
      * @return The service of the specified type, or {@code null} if no such service exists.
      */
     @Nullable
diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/ServiceNotFoundException.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/ServiceNotFoundException.java
index 7046109dda..3209d89ef2 100644
--- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/ServiceNotFoundException.java
+++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/ServiceNotFoundException.java
@@ -1,3 +1,4 @@
+// Copyright (c) Microsoft. All rights reserved.
 package com.microsoft.semantickernel.services;
 
 import com.microsoft.semantickernel.exceptions.SKCheckedException;
@@ -9,6 +10,7 @@ public class ServiceNotFoundException extends SKCheckedException {
 
     /**
      * Initializes a new instance of the {@link ServiceNotFoundException} class.
+     *
      * @param s A message which describes the service that could not be found.
      */
     public ServiceNotFoundException(String s) {
diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/StreamingKernelContent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/StreamingKernelContent.java
index 0b05ff05ee..6c1ddab100 100644
--- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/StreamingKernelContent.java
+++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/StreamingKernelContent.java
@@ -1,3 +1,4 @@
+// Copyright (c) Microsoft. All rights reserved.
 package com.microsoft.semantickernel.services;
 
 import com.microsoft.semantickernel.contextvariables.ContextVariable;
@@ -6,22 +7,24 @@ import javax.annotation.Nullable;
 
 /**
  * Base class which represents the content returned by a streaming AI service.
- * @param  The type of the content. 
+ *
+ * @param  The type of the content.
  */
 public abstract class StreamingKernelContent extends KernelContent {
 
     /**
-     * In a scenario of multiple choices per request, this represents 
-     * the zero-based index of the choice in the streaming sequence
+     * In a scenario of multiple choices per request, this represents the zero-based index of the
+     * choice in the streaming sequence
      */
     private final int choiceIndex;
 
     /**
      * Initializes a new instance of the {@link StreamingKernelContent} class.
+     *
      * @param innerContent The inner content representation.
-     * @param choiceIndex The zero-based index of the choice in the streaming sequence.
-     * @param modelId The model identifier used to generate the content.
-     * @param metadata The metadata associated with the content.
+     * @param choiceIndex  The zero-based index of the choice in the streaming sequence.
+     * @param modelId      The model identifier used to generate the content.
+     * @param metadata     The metadata associated with the content.
      */
     protected StreamingKernelContent(
         @Nullable T innerContent,
@@ -34,6 +37,7 @@ public abstract class StreamingKernelContent extends KernelContent {
 
     /**
      * Gets the zero-based index of the choice in the streaming sequence.
+     *
      * @return The zero-based index of the choice in the streaming sequence.
      */
     public int getChoiceIndex() {
diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/TextAIService.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/TextAIService.java
index 6914e48bf0..09b3ea1fe5 100644
--- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/TextAIService.java
+++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/TextAIService.java
@@ -1,31 +1,32 @@
 // Copyright (c) Microsoft. All rights reserved.
 package com.microsoft.semantickernel.services;
 
-import com.microsoft.semantickernel.services.AIService;
-
 /**
  * Marker interface for Text AI services, typically Chat or Text generation for OpenAI
  */
 public interface TextAIService extends AIService {
+
     /**
      * The maximum number of results per prompt
      */
     int MAX_RESULTS_PER_PROMPT = 128;
 
     /**
-     * The maximum number of auto-invokes that can be in-flight at any given time as part of the current
-     * asynchronous chain of execution.
+     * The maximum number of auto-invokes that can be in-flight at any given time as part of the
+     * current asynchronous chain of execution.
      * 

- * This is a fail-safe mechanism. If someone accidentally manages to set up execution settings in such a way that - * auto-invocation is invoked recursively, and in particular where a prompt function is able to auto-invoke itself, - * we could end up in an infinite loop. This const is a backstop against that happening. We should never come close - * to this limit, but if we do, auto-invoke will be disabled for the current flow in order to prevent runaway execution. - * With the current setup, the way this could possibly happen is if a prompt function is configured with built-in - * execution settings that opt-in to auto-invocation of everything in the kernel, in which case the invocation of that - * prompt function could advertise itself as a candidate for auto-invocation. We don't want to outright block that, - * if that's something a developer has asked to do (e.g. it might be invoked with different arguments than its parent - * was invoked with), but we do want to limit it. This limit is arbitrary and can be tweaked in the future and/or made - * configurable should need arise. + * This is a fail-safe mechanism. If someone accidentally manages to set up execution settings + * in such a way that auto-invocation is invoked recursively, and in particular where a prompt + * function is able to auto-invoke itself, we could end up in an infinite loop. This const is a + * backstop against that happening. We should never come close to this limit, but if we do, + * auto-invoke will be disabled for the current flow in order to prevent runaway execution. With + * the current setup, the way this could possibly happen is if a prompt function is configured + * with built-in execution settings that opt-in to auto-invocation of everything in the kernel, + * in which case the invocation of that prompt function could advertise itself as a candidate + * for auto-invocation. We don't want to outright block that, if that's something a developer + * has asked to do (e.g. it might be invoked with different arguments than its parent was + * invoked with), but we do want to limit it. This limit is arbitrary and can be tweaked in the + * future and/or made configurable should need arise. *

*/ int MAXIMUM_INFLIGHT_AUTO_INVOKES = 5; diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/AuthorRole.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/AuthorRole.java index 6a1e76a61c..745a1050f8 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/AuthorRole.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/AuthorRole.java @@ -6,8 +6,8 @@ package com.microsoft.semantickernel.services.chatcompletion; */ public enum AuthorRole { - /** - * A system message helps set the behavior of the assistant. + /** + * A system message helps set the behavior of the assistant. */ SYSTEM("system"), /** @@ -24,14 +24,14 @@ public enum AuthorRole { */ TOOL("tool"); - @Override - public String toString() { - return role; - } - private final String role; private AuthorRole(String role) { this.role = role; } + + @Override + public String toString() { + return role; + } } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/ChatCompletionService.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/ChatCompletionService.java index e65495ba48..aa7c71c2f8 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/ChatCompletionService.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/ChatCompletionService.java @@ -4,11 +4,11 @@ package com.microsoft.semantickernel.services.chatcompletion; import com.azure.ai.openai.OpenAIAsyncClient; import com.azure.ai.openai.OpenAIClient; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.services.TextAIService; import com.microsoft.semantickernel.builders.Buildable; import com.microsoft.semantickernel.builders.SemanticKernelBuilder; import com.microsoft.semantickernel.implementation.ServiceLoadUtil; import com.microsoft.semantickernel.orchestration.InvocationContext; +import com.microsoft.semantickernel.services.TextAIService; import java.util.List; import javax.annotation.Nullable; import reactor.core.publisher.Mono; @@ -19,13 +19,24 @@ import reactor.core.publisher.Mono; public interface ChatCompletionService extends Buildable, TextAIService { /** - * Gets the chat message contents asynchronously using - * {@code ChatHistory} to support a turn-based conversation. - * Typically, the resulting chat message contents is appended - * to the {@code chatHistory} to continue the conversation. + * Get a builder for creating a {@code ChatCompletionService}. The builder loads a service that + * implements the {@link ChatCompletionService.Builder} interface. * - * @param chatHistory the chat history - * @param kernel the kernel + * @return a builder for creating a {@code ChatCompletionService} + */ + static Builder builder() { + return ServiceLoadUtil.findServiceLoader(Builder.class, + "com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatCompletion$Builder") + .get(); + } + + /** + * Gets the chat message contents asynchronously using {@code ChatHistory} to support a + * turn-based conversation. Typically, the resulting chat message contents is appended to the + * {@code chatHistory} to continue the conversation. + * + * @param chatHistory the chat history + * @param kernel the kernel * @param invocationContext the invocation context * @return the chat message contents */ @@ -37,8 +48,8 @@ public interface ChatCompletionService extends Buildable, TextAIService { /** * Gets the chat message contents asynchronously using a prompt. * - * @param prompt the prompt - * @param kernel the kernel + * @param prompt the prompt + * @param kernel the kernel * @param invocationContext the invocation context * @return the chat message contents */ @@ -47,20 +58,9 @@ public interface ChatCompletionService extends Buildable, TextAIService { @Nullable Kernel kernel, @Nullable InvocationContext invocationContext); - /** - * Get a builder for creating a {@code ChatCompletionService}. The builder loads a service - * that implements the {@link ChatCompletionService.Builder} interface. - * @return a builder for creating a {@code ChatCompletionService} - */ - static Builder builder() { - return ServiceLoadUtil.findServiceLoader(Builder.class, - "com.microsoft.semantickernel.aiservices.openai.chatcompletion.OpenAIChatCompletion$Builder") - .get(); - } - /** * Builder API for creating a {@link ChatCompletionService}. Concrete implementations of - * {@link ChatCompletionService} must implement the {@link SemanticKernelBuilder#build()} + * {@link ChatCompletionService} must implement the {@link SemanticKernelBuilder#build()} * method. */ abstract class Builder implements SemanticKernelBuilder { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/ChatHistory.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/ChatHistory.java index 43271069ce..5ac4bc91ee 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/ChatHistory.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/ChatHistory.java @@ -21,8 +21,8 @@ public class ChatHistory implements Iterable> { private final List> chatMessageContents; /** - * The default constructor adds an "Assistant is a large language model." - * system message to the chat history + * The default constructor adds an "Assistant is a large language model." system message to the + * chat history */ public ChatHistory() { this(DEFAULT_CHAT_SYSTEM_PROMPT); @@ -111,9 +111,9 @@ public class ChatHistory implements Iterable> { * Add a message to the chat history * * @param authorRole The role of the author of the message - * @param content The content of the message - * @param encoding The encoding of the message - * @param metadata The metadata of the message + * @param content The content of the message + * @param encoding The encoding of the message + * @param metadata The metadata of the message */ public void addMessage(AuthorRole authorRole, String content, Charset encoding, FunctionResultMetadata metadata) { @@ -125,7 +125,7 @@ public class ChatHistory implements Iterable> { * Add a message to the chat history * * @param authorRole The role of the author of the message - * @param content The content of the message + * @param content The content of the message */ public void addMessage(AuthorRole authorRole, String content) { chatMessageContents.add( diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/ChatMessageContent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/ChatMessageContent.java index 0799d44341..c75c8d2eda 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/ChatMessageContent.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/ChatMessageContent.java @@ -1,8 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.services.chatcompletion; -import com.microsoft.semantickernel.services.KernelContent; import com.microsoft.semantickernel.orchestration.FunctionResultMetadata; +import com.microsoft.semantickernel.services.KernelContent; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -12,16 +12,18 @@ import javax.annotation.Nullable; /** * Represents the content of a chat message + * + * @param the type of the inner content within the messages */ public class ChatMessageContent extends KernelContent { - private AuthorRole authorRole; + private final AuthorRole authorRole; @Nullable - private String content; + private final String content; @Nullable - private List> items; + private final List> items; @Nullable - private Charset encoding; + private final Charset encoding; /** * Creates a new instance of the {@link ChatMessageContent} class. @@ -62,6 +64,7 @@ public class ChatMessageContent extends KernelContent { this.authorRole = authorRole; this.content = content; this.encoding = encoding != null ? encoding : StandardCharsets.UTF_8; + this.items = null; } /** @@ -97,15 +100,6 @@ public class ChatMessageContent extends KernelContent { return authorRole; } - /** - * Sets the author role that generated the content - * - * @param authorRole the author role that generated the content - */ - public void setAuthorRole(AuthorRole authorRole) { - this.authorRole = authorRole; - } - /** * Gets the content * @@ -117,15 +111,6 @@ public class ChatMessageContent extends KernelContent { return content; } - /** - * Sets the content - * - * @param content the content - */ - public void setContent(@Nullable String content) { - this.content = content; - } - /** * Gets the {@code KernelContent} items that comprise the content. * @@ -135,15 +120,6 @@ public class ChatMessageContent extends KernelContent { return Collections.unmodifiableList(items); } - /** - * Sets the {@code KernelContent} items that comprise the content. - * - * @param items the items - */ - public void setItems(List> items) { - this.items = new ArrayList<>(items); - } - /** * Gets the encoding of the content * @@ -154,15 +130,6 @@ public class ChatMessageContent extends KernelContent { return encoding; } - /** - * Sets the encoding of the content - * - * @param encoding the encoding - */ - public void setEncoding(Charset encoding) { - this.encoding = encoding; - } - @Override public String toString() { return content != null ? content : ""; diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/StreamingChatMessageContent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/StreamingChatMessageContent.java deleted file mode 100644 index 8164a3c610..0000000000 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/StreamingChatMessageContent.java +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -package com.microsoft.semantickernel.services.chatcompletion; - -import com.microsoft.semantickernel.services.StreamingKernelContent; -import com.microsoft.semantickernel.contextvariables.ContextVariable; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.util.Map; -import javax.annotation.Nullable; - -/** - * Represents the content of a chat message that is streamed. - * - * @param the type of the inner content - */ -public class StreamingChatMessageContent extends StreamingKernelContent { - - private final String content; - private final AuthorRole role; - private Charset encoding; - - /** - * Creates a new instance of the {@link StreamingChatMessageContent} class. - * - * @param role the author role that generated the content - * @param content the content - * @param modelId the model id - */ - public StreamingChatMessageContent( - AuthorRole role, - String content, - @Nullable String modelId) { - this(role, content, null, 0, modelId, null, null); - } - - /** - * Creates a new instance of the {@link StreamingChatMessageContent} class. - * - * @param role the author role that generated the content - * @param content the content - * @param innerContent the inner content - * @param choiceIndex the choice index - * @param modelId the model id - * @param encoding the encoding - * @param metadata the metadata - */ - public StreamingChatMessageContent( - AuthorRole role, - String content, - @Nullable T innerContent, - int choiceIndex, - @Nullable String modelId, - @Nullable Charset encoding, - @Nullable Map> metadata) { - super(innerContent, choiceIndex, modelId, metadata); - this.role = role; - this.content = content; - this.encoding = encoding != null ? encoding : StandardCharsets.UTF_8; - } - - @Override - public String toString() { - return content != null ? content : ""; - } - - @Override - public String getContent() { - return content; - } - - /** - * Gets the role of the author of the message - * - * @return the role of the author of the message - */ - public AuthorRole getRole() { - return role; - } - - /** - * Gets the encoding of the message - * - * @return the encoding of the message - */ - public Charset getEncoding() { - return encoding; - } - - /** - * Sets the encoding of the message - * - * @param encoding the encoding of the message - * @return this instance - */ - public StreamingChatMessageContent setEncoding(Charset encoding) { - this.encoding = encoding; - return this; - } -} diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/textcompletion/StreamingTextContent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/textcompletion/StreamingTextContent.java index 213ee3b0c1..7fdadad792 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/textcompletion/StreamingTextContent.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/textcompletion/StreamingTextContent.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.services.textcompletion; import com.microsoft.semantickernel.services.StreamingKernelContent; diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/textcompletion/TextContent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/textcompletion/TextContent.java index b734f1e2f7..d5eb1690af 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/textcompletion/TextContent.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/textcompletion/TextContent.java @@ -1,7 +1,8 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.services.textcompletion; -import com.microsoft.semantickernel.services.KernelContent; import com.microsoft.semantickernel.orchestration.FunctionResultMetadata; +import com.microsoft.semantickernel.services.KernelContent; /** * Content from a text completion service. @@ -11,10 +12,11 @@ public class TextContent extends KernelContent { private final String content; /** - * Initializes a new instance of the {@code TextContent} class with a provided content, model ID, and metadata. + * Initializes a new instance of the {@code TextContent} class with a provided content, model + * ID, and metadata. * - * @param content The content. - * @param modelId The model ID. + * @param content The content. + * @param modelId The model ID. * @param metadata The metadata. */ public TextContent( @@ -27,6 +29,7 @@ public class TextContent extends KernelContent { /** * Gets the content. + * * @return The content. */ public String getValue() { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/textcompletion/TextGenerationService.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/textcompletion/TextGenerationService.java index 313f393e54..6ba5e4f450 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/textcompletion/TextGenerationService.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/textcompletion/TextGenerationService.java @@ -3,11 +3,11 @@ package com.microsoft.semantickernel.services.textcompletion; import com.azure.ai.openai.OpenAIAsyncClient; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.services.TextAIService; import com.microsoft.semantickernel.builders.Buildable; import com.microsoft.semantickernel.builders.SemanticKernelBuilder; import com.microsoft.semantickernel.implementation.ServiceLoadUtil; import com.microsoft.semantickernel.orchestration.PromptExecutionSettings; +import com.microsoft.semantickernel.services.TextAIService; import java.util.List; import javax.annotation.Nullable; import reactor.core.publisher.Flux; @@ -18,13 +18,24 @@ import reactor.core.publisher.Mono; */ public interface TextGenerationService extends Buildable, TextAIService { + /** + * Get the builder for the TextGenerationService + * + * @return The builder + */ + static Builder builder() { + return ServiceLoadUtil.findServiceLoader(Builder.class, + "com.microsoft.semantickernel.aiservices.openai.textcompletion.OpenAITextGenerationService$Builder") + .get(); + } + /** * Creates a completion for the prompt and settings. * * @param prompt The prompt to complete. * @param executionSettings Request settings for the completion API * @param kernel The {@code Kernel} containing services, plugins, and other state for - * use throughout the operation. + * use throughout the operation. * @return Text generated by the remote model */ Mono> getTextContentsAsync( @@ -39,7 +50,7 @@ public interface TextGenerationService extends Buildable, TextAIService { * @param prompt The prompt to complete. * @param executionSettings The AI execution settings (optional). * @param kernel The {@code Kernel} containing services, plugins, and other state for - * use throughout the operation. + * use throughout the operation. * @return Streaming list of different completion streaming string updates generated by the * remote model */ @@ -48,16 +59,6 @@ public interface TextGenerationService extends Buildable, TextAIService { @Nullable PromptExecutionSettings executionSettings, @Nullable Kernel kernel); - /** - * Get the builder for the TextGenerationService - * @return The builder - */ - static Builder builder() { - return ServiceLoadUtil.findServiceLoader(Builder.class, - "com.microsoft.semantickernel.aiservices.openai.textcompletion.OpenAITextGenerationService$Builder") - .get(); - } - /** * Builder for a TextGenerationService */ diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/templateengine/handlebars/HandlebarsPromptTemplate.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/templateengine/handlebars/HandlebarsPromptTemplate.java index 82e6a563fe..ec6b5aa4a3 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/templateengine/handlebars/HandlebarsPromptTemplate.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/templateengine/handlebars/HandlebarsPromptTemplate.java @@ -6,16 +6,17 @@ import com.github.jknack.handlebars.Handlebars; import com.github.jknack.handlebars.Options; import com.github.jknack.handlebars.ValueResolver; import com.microsoft.semantickernel.Kernel; -import com.microsoft.semantickernel.semanticfunctions.KernelParameterMetadata; -import com.microsoft.semantickernel.services.chatcompletion.ChatHistory; -import com.microsoft.semantickernel.services.chatcompletion.ChatMessageContent; +import com.microsoft.semantickernel.contextvariables.ContextVariable; +import com.microsoft.semantickernel.exceptions.SKException; import com.microsoft.semantickernel.orchestration.InvocationContext; +import com.microsoft.semantickernel.plugin.KernelPlugin; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments; -import com.microsoft.semantickernel.contextvariables.ContextVariable; -import com.microsoft.semantickernel.plugin.KernelPlugin; +import com.microsoft.semantickernel.semanticfunctions.KernelParameterMetadata; import com.microsoft.semantickernel.semanticfunctions.PromptTemplate; import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig; +import com.microsoft.semantickernel.services.chatcompletion.ChatHistory; +import com.microsoft.semantickernel.services.chatcompletion.ChatMessageContent; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.IOException; import java.util.ArrayList; @@ -54,8 +55,14 @@ public class HandlebarsPromptTemplate implements PromptTemplate { Kernel kernel, @Nullable KernelFunctionArguments arguments, @Nullable InvocationContext context) { + String template = promptTemplate.getTemplate(); + if (template == null) { + return Mono.error(new SKException( + String.format("No prompt template was provided for the prompt %s.", + promptTemplate.getName()))); + } HandleBarsPromptTemplateHandler handler = new HandleBarsPromptTemplateHandler(kernel, - promptTemplate.getTemplate()); + template); if (arguments == null) { arguments = new KernelFunctionArguments(); diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/templateengine/semantickernel/TemplateException.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/templateengine/semantickernel/TemplateException.java index c18ed8ae91..6c5779b42e 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/templateengine/semantickernel/TemplateException.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/templateengine/semantickernel/TemplateException.java @@ -10,6 +10,9 @@ import javax.annotation.Nullable; */ public class TemplateException extends SKException { + /** + * Error code. + */ @Nonnull private final ErrorCodes errorCode; @@ -54,6 +57,7 @@ public class TemplateException extends SKException { /** * Gets the error code for this exception. + * * @return The error code. */ //spotless:on @@ -110,8 +114,10 @@ public class TemplateException extends SKException { } // spotless:off + /** * Gets the message for the error code. + * * @return The error code message */ //spotless:on diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/text/TextChunker.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/text/TextChunker.java index 92659a71f5..470a2deff8 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/text/TextChunker.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/text/TextChunker.java @@ -89,7 +89,7 @@ public class TextChunker { List lines, int maxTokensPerParagraph, Function> longLinesSplitter) { - if (lines.size() == 0) { + if (lines.isEmpty()) { return new ArrayList<>(); } @@ -128,11 +128,11 @@ public class TextChunker { if (TokenCount(lastParagraph.length()) < maxTokensPerParagraph / 4) { List lastParagraphTokens = Arrays.stream(lastParagraph.split(s_spaceChar)) - .filter(it -> it.length() != 0) + .filter(it -> !it.isEmpty()) .collect(Collectors.toList()); List secondLastParagraphTokens = Arrays .stream(secondLastParagraph.split(s_spaceChar)) - .filter(it -> it.length() != 0) + .filter(it -> !it.isEmpty()) .collect(Collectors.toList()); int lastParagraphTokensCount = lastParagraphTokens.size(); @@ -166,17 +166,6 @@ public class TextChunker { return paragraphs; } - private static class SplitString { - - public final boolean inputWasSplit; - public final List result; - - private SplitString(boolean inputWasSplit, List result) { - this.inputWasSplit = inputWasSplit; - this.result = result; - } - } - private static List internalSplitLines( String text, int maxTokensPerLine, boolean trim, List splitOptions) { text = text.replaceAll("\\r?\\n|\\r", "\n"); @@ -290,4 +279,15 @@ public class TextChunker { // depending on the model to be called. For now, we use an extremely rough estimate. return inputLength / 4; } + + private static class SplitString { + + public final boolean inputWasSplit; + public final List result; + + private SplitString(boolean inputWasSplit, List result) { + this.inputWasSplit = inputWasSplit; + this.result = result; + } + } } diff --git a/java/semantickernel-api/src/test/java/com/microsoft/semantickernel/contextvariables/converters/ContextVariableTypeConverterTest.java b/java/semantickernel-api/src/test/java/com/microsoft/semantickernel/contextvariables/converters/ContextVariableTypeConverterTest.java new file mode 100644 index 0000000000..1b479753d2 --- /dev/null +++ b/java/semantickernel-api/src/test/java/com/microsoft/semantickernel/contextvariables/converters/ContextVariableTypeConverterTest.java @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft. All rights reserved. +package com.microsoft.semantickernel.contextvariables.converters; + +import com.microsoft.semantickernel.contextvariables.ContextVariable; +import com.microsoft.semantickernel.contextvariables.ContextVariableType; +import com.microsoft.semantickernel.contextvariables.ContextVariableTypes; +import java.io.Serializable; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.stream.Stream; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.TestFactory; + +public class ContextVariableTypeConverterTest { + + @TestFactory + public Stream testConvertIntegerToString() { + return Stream.of( + new TestCase<>("StringToInteger", String.class, Integer.class, "1"), + new TestCase<>("IntegerToString", Integer.class, String.class, 1), + + new TestCase<>("StringToFloat", String.class, Float.class, "0.1"), + new TestCase<>("FloatToString", Float.class, String.class, 0.1f), + + new TestCase<>("StringToBoolean", String.class, Boolean.class, "true"), + new TestCase<>("BooleanToString", Boolean.class, String.class, true), + + new TestCase<>("NumberToInteger", Number.class, Integer.class, 100.0f), + new TestCase<>("IntegerToNumber", Integer.class, Number.class, 100), + + new TestCase<>("StringToDate", String.class, OffsetDateTime.class, + ZonedDateTime.now(ZoneId.systemDefault()).format(DateTimeFormatter.ISO_DATE_TIME)), + new TestCase<>("DateToString", OffsetDateTime.class, String.class, + OffsetDateTime.now(ZoneId.systemDefault()))) + .map(s -> DynamicTest.dynamicTest(s.name, () -> { + Assertions.assertNotNull(ContextVariable.ofGlobalType(s.object)); + Assertions.assertNotNull(ContextVariable.ofGlobalType(s.object).getValue()); + + try { + ContextVariableType type = ContextVariableTypes + .getGlobalVariableTypeForClass( + s.targetClazz); + Assertions.assertNotNull(ContextVariable.convert(s.object, type)); + } catch (Exception ignored) { + + } + })); + + } + + private static class TestCase { + + private final String name; + private final Class clazz; + private final Class targetClazz; + private final T object; + + private TestCase(String name, Class clazz, Class targetClazz, T object) { + this.name = name; + this.clazz = clazz; + this.targetClazz = targetClazz; + this.object = object; + } + } + +} diff --git a/java/semantickernel-api/src/test/java/com/microsoft/semantickernel/contextvariables/converters/NumberVariableContextVariableTypeConverterTest.java b/java/semantickernel-api/src/test/java/com/microsoft/semantickernel/contextvariables/converters/NumberVariableContextVariableTypeConverterTest.java index b8a06c861a..b8852870fb 100644 --- a/java/semantickernel-api/src/test/java/com/microsoft/semantickernel/contextvariables/converters/NumberVariableContextVariableTypeConverterTest.java +++ b/java/semantickernel-api/src/test/java/com/microsoft/semantickernel/contextvariables/converters/NumberVariableContextVariableTypeConverterTest.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/java/semantickernel-bom/pom.xml b/java/semantickernel-bom/pom.xml index e5ae859bb0..46861867f7 100644 --- a/java/semantickernel-bom/pom.xml +++ b/java/semantickernel-bom/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 com.microsoft.semantic-kernel