From 44c4e15de17093d7a1bef759cccda59d4e55dff1 Mon Sep 17 00:00:00 2001 From: GitHub Date: Fri, 16 Feb 2024 15:36:41 +0000 Subject: [PATCH 01/13] [maven-release-plugin] prepare release java-1.0.0-rc1 --- java/aiservices/openai/pom.xml | 5 ++--- java/api-test/integration-tests/pom.xml | 5 ++--- java/api-test/pom.xml | 5 ++--- .../semantickernel-connectors-web-bing/pom.xml | 5 ++--- java/plugins/semantickernel-plugin-core/pom.xml | 2 +- java/pom.xml | 7 +++---- java/samples/pom.xml | 11 +++++------ java/samples/sample-code/pom.xml | 5 ++--- java/semantickernel-api/pom.xml | 5 ++--- java/semantickernel-bom/pom.xml | 7 +++---- 10 files changed, 24 insertions(+), 33 deletions(-) diff --git a/java/aiservices/openai/pom.xml b/java/aiservices/openai/pom.xml index 12724b8165ff..9c7a2d417f9a 100644 --- a/java/aiservices/openai/pom.xml +++ b/java/aiservices/openai/pom.xml @@ -1,13 +1,12 @@ - + 4.0.0 com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1-SNAPSHOT + 1.0.0-rc1 ../../pom.xml diff --git a/java/api-test/integration-tests/pom.xml b/java/api-test/integration-tests/pom.xml index 5575f2eb55ba..82213bdc1316 100644 --- a/java/api-test/integration-tests/pom.xml +++ b/java/api-test/integration-tests/pom.xml @@ -1,13 +1,12 @@ - + 4.0.0 com.microsoft.semantic-kernel api-test - 1.0.0-rc1-SNAPSHOT + 1.0.0-rc1 ../pom.xml diff --git a/java/api-test/pom.xml b/java/api-test/pom.xml index 89e9ac2047a1..330c5d741543 100644 --- a/java/api-test/pom.xml +++ b/java/api-test/pom.xml @@ -1,13 +1,12 @@ - + 4.0.0 com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1-SNAPSHOT + 1.0.0-rc1 ../pom.xml diff --git a/java/connectors/semantickernel-connectors-web-bing/pom.xml b/java/connectors/semantickernel-connectors-web-bing/pom.xml index b8c31a4bcf1b..fa3157e9db71 100644 --- a/java/connectors/semantickernel-connectors-web-bing/pom.xml +++ b/java/connectors/semantickernel-connectors-web-bing/pom.xml @@ -1,13 +1,12 @@ - + 4.0.0 com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1-SNAPSHOT + 1.0.0-rc1 ../../pom.xml diff --git a/java/plugins/semantickernel-plugin-core/pom.xml b/java/plugins/semantickernel-plugin-core/pom.xml index 53e375dca9e4..50d9bcaf2f0d 100644 --- a/java/plugins/semantickernel-plugin-core/pom.xml +++ b/java/plugins/semantickernel-plugin-core/pom.xml @@ -6,7 +6,7 @@ com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1-SNAPSHOT + 1.0.0-rc1 ../../pom.xml diff --git a/java/pom.xml b/java/pom.xml index f4ae92bc8a6e..3dc0e543f947 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -1,13 +1,12 @@ - + 4.0.0 com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1-SNAPSHOT + 1.0.0-rc1 pom https://www.github.com/microsoft/semantic-kernel @@ -789,6 +788,6 @@ https://github.com/microsoft/semantic-kernel scm:git:https://github.com/microsoft/semantic-kernel.git scm:git:https://github.com/microsoft/semantic-kernel.git - HEAD + java-1.0.0-rc1 diff --git a/java/samples/pom.xml b/java/samples/pom.xml index 390bb4c83b64..316ae948d67d 100644 --- a/java/samples/pom.xml +++ b/java/samples/pom.xml @@ -1,16 +1,15 @@ - + 4.0.0 com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1-SNAPSHOT + 1.0.0-rc1 ../pom.xml semantickernel-samples-parent - 1.0.0-rc1-SNAPSHOT + 1.0.0-rc1 pom Semantic Kernel Samples Parent Parent pom for sample code for using the Semantic Kernel project @@ -131,8 +130,8 @@ ${project.build.sourceEncoding} true - - + + diff --git a/java/samples/sample-code/pom.xml b/java/samples/sample-code/pom.xml index c9b08a4509a6..345af266adab 100644 --- a/java/samples/sample-code/pom.xml +++ b/java/samples/sample-code/pom.xml @@ -1,11 +1,10 @@ - + 4.0.0 com.microsoft.semantic-kernel semantickernel-samples-parent - 1.0.0-rc1-SNAPSHOT + 1.0.0-rc1 ../pom.xml diff --git a/java/semantickernel-api/pom.xml b/java/semantickernel-api/pom.xml index 01d492f2e2d8..4a1e4999b933 100644 --- a/java/semantickernel-api/pom.xml +++ b/java/semantickernel-api/pom.xml @@ -1,13 +1,12 @@ - + 4.0.0 com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1-SNAPSHOT + 1.0.0-rc1 ../pom.xml diff --git a/java/semantickernel-bom/pom.xml b/java/semantickernel-bom/pom.xml index 15c896be4ce2..03aedaf7a605 100644 --- a/java/semantickernel-bom/pom.xml +++ b/java/semantickernel-bom/pom.xml @@ -1,12 +1,11 @@ - + 4.0.0 com.microsoft.semantic-kernel semantickernel-bom - 1.0.0-rc1-SNAPSHOT + 1.0.0-rc1 pom Semantic Kernel Java BOM @@ -195,6 +194,6 @@ https://github.com/microsoft/semantic-kernel scm:git:https://github.com/microsoft/semantic-kernel.git scm:git:https://github.com/microsoft/semantic-kernel.git - java-0.2.13-alpha + java-1.0.0-rc1 From e5bb1f3a502f54e6f64db07577a790b90d55e705 Mon Sep 17 00:00:00 2001 From: GitHub Date: Fri, 16 Feb 2024 15:36:41 +0000 Subject: [PATCH 02/13] [maven-release-plugin] prepare for next development iteration --- java/aiservices/openai/pom.xml | 2 +- java/api-test/integration-tests/pom.xml | 2 +- java/api-test/pom.xml | 2 +- java/connectors/semantickernel-connectors-web-bing/pom.xml | 2 +- java/plugins/semantickernel-plugin-core/pom.xml | 2 +- java/pom.xml | 4 ++-- java/samples/pom.xml | 4 ++-- java/samples/sample-code/pom.xml | 2 +- java/semantickernel-api/pom.xml | 2 +- java/semantickernel-bom/pom.xml | 4 ++-- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/java/aiservices/openai/pom.xml b/java/aiservices/openai/pom.xml index 9c7a2d417f9a..a3079e619c20 100644 --- a/java/aiservices/openai/pom.xml +++ b/java/aiservices/openai/pom.xml @@ -6,7 +6,7 @@ com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1 + 1.0.0-rc2-SNAPSHOT ../../pom.xml diff --git a/java/api-test/integration-tests/pom.xml b/java/api-test/integration-tests/pom.xml index 82213bdc1316..381e68e863b4 100644 --- a/java/api-test/integration-tests/pom.xml +++ b/java/api-test/integration-tests/pom.xml @@ -6,7 +6,7 @@ com.microsoft.semantic-kernel api-test - 1.0.0-rc1 + 1.0.0-rc2-SNAPSHOT ../pom.xml diff --git a/java/api-test/pom.xml b/java/api-test/pom.xml index 330c5d741543..69bb8b8c3fe3 100644 --- a/java/api-test/pom.xml +++ b/java/api-test/pom.xml @@ -6,7 +6,7 @@ com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1 + 1.0.0-rc2-SNAPSHOT ../pom.xml diff --git a/java/connectors/semantickernel-connectors-web-bing/pom.xml b/java/connectors/semantickernel-connectors-web-bing/pom.xml index fa3157e9db71..93eaf28a0297 100644 --- a/java/connectors/semantickernel-connectors-web-bing/pom.xml +++ b/java/connectors/semantickernel-connectors-web-bing/pom.xml @@ -6,7 +6,7 @@ com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1 + 1.0.0-rc2-SNAPSHOT ../../pom.xml diff --git a/java/plugins/semantickernel-plugin-core/pom.xml b/java/plugins/semantickernel-plugin-core/pom.xml index 50d9bcaf2f0d..114299a77d14 100644 --- a/java/plugins/semantickernel-plugin-core/pom.xml +++ b/java/plugins/semantickernel-plugin-core/pom.xml @@ -6,7 +6,7 @@ com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1 + 1.0.0-rc2-SNAPSHOT ../../pom.xml diff --git a/java/pom.xml b/java/pom.xml index 3dc0e543f947..553e7dbf42fe 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -6,7 +6,7 @@ com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1 + 1.0.0-rc2-SNAPSHOT pom https://www.github.com/microsoft/semantic-kernel @@ -788,6 +788,6 @@ https://github.com/microsoft/semantic-kernel scm:git:https://github.com/microsoft/semantic-kernel.git scm:git:https://github.com/microsoft/semantic-kernel.git - java-1.0.0-rc1 + HEAD diff --git a/java/samples/pom.xml b/java/samples/pom.xml index 316ae948d67d..540edd4b33c5 100644 --- a/java/samples/pom.xml +++ b/java/samples/pom.xml @@ -4,12 +4,12 @@ com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1 + 1.0.0-rc2-SNAPSHOT ../pom.xml semantickernel-samples-parent - 1.0.0-rc1 + 1.0.0-rc2-SNAPSHOT pom Semantic Kernel Samples Parent Parent pom for sample code for using the Semantic Kernel project diff --git a/java/samples/sample-code/pom.xml b/java/samples/sample-code/pom.xml index 345af266adab..21efb67c9b34 100644 --- a/java/samples/sample-code/pom.xml +++ b/java/samples/sample-code/pom.xml @@ -4,7 +4,7 @@ com.microsoft.semantic-kernel semantickernel-samples-parent - 1.0.0-rc1 + 1.0.0-rc2-SNAPSHOT ../pom.xml diff --git a/java/semantickernel-api/pom.xml b/java/semantickernel-api/pom.xml index 4a1e4999b933..56e9f20da19c 100644 --- a/java/semantickernel-api/pom.xml +++ b/java/semantickernel-api/pom.xml @@ -6,7 +6,7 @@ com.microsoft.semantic-kernel semantickernel-parent - 1.0.0-rc1 + 1.0.0-rc2-SNAPSHOT ../pom.xml diff --git a/java/semantickernel-bom/pom.xml b/java/semantickernel-bom/pom.xml index 03aedaf7a605..e5ae859bb0ff 100644 --- a/java/semantickernel-bom/pom.xml +++ b/java/semantickernel-bom/pom.xml @@ -5,7 +5,7 @@ com.microsoft.semantic-kernel semantickernel-bom - 1.0.0-rc1 + 1.0.0-rc2-SNAPSHOT pom Semantic Kernel Java BOM @@ -194,6 +194,6 @@ https://github.com/microsoft/semantic-kernel scm:git:https://github.com/microsoft/semantic-kernel.git scm:git:https://github.com/microsoft/semantic-kernel.git - java-1.0.0-rc1 + java-0.2.13-alpha From b780bc88101393a868d95fa680c903fe7162eb7d Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Sun, 18 Feb 2024 17:51:46 +0000 Subject: [PATCH 03/13] Convert PromptTemplateConfig and ChatMessageContent to immutable --- .../Example58_ConfigureExecutionSettings.java | 4 +- .../Example61_MultipleLLMs.java | 12 +- .../samples/syntaxexamples/RunAll.java | 1 + .../tokenizer/DefaultPromptTemplate.java | 35 ++- .../PromptTemplateConfig.java | 277 +++++++++++------- .../chatcompletion/ChatMessageContent.java | 45 +-- .../StreamingChatMessageContent.java | 99 ------- 7 files changed, 213 insertions(+), 260 deletions(-) delete mode 100644 java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/chatcompletion/StreamingChatMessageContent.java 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 8915b357ed29..ff9212bc2366 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 @@ -88,7 +88,9 @@ public static void main(String[] args) { 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/Example61_MultipleLLMs.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example61_MultipleLLMs.java index 7a69df800e18..b61979221f83 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 @@ -5,12 +5,12 @@ 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,9 +124,11 @@ public static void runByFirstModelIdAsync(Kernel kernel, String... modelIds) { .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); 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 4c96afc78237..30b7a96fc5e1 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 @@ -43,6 +43,7 @@ public static void main(String[] args) { Example56_TemplateMethodFunctionsWithMultipleArguments::main, Example57_KernelHooks::main, Example58_ConfigureExecutionSettings::main, + Example60_AdvancedMethodFunctions::main, Example61_MultipleLLMs::main, Example62_CustomAIServiceSelector::main, Example63_ChatCompletionPrompts::main, 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 8ff9ae486a30..6d6db14a044a 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 @@ -10,8 +10,8 @@ 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; @@ -31,25 +31,28 @@ */ 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); + this.blocks = extractBlocks(promptTemplateConfig); + this.promptTemplateConfig = addMissingInputVariables(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(); List blocks = new TemplateTokenizer().tokenize(templateText); @@ -67,23 +70,28 @@ private List extractBlocks() { } /** - * 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 */ @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 +103,11 @@ private void addMissingInputVariables(List blocks) { 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 +116,6 @@ public Mono renderAsync( @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/semanticfunctions/PromptTemplateConfig.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplateConfig.java index 4c46939fe7ef..935d0ba12f2a 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.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 @@ * 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,15 @@ 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; + private final String template; + private final String templateFormat; @Nullable - private String description; - private List inputVariables; + private final String description; + private final List inputVariables; @Nullable - private OutputVariable outputVariable; - private Map executionSettings; + private final OutputVariable outputVariable; + private final Map executionSettings; /** * Constructor for a prompt template config @@ -69,13 +70,13 @@ public PromptTemplateConfig(String template) { /** * 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 @@ -188,19 +189,9 @@ public KernelReturnParameterMetadata getKernelReturnParameterMetadata() { 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 +199,18 @@ public String getName() { 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. */ 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 +218,18 @@ public String getDescription() { 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 +237,9 @@ public OutputVariable getOutputVariable() { 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,18 +251,17 @@ public Map getExecutionSettings() { } /** - * 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. @@ -347,4 +274,152 @@ public static PromptTemplateConfig parseFromJson(String json) throws SKException } } + public Builder copy() { + return new Builder(this); + } + + public static Builder builder() { + return new Builder(); + } + + public static Builder defaultTemplateBuilder() { + return new Builder() + .withName(DEFAULT_CONFIG_NAME); + } + + 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() { + if (template == null) { + throw new SKException("Template is required"); + } + return new PromptTemplateConfig( + name, + template, + templateFormat, + description, + inputVariables, + outputVariable, + executionSettings); + } + } } 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 0799d44341a9..42b71a690a8c 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 @@ -15,13 +15,13 @@ */ 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 +62,7 @@ public ChatMessageContent( this.authorRole = authorRole; this.content = content; this.encoding = encoding != null ? encoding : StandardCharsets.UTF_8; + this.items = null; } /** @@ -97,15 +98,6 @@ public AuthorRole getAuthorRole() { 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 +109,6 @@ public String getContent() { 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 +118,6 @@ public List> getItems() { 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 +128,6 @@ public Charset getEncoding() { 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 8164a3c610b9..000000000000 --- 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; - } -} From 27ba747b2ec82bb1690a75ce80075e827b79dd47 Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:03:45 +0000 Subject: [PATCH 04/13] Apply linting fixes --- .../chatcompletion/OpenAIChatCompletion.java | 2 +- .../openai/chatcompletion/OpenAIFunction.java | 48 ++++++-- .../Example08_RetryHandler.java | 4 +- .../Example43_GetModelResult.java | 4 +- .../syntaxexamples/Example57_KernelHooks.java | 6 +- .../Example61_MultipleLLMs.java | 3 +- .../Example63_ChatCompletionPrompts.java | 3 +- .../exceptions/AIException.java | 61 +++++++--- .../exceptions/ConfigurationException.java | 38 ++++-- .../tokenizer/DefaultPromptTemplate.java | 24 +++- .../semanticfunctions/InputConfig.java | 15 ++- .../semanticfunctions/InputParameter.java | 11 +- .../semanticfunctions/KernelFunction.java | 4 +- .../KernelFunctionFromMethod.java | 61 +++++++++- .../KernelFunctionFromPrompt.java | 113 +----------------- .../KernelPromptTemplateFactory.java | 2 +- .../PromptTemplateConfig.java | 19 +++ .../services/AIServiceSupplier.java | 7 -- .../semantickernel/TemplateException.java | 3 + 19 files changed, 259 insertions(+), 169 deletions(-) delete mode 100644 java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSupplier.java 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 493416b1d681..8b3ac8c44f5d 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 @@ -110,7 +110,7 @@ private Mono>> internalChatMessageContentsAsync( 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/OpenAIFunction.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIFunction.java index bdb88ae31d00..6064e136d39c 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 @@ -9,20 +9,32 @@ 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 +50,8 @@ public FunctionDefinition getFunctionDefinition() { } /** - * 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 +71,8 @@ private static String getFullyQualifiedName( } /** - * 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 +111,7 @@ public static FunctionDefinition toFunctionDefinition(KernelFunctionMetadata } private static class OpenAIFunctionParameter { + @JsonProperty("type") private String type; @JsonProperty("required") @@ -104,17 +119,32 @@ private static class OpenAIFunctionParameter { @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/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 ad7c28375697..aceadfce6892 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 @@ -41,7 +41,9 @@ public static void main(String[] args) throws ConfigurationException { 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/Example43_GetModelResult.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example43_GetModelResult.java index a973ea6f9cf0..362ac5e2bd6f 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 @@ -52,8 +52,8 @@ public static void main(String[] args) { // 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/Example57_KernelHooks.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example57_KernelHooks.java index 763c24eef366..cfad72b15d48 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 @@ -288,8 +288,10 @@ private static void afterInvokeCancellationAsync(Kernel kernel) { 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/Example61_MultipleLLMs.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example61_MultipleLLMs.java index b61979221f83..0dfccce1873c 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 @@ -130,7 +130,8 @@ public static void runByFirstModelIdAsync(Kernel kernel, String... modelIds) { .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/Example63_ChatCompletionPrompts.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example63_ChatCompletionPrompts.java index 9388c88384d3..00f87860f6a1 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 @@ -49,7 +49,8 @@ public static void main(String[] args) throws InterruptedException { 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/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 ad4560ac405f..17416a5b6550 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 @@ 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 AIException(@Nonnull ErrorCodes error) { * 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 AIException(@Nonnull ErrorCodes errorCode, @Nullable String message) { /** * 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 ErrorCodes getErrorCode() { 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 8771ee4a3ddb..1784ee8249d3 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.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 ConfigurationException(@Nonnull ErrorCodes error) { /** * 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 ConfigurationException(@Nonnull ErrorCodes errorCode, @Nullable String me /** * 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 ConfigurationException( /** * Gets the error code. + * * @return the error code */ public ErrorCodes getErrorCode() { @@ -56,19 +62,29 @@ public ErrorCodes getErrorCode() { * 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 enum ErrorCodes { /** * Gets the message for the error code. + * * @return the message for the error code */ public String getMessage() { @@ -87,6 +104,7 @@ public String getMessage() { /** * 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/implementation/templateengine/tokenizer/DefaultPromptTemplate.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/DefaultPromptTemplate.java index 6d6db14a044a..2f2848428c12 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 @@ -16,6 +16,7 @@ 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; @@ -39,10 +40,25 @@ public class DefaultPromptTemplate implements PromptTemplate { * * @param promptTemplateConfig The prompt template configuration. */ - public DefaultPromptTemplate( - @Nonnull PromptTemplateConfig promptTemplateConfig) { - this.blocks = extractBlocks(promptTemplateConfig); - this.promptTemplateConfig = addMissingInputVariables(promptTemplateConfig, blocks); + 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); } /* 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 16ff4c8af256..556cf832f95d 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,27 @@ 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 6d290ff29da4..7238c1bd3390 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 @@ 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/KernelFunction.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunction.java index 5a0c50032464..171bd596a2d0 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 @@ * @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 { @@ -128,7 +128,7 @@ public KernelFunctionMetadata getMetadata() { *

* 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}. + * 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 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 9b7059f13714..64d6b951959b 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 @@ -22,6 +22,7 @@ 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; @@ -29,6 +30,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import javax.annotation.Nullable; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; @@ -576,10 +578,19 @@ private static KernelParameterMetadata toKernelParameterMetadata(Parameter pa 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<>(); } + /** + * A builder for {@link KernelFunction}. + */ public static class Builder { @Nullable @@ -597,41 +608,89 @@ public static class Builder { @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 c7435066e7ff..a9ff6dfaa823 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 @@ -2,9 +2,8 @@ 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 +12,11 @@ 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; @@ -70,60 +70,6 @@ private static String getName(PromptTemplateConfig promptConfig) { } } - /** - * Creates a new instance of {@link KernelFunctionFromPrompt} from a - * {@code PromptTemplateConfig}. - * - * @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( - 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); - } - private Flux> invokeInternalAsync( Kernel kernel, @Nullable KernelFunctionArguments argumentsIn, @@ -303,53 +249,6 @@ public Mono> invokeAsync( .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}. * @@ -527,8 +426,6 @@ public KernelFunction build() { 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/KernelPromptTemplateFactory.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelPromptTemplateFactory.java index 4fc33024c7c5..55c59c2bafc1 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 @@ -18,7 +18,7 @@ public class KernelPromptTemplateFactory implements PromptTemplateFactory { public PromptTemplate tryCreate(@Nonnull PromptTemplateConfig templateConfig) { 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/PromptTemplateConfig.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/PromptTemplateConfig.java index 935d0ba12f2a..1156fbd840fe 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 @@ -274,19 +274,38 @@ public static PromptTemplateConfig parseFromJson(String json) throws SKException } } + /** + * Create a builder for a prompt template config which is a clone of the current object. + * + * @return The prompt template config builder. + */ public Builder copy() { return new Builder(this); } + /** + * 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); } + /** + * Builder for a prompt template config. + */ public static class Builder { @Nullable 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 9a1dc6e596d6..000000000000 --- 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/templateengine/semantickernel/TemplateException.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/templateengine/semantickernel/TemplateException.java index c18ed8ae9141..0a60a4197698 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 @@ */ public class TemplateException extends SKException { + /** + * Error code. + */ @Nonnull private final ErrorCodes errorCode; From 93003e15def6dc8e9efa2c4a279113f1260fd6dd Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:18:24 +0000 Subject: [PATCH 05/13] Format --- .../com/microsoft/semantickernel/Kernel.java | 77 +++++--- .../KernelPluginCollection.java | 26 ++- .../semantickernel/builders/Buildable.java | 5 +- .../connectors/WebSearchEngineConnector.java | 26 ++- .../contextvariables/CaseInsensitiveMap.java | 2 + .../contextvariables/ContextVariable.java | 130 +++++++------ .../contextvariables/ContextVariableType.java | 2 +- .../ContextVariableTypeConverter.java | 164 ++++++++-------- .../ContextVariableTypes.java | 47 +++-- ...nVariableContextVariableTypeConverter.java | 8 +- ...rVariableContextVariableTypeConverter.java | 11 +- ...yVariableContextVariableTypeConverter.java | 14 +- ...tionUsageContextVariableTypeConverter.java | 6 +- .../DateTimeContextVariableTypeConverter.java | 9 +- .../InstantContextVariableTypeConverter.java | 9 +- ...rVariableContextVariableTypeConverter.java | 14 +- ...gVariableContextVariableTypeConverter.java | 8 +- ...dVariableContextVariableTypeConverter.java | 8 +- .../exceptions/SKCheckedException.java | 8 +- .../exceptions/SKException.java | 20 +- .../hooks/FunctionInvokedEvent.java | 9 +- .../hooks/FunctionInvokingEvent.java | 12 +- .../semantickernel/hooks/KernelHook.java | 32 ++-- .../hooks/PreChatCompletionEvent.java | 2 + .../hooks/PromptRenderedEvent.java | 8 +- .../hooks/PromptRenderingEvent.java | 5 +- .../EmbeddedResourceLoader.java | 42 ++--- .../implementation/ServiceLoadUtil.java | 11 +- .../semantickernel/implementation/Verify.java | 6 +- .../tokenizer/CodeTokenizer.java | 111 ++++++----- .../tokenizer/TemplateTokenizer.java | 84 ++++----- .../tokenizer/blocks/CodeBlock.java | 6 +- .../tokenizer/blocks/CodeRendering.java | 4 +- .../tokenizer/blocks/FunctionIdBlock.java | 17 +- .../tokenizer/blocks/NamedArgBlock.java | 66 +++---- .../tokenizer/blocks/TextBlock.java | 8 +- .../tokenizer/blocks/TextRendering.java | 1 + .../tokenizer/blocks/ValBlock.java | 12 +- .../tokenizer/blocks/VarBlock.java | 2 +- .../orchestration/FunctionInvocation.java | 177 ++++++++++-------- .../orchestration/FunctionResult.java | 6 +- .../orchestration/FunctionResultMetadata.java | 16 +- .../orchestration/InvocationContext.java | 88 +++++---- .../PromptExecutionSettings.java | 124 +++++++----- .../orchestration/ToolCallBehavior.java | 61 +++--- .../semantickernel/plugin/KernelPlugin.java | 15 +- .../plugin/KernelPluginFactory.java | 45 +++-- .../plugin/KernelReturnParameterMetadata.java | 3 +- .../semantickernel/plugin/Plugin.java | 4 +- .../AggregatorPromptTemplateFactory.java | 5 +- .../HandlebarsPromptTemplateFactory.java | 4 +- .../semanticfunctions/InputConfig.java | 1 + .../semanticfunctions/InputParameter.java | 4 +- .../semanticfunctions/InputVariable.java | 14 +- .../semanticfunctions/KernelFunction.java | 96 +++++----- .../KernelFunctionArguments.java | 27 +-- .../KernelFunctionFromMethod.java | 74 ++++---- .../KernelFunctionFromPrompt.java | 20 +- .../KernelFunctionMetadata.java | 13 +- .../semanticfunctions/KernelFunctionYaml.java | 26 +-- .../KernelParameterMetadata.java | 20 +- .../KernelPromptTemplateFactory.java | 4 +- .../semanticfunctions/MethodDetails.java | 5 + .../semanticfunctions/OutputVariable.java | 2 + .../semanticfunctions/PromptTemplate.java | 10 +- .../PromptTemplateConfig.java | 70 +++---- .../PromptTemplateFactory.java | 24 +-- .../annotations/DefineKernelFunction.java | 37 ++-- .../annotations/KernelFunctionParameter.java | 37 ++-- .../annotations/SKSample.java | 7 +- .../services/AIServiceSelection.java | 9 +- .../services/AIServiceSelector.java | 12 +- .../services/BaseAIServiceSelector.java | 21 ++- .../services/KernelContent.java | 14 +- .../services/NamedServiceProvider.java | 6 +- .../services/OrderedAIServiceSelector.java | 66 +++---- .../services/ServiceNotFoundException.java | 1 + .../services/StreamingKernelContent.java | 15 +- .../services/TextAIService.java | 29 +-- .../services/chatcompletion/AuthorRole.java | 14 +- .../chatcompletion/ChatCompletionService.java | 42 ++--- .../services/chatcompletion/ChatHistory.java | 12 +- .../chatcompletion/ChatMessageContent.java | 2 +- .../services/textcompletion/TextContent.java | 10 +- .../textcompletion/TextGenerationService.java | 27 +-- .../handlebars/HandlebarsPromptTemplate.java | 10 +- .../semantickernel/TemplateException.java | 3 + .../semantickernel/text/TextChunker.java | 22 +-- 88 files changed, 1305 insertions(+), 1081 deletions(-) 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 afbd6494f572..91bccb9ae648 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 @@ -5,12 +5,12 @@ import com.microsoft.semantickernel.builders.SemanticKernelBuilder; import com.microsoft.semantickernel.hooks.KernelHooks; import com.microsoft.semantickernel.orchestration.FunctionInvocation; -import com.microsoft.semantickernel.semanticfunctions.KernelFunction; import com.microsoft.semantickernel.plugin.KernelPlugin; +import com.microsoft.semantickernel.semanticfunctions.KernelFunction; 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 +35,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 +57,20 @@ public Kernel( 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 +87,8 @@ public FunctionInvocation invokeAsync( /** * 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 +98,9 @@ public FunctionInvocation invokeAsync(KernelFunction function) { } /** - * 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 +111,7 @@ public Kernel addPlugin(KernelPlugin plugin) { /** * 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 +122,7 @@ public KernelPlugin getPlugin(String pluginName) { /** * Gets the plugins that were added to the kernel. + * * @return The plugins available through the kernel (unmodifiable list). * @see Kernel#getPlugins() */ @@ -114,8 +132,9 @@ public Collection getPlugins() { /** * 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 +147,8 @@ public KernelFunction getFunction(String pluginName, String functionName) /** * 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 +158,12 @@ public List> getFunctions() { } /** - * 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 +172,7 @@ public KernelHooks getGlobalKernelHooks() { /** * 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 +181,13 @@ public AIServiceSelector getServiceSelector() { /** * 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, KernelFunctionArguments) */ public T getService(Class clazz) throws ServiceNotFoundException { AIServiceSelection selector = serviceSelector @@ -178,14 +203,6 @@ public T getService(Class clazz) throws ServiceNotFound 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 +215,9 @@ public static class Builder implements SemanticKernelBuilder { /** * 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 +228,7 @@ public Builder withAIService(Class clazz, T aiService) /** * Adds a plugin to the kernel. + * * @param plugin The plugin to add. * @return {@code this} builder with the plugin added. */ @@ -220,6 +239,7 @@ public Kernel.Builder withPlugin(KernelPlugin plugin) { /** * 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 +251,7 @@ public Kernel.Builder withServiceSelector( /** * 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 81f7485916a8..ec6904122a52 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,17 @@ 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 +23,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 +39,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 +61,7 @@ KernelFunction getFunction(String pluginName, String functionName) { /** * Gets all functions from all plugins. + * * @return A list of all functions from all plugins. */ List> getFunctions() { @@ -70,6 +72,7 @@ List> getFunctions() { /** * Gets all function metadata from all plugins. + * * @return A list of all function metadata from all plugins. */ List> getFunctionsMetadata() { @@ -81,6 +84,7 @@ List> getFunctionsMetadata() { /** * Gets all plugins that were added to the kernel. + * * @return The plugins available through the kernel. */ Collection getPlugins() { @@ -89,6 +93,7 @@ Collection getPlugins() { /** * 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 +103,9 @@ KernelPlugin getPlugin(String pluginName) { } /** - * 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 e92c299acc47..0f54dba6f715 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 768717216579..0d1bf8777f81 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 @@ * 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 783c2a9a28e6..daf78791cd79 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 @@ /** * 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 20b032bc841a..0b517c39698f 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 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 static ContextVariable convert( * 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, @@ -156,7 +159,7 @@ public static ContextVariable convert( /** * 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 static ContextVariable untypedOf( } /** - * 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 static ContextVariable of(CompletionsUsage x) { } /** - * 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 static ContextVariable of(OffsetDateTime x) { } /** - * 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 static ContextVariable of(String value) { } /** - * 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,8 +218,37 @@ public static ContextVariable ofGlobalType(Object x) { return ofValue(x); } + @SuppressWarnings("unchecked") + private static ContextVariable ofValue(T value) { + Objects.requireNonNull(value, "value cannot be null"); + + if (value instanceof ContextVariable) { + return (ContextVariable) value; + } + + ContextVariableType type = ContextVariableTypes.getGlobalVariableTypeForClass( + (Class) value.getClass()); + return new ContextVariable<>(type, value); + } + + /** + * Creates a new instance of the {@link ContextVariable} class. + * + * @param value the value + * @param converter the converter + * @param the type of the value + * @return the new instance + */ + public static ContextVariable of(T value, ContextVariableTypeConverter converter) { + Objects.requireNonNull(value, "value cannot be null"); + Objects.requireNonNull(converter, "converter cannot be null"); + ContextVariableType type = new ContextVariableType<>(converter, converter.getType()); + return new ContextVariable<>(type, value); + } + /** * Get the value of the context variable. + * * @return the value */ @Nullable @@ -223,8 +258,9 @@ public T getValue() { /** * Get the value of the context variable. + * * @param clazz the class - * @param the type of the value + * @param the type of the value * @return the value * @throws SKException if the value cannot be cast to the requested type */ @@ -240,6 +276,7 @@ public U getValue(Class clazz) { /** * Get the type of the context variable. + * * @return the type */ public ContextVariableType getType() { @@ -247,10 +284,10 @@ public ContextVariableType getType() { } /** - * 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. + * 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 */ @@ -259,46 +296,21 @@ public String toPromptString(ContextVariableTypeConverter converter) { } /** - * Use the convert of the type of this {@code ContextVariable} to convert - * the value of this {@code ContextVariable} to a prompt string. + * 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"); - - if (value instanceof ContextVariable) { - return (ContextVariable) value; - } - - ContextVariableType type = ContextVariableTypes.getGlobalVariableTypeForClass( - (Class) value.getClass()); - return new ContextVariable<>(type, value); - } - - /** - * Creates a new instance of the {@link ContextVariable} class. - * @param value the value - * @param converter the converter - * @param the type of the value - * @return the new instance - */ - public static ContextVariable of(T value, ContextVariableTypeConverter converter) { - Objects.requireNonNull(value, "value cannot be null"); - Objects.requireNonNull(converter, "converter cannot be null"); - ContextVariableType type = new ContextVariableType<>(converter, converter.getType()); - return new ContextVariable<>(type, value); - } } 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 6423737ed0fa..c8a8cc19002a 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 @@ -16,7 +16,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 9ee09ac46218..646e24519c8f 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 @@ -12,6 +12,7 @@ /** * 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 +26,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 +44,12 @@ public 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 +66,9 @@ public 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 +104,7 @@ public U toObject(@Nullable Object t, Class clazz) { /** * 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 */ @@ -180,6 +119,7 @@ public T fromObject(@Nullable Object 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 +133,7 @@ public String toPromptString(@Nullable T t) { /** * 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 +147,82 @@ public T fromPromptString(@Nullable String t) { /** * 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 e7ae2c9fe85b..a76dee946c5f 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,5 @@ 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; @@ -10,6 +9,7 @@ import com.microsoft.semantickernel.contextvariables.converters.NumberVariableContextVariableTypeConverter; import com.microsoft.semantickernel.contextvariables.converters.StringVariableContextVariableTypeConverter; 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; @@ -97,6 +97,7 @@ public ContextVariableTypes(ContextVariableTypes contextVariableTypes) { /** * Add a converter to the global collection of context variable type converters. + * * @param conveter The converter to add. * @see #getGlobalVariableTypeForClass(Class) */ @@ -107,8 +108,9 @@ public static void addGlobalConverter( /** * 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 +118,11 @@ public static ContextVariableType getGlobalVariableTypeForClass(Class 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 +140,24 @@ public static T convert(@Nullable Object s, Class clazz) { } } + /** + * 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 +171,11 @@ public ContextVariableType getVariableTypeForClass(Class aClass) { } /** - * 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 +228,7 @@ private ContextVariableType getVariableTypeForSuperClassInternal(Class /** * 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 eeca3d9963ae..4ec5183fe8cd 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 @@ -6,10 +6,10 @@ 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 02523ac7757b..fa0c479a8678 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 @@ -6,17 +6,18 @@ 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 b4532a36f5fb..289c92648eda 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 @@ -2,22 +2,24 @@ 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 f9d4e3ad44d9..9e5edcf4852d 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 @@ -5,10 +5,10 @@ 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 7416ad8eca47..dcba14a20ae5 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 @@ -2,17 +2,16 @@ 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 2eb492a881bd..ffb1c0846801 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 @@ -2,15 +2,14 @@ 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 bbdcdca6b6b6..eeb25abad9d9 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 @@ -4,15 +4,14 @@ 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. + * * @see ContextVariableTypes#getGlobalVariableTypeForClass(Class) */ public class NumberVariableContextVariableTypeConverter extends @@ -22,9 +21,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 0269f4be4147..5a2be484a506 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 @@ -6,10 +6,10 @@ 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/VoidVariableContextVariableTypeConverter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/converters/VoidVariableContextVariableTypeConverter.java index 59a4f945ee9f..0bae5f769980 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 @@ -4,10 +4,10 @@ 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/SKCheckedException.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/exceptions/SKCheckedException.java index 8119fde62c82..9506b41055e6 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 @@ 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 @@ protected SKCheckedException(@Nullable String message) { * {@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 @@ protected SKCheckedException(@Nullable String message, @Nullable Throwable cause * 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 1a637ffabe74..ee2f027bf703 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 @@ 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 SKException(@Nullable String message) { } /** - * 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 SKException(@Nullable String message, @Nullable Throwable cause) { * 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 e09714cb0705..65e4fd48a5c3 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 @@ -8,6 +8,7 @@ /** * 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 +20,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 +37,7 @@ public FunctionInvokedEvent( /** * Gets the function that was invoked. + * * @return the function */ public KernelFunction getFunction() { @@ -43,6 +46,7 @@ public KernelFunction getFunction() { /** * Gets the arguments that were passed to the function. + * * @return the arguments */ @SuppressFBWarnings("EI_EXPOSE_REP") @@ -53,6 +57,7 @@ public KernelFunctionArguments getArguments() { /** * 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 1c1f92a8b4d6..670d93c4cd45 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 @@ -6,9 +6,10 @@ 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 +19,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 +32,7 @@ public FunctionInvokingEvent(KernelFunction function, /** * Gets the function that is being invoked. + * * @return the function */ public KernelFunction getFunction() { @@ -38,6 +41,7 @@ public KernelFunction getFunction() { /** * 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 169fddc6a0f7..6139274f96c4 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 @@ -8,8 +8,9 @@ /** * 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 +18,8 @@ public interface KernelHook extends Predicate> { @@ -38,7 +39,7 @@ default boolean test(KernelHookEvent arguments) { } /** - * A hook that accepts {@link FunctionInvokedEvent} + * A hook that accepts {@link FunctionInvokedEvent} */ interface FunctionInvokedHook extends KernelHook> { @@ -49,7 +50,7 @@ default boolean test(KernelHookEvent arguments) { } /** - * A hook that accepts {@link PromptRenderingEvent} + * A hook that accepts {@link PromptRenderingEvent} */ interface PromptRenderingHook extends KernelHook { @@ -60,7 +61,7 @@ default boolean test(KernelHookEvent arguments) { } /** - * A hook that accepts {@link PromptRenderedEvent} + * A hook that accepts {@link PromptRenderedEvent} */ interface PromptRenderedHook extends KernelHook { @@ -71,18 +72,14 @@ default boolean test(KernelHookEvent arguments) { } /** - * A hook that accepts {@link PreChatCompletionEvent} + * A hook that accepts {@link PreChatCompletionEvent} */ interface PreChatCompletionHook extends KernelHook { - @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 +111,10 @@ static ChatCompletionsOptions cloneOptionsWithMessages( } return newOptions; } + + @Override + default boolean test(KernelHookEvent arguments) { + return PreChatCompletionEvent.class.isAssignableFrom(arguments.getClass()); + } } } diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PreChatCompletionEvent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PreChatCompletionEvent.java index f3f3589c5e9f..6977c550e5bf 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PreChatCompletionEvent.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PreChatCompletionEvent.java @@ -11,6 +11,7 @@ public class PreChatCompletionEvent implements KernelHookEvent { /** * Creates a new instance of the {@link PreChatCompletionEvent} class. + * * @param options the chat completion options */ public PreChatCompletionEvent(ChatCompletionsOptions options) { @@ -19,6 +20,7 @@ public PreChatCompletionEvent(ChatCompletionsOptions options) { /** * Gets the chat completion options. + * * @return the options */ public ChatCompletionsOptions getOptions() { diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderedEvent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderedEvent.java index 974d6cb07572..f9bc2c48241e 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderedEvent.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderedEvent.java @@ -16,9 +16,10 @@ public class PromptRenderedEvent implements KernelHookEvent { /** * Creates a new instance of the {@link PromptRenderedEvent} class. - * @param function the function + * + * @param function the function * @param arguments the arguments - * @param prompt the prompt + * @param prompt the prompt */ public PromptRenderedEvent( KernelFunction function, @@ -32,6 +33,7 @@ public PromptRenderedEvent( /** * Gets the function that was invoked. + * * @return the function */ public KernelFunction getFunction() { @@ -40,6 +42,7 @@ public KernelFunction getFunction() { /** * Gets the arguments that were passed to the function. + * * @return the arguments */ @SuppressFBWarnings("EI_EXPOSE_REP") @@ -49,6 +52,7 @@ public KernelFunctionArguments getArguments() { /** * Gets the prompt that was rendered. + * * @return the prompt */ @SuppressFBWarnings("EI_EXPOSE_REP") diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderingEvent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderingEvent.java index 1898852d6de6..a9f1058649a3 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderingEvent.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderingEvent.java @@ -15,7 +15,8 @@ public class PromptRenderingEvent implements KernelHookEvent { /** * Creates a new instance of the {@link PromptRenderingEvent} class. - * @param function the function + * + * @param function the function * @param arguments the arguments */ public PromptRenderingEvent(KernelFunction function, @@ -27,6 +28,7 @@ public PromptRenderingEvent(KernelFunction function, /** * Gets the function that was invoked. + * * @return the function */ public KernelFunction getFunction() { @@ -35,6 +37,7 @@ public KernelFunction getFunction() { /** * 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 29b7bc8817c8..3813068a3df4 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 @@ */ 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 static String readFile(String fileName, Class clazz) throws FileNotFou /** * 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 @@ private static String readInputStream(String fileName, InputStream inputStream) .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 fe5c7d335647..2f611e0d141f 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.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 @@ private 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) { 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 afe441310d40..6e6d002b3583 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 @@ 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 static void notNull(Object object) { /** * 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 static boolean isNullOrEmpty(@Nullable String s) { /** * 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 7f56277ee94e..b44ccc5f7a54 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 @@ 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 @@ /** * 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] + *

+ * 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 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 List tokenize(String text) { return blocks; } - 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); + private enum TokenTypes { + None(0), Value(1), Variable(2), FunctionId(3), NamedArg(4); - if (Verify.isNullOrEmpty(name) || Verify.isNullOrEmpty(value)) { - return null; - } - NamedArgBlock block = new NamedArgBlock(tokenContent, name, value); - if (block.isValid()) { - return block; + TokenTypes(int i) { } - - return null; } } 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 b1e95749c4c0..693009948453 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.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 */ @@ -185,24 +201,4 @@ else if (currentChar == Symbols.BlockEnder && nextChar == Symbols.BlockEnder) { 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 888194b5ff82..712866ee6b99 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; 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 ff597f3bea66..7a411a095639 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 305a0c632b83..25f58c42fdbd 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 @@ * 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 FunctionIdBlock(String content) { 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 boolean isValid() { 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 e2dac6e0cadd..caeee93663f6 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 @@ -79,6 +79,31 @@ public static NamedArgBlock from(String content) { 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 +131,14 @@ public String render(@Nullable KernelFunctionArguments variables) { 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 +163,4 @@ public String getValue(KernelFunctionArguments arguments) { 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 5ca24bf75426..006e902180a7 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 TextBlock(String text) { 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 boolean isValid() { 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 aadd1c865998..f59b1f79fcbb 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 f98f257cfe35..85199e8afdbe 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 ValBlock(String quotedValue) { this.value = this.getContent().substring(1, this.getContent().length() - 1); } + public static boolean hasValPrefix(@Nullable String text) { + return text != null + && text.length() > 0 + && (text.charAt(0) == Symbols.DblQuote || text.charAt(0) == Symbols.SglQuote); + } + @Override @Nullable public String render(@Nullable KernelFunctionArguments variables) { @@ -54,10 +60,4 @@ public boolean isValid() { 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 bb5a202afeb9..eedb03f79ae2 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 f7e5eca7c5b0..22a49e2a17b3 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 @@ -20,8 +20,9 @@ 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 +34,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 +43,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 +62,9 @@ public FunctionInvocation( /** * 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,8 +81,80 @@ public FunctionInvocation( this.addKernelHooks(kernel.getGlobalKernelHooks()); } + // Extracted to static to ensure mutable state is not used + private static void performSubscribe( + CoreSubscriber> coreSubscriber, + Kernel kernel, + KernelFunction function, + @Nullable KernelFunctionArguments arguments, + @Nullable ContextVariableType variableType, + @Nullable InvocationContext context) { + if (variableType == null) { + LOGGER.debug( + "No variable type explicitly specified by calling 'withResultType' for function invocation: " + + function.getPluginName() + "." + function.getName() + "." + + " This may cause a runtime error (probably a ClassCastException) if the result type is not compatible with the expected type."); + } + + function + .invokeAsync( + kernel, + new KernelFunctionArguments(arguments), + null, + new InvocationContext(context)) + .handle(convertToType(variableType)) + .subscribe(coreSubscriber); + } + + private static BiConsumer, SynchronousSink>> convertToType( + @Nullable ContextVariableType variableType) { + return (result, sink) -> { + // If a specific result type was requested, convert the result to that type. + if (variableType != null) { + try { + sink.next(new FunctionResult<>( + ContextVariable.convert(result.getResult(), variableType), + result.getMetadata())); + } catch (Exception e) { + sink.error(new SKException( + "Failed to convert result to requested type: " + + variableType.getClazz().getName(), + e)); + } + } else { + // Otherwise, just pass the result through and trust that the user requested the correct type. + sink.next((FunctionResult) result); + } + }; + } + + @Nullable + private static UnmodifiableToolCallBehavior unmodifiableClone( + @Nullable ToolCallBehavior toolCallBehavior) { + if (toolCallBehavior instanceof UnmodifiableToolCallBehavior) { + return (UnmodifiableToolCallBehavior) toolCallBehavior; + } else if (toolCallBehavior != null) { + return toolCallBehavior.unmodifiableClone(); + } else { + return null; + } + } + + @Nullable + private static UnmodifiableKernelHooks unmodifiableClone( + @Nullable KernelHooks kernelHooks) { + if (kernelHooks instanceof UnmodifiableKernelHooks) { + return (UnmodifiableKernelHooks) kernelHooks; + } else if (kernelHooks != null) { + return kernelHooks.unmodifiableClone(); + } else { + return null; + } + } + /** * Supply arguments to the function invocation. + * * @param arguments The arguments to supply to the function invocation. * @return this {@code FunctionInvocation} for fluent chaining. */ @@ -96,8 +170,9 @@ public FunctionInvocation withArguments( /** * 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. + * @param The type of the result of the function invocation. * @return A new {@code FunctionInvocation} for fluent chaining. */ public FunctionInvocation withResultType(ContextVariableType resultType) { @@ -113,6 +188,7 @@ public FunctionInvocation withResultType(ContextVariableType resultTyp /** * Add a kernel hook to the function invocation. + * * @param hook The kernel hook to add. * @return this {@code FunctionInvocation} for fluent chaining. */ @@ -128,6 +204,7 @@ public FunctionInvocation addKernelHook(@Nullable KernelHook hook) { /** * Add kernel hooks to the function invocation. + * * @param hooks The kernel hooks to add. * @return this {@code FunctionInvocation} for fluent chaining. */ @@ -142,7 +219,9 @@ public FunctionInvocation addKernelHooks( /** * Supply prompt execution settings to the function invocation. - * @param promptExecutionSettings The prompt execution settings to supply 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( @@ -153,6 +232,7 @@ public FunctionInvocation withPromptExecutionSettings( /** * 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. */ @@ -163,6 +243,7 @@ public FunctionInvocation withToolCallBehavior(@Nullable ToolCallBehavior too /** * 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. */ @@ -173,6 +254,7 @@ public FunctionInvocation withTypeConverter(ContextVariableType typeConver /** * 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. */ @@ -182,8 +264,9 @@ public FunctionInvocation withTypes(ContextVariableTypes contextVariableTypes } /** - * Use an invocation context variable to supply the types, tool call behavior, - * prompt execution settings, and kernel hooks to the function invocation. + * 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. */ @@ -200,7 +283,8 @@ public FunctionInvocation withInvocationContext( } /** - * This method hanldes the reactive stream when the KernelFunciton is invoked. + * This method hanldes the reactive stream when the KernelFunciton is invoked. + * * @param coreSubscriber The subscriber to subscribe to the function invocation. */ @Override @@ -218,75 +302,4 @@ public void subscribe(CoreSubscriber> coreSubscriber) contextVariableTypes)); } - // Extracted to static to ensure mutable state is not used - private static void performSubscribe( - CoreSubscriber> coreSubscriber, - Kernel kernel, - KernelFunction function, - @Nullable KernelFunctionArguments arguments, - @Nullable ContextVariableType variableType, - @Nullable InvocationContext context) { - if (variableType == null) { - LOGGER.debug( - "No variable type explicitly specified by calling 'withResultType' for function invocation: " - + function.getPluginName() + "." + function.getName() + "." - + " This may cause a runtime error (probably a ClassCastException) if the result type is not compatible with the expected type."); - } - - function - .invokeAsync( - kernel, - new KernelFunctionArguments(arguments), - null, - new InvocationContext(context)) - .handle(convertToType(variableType)) - .subscribe(coreSubscriber); - } - - private static BiConsumer, SynchronousSink>> convertToType( - @Nullable ContextVariableType variableType) { - return (result, sink) -> { - // If a specific result type was requested, convert the result to that type. - if (variableType != null) { - try { - sink.next(new FunctionResult<>( - ContextVariable.convert(result.getResult(), variableType), - result.getMetadata())); - } catch (Exception e) { - sink.error(new SKException( - "Failed to convert result to requested type: " - + variableType.getClazz().getName(), - e)); - } - } else { - // Otherwise, just pass the result through and trust that the user requested the correct type. - sink.next((FunctionResult) result); - } - }; - } - - @Nullable - private static UnmodifiableToolCallBehavior unmodifiableClone( - @Nullable ToolCallBehavior toolCallBehavior) { - if (toolCallBehavior instanceof UnmodifiableToolCallBehavior) { - return (UnmodifiableToolCallBehavior) toolCallBehavior; - } else if (toolCallBehavior != null) { - return toolCallBehavior.unmodifiableClone(); - } else { - return null; - } - } - - @Nullable - private static UnmodifiableKernelHooks unmodifiableClone( - @Nullable KernelHooks kernelHooks) { - if (kernelHooks instanceof UnmodifiableKernelHooks) { - return (UnmodifiableKernelHooks) kernelHooks; - } else if (kernelHooks != null) { - return kernelHooks.unmodifiableClone(); - } else { - return null; - } - } - } 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 dfb521862692..540d0919d955 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 @@ -39,9 +39,9 @@ public FunctionResult(ContextVariable of) { } /** - * Get the result of the function invocation. - * NOTE: If you get a ClassCastException from this method, - * try adding a result type with + * 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. 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 a5e7a00a5777..6e7dadf7f611 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 @@ -13,13 +13,19 @@ */ 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 +49,8 @@ public FunctionResultMetadata(CaseInsensitiveMap> metadata) { /** * 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 bb87903c5c8e..257986c8abdf 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 @@ -2,18 +2,18 @@ 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,8 +77,42 @@ public InvocationContext(@Nullable InvocationContext context) { } } + /** + * Create a new {@link Builder} for building an instance of {@code InvocationContext}. + * + * @return the new Builder. + */ + public static Builder builder() { + return new Builder(); + } + + @Nullable + private static UnmodifiableToolCallBehavior unmodifiableClone( + @Nullable ToolCallBehavior toolCallBehavior) { + if (toolCallBehavior instanceof UnmodifiableToolCallBehavior) { + return (UnmodifiableToolCallBehavior) toolCallBehavior; + } else if (toolCallBehavior != null) { + return toolCallBehavior.unmodifiableClone(); + } else { + return null; + } + } + + @Nullable + private static UnmodifiableKernelHooks unmodifiableClone( + @Nullable KernelHooks kernelHooks) { + if (kernelHooks instanceof UnmodifiableKernelHooks) { + return (UnmodifiableKernelHooks) kernelHooks; + } else if (kernelHooks != null) { + return kernelHooks.unmodifiableClone(); + } else { + return null; + } + } + /** * Get the hooks to use for the invocation. + * * @return The hooks to use for the invocation. */ @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "returns UnmodifiableKernelHooks") @@ -89,6 +123,7 @@ public UnmodifiableKernelHooks getKernelHooks() { /** * Get the settings for prompt execution. + * * @return The settings for prompt execution. */ @Nullable @@ -98,6 +133,7 @@ public PromptExecutionSettings getPromptExecutionSettings() { /** * Get the behavior for tool calls. + * * @return The behavior for tool calls. */ @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "returns UnmodifiableToolCallBehavior") @@ -108,62 +144,29 @@ public UnmodifiableToolCallBehavior getToolCallBehavior() { /** * 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() { - return new Builder(); - } - - @Nullable - private static UnmodifiableToolCallBehavior unmodifiableClone( - @Nullable ToolCallBehavior toolCallBehavior) { - if (toolCallBehavior instanceof UnmodifiableToolCallBehavior) { - return (UnmodifiableToolCallBehavior) toolCallBehavior; - } else if (toolCallBehavior != null) { - return toolCallBehavior.unmodifiableClone(); - } else { - return null; - } - } - - @Nullable - private static UnmodifiableKernelHooks unmodifiableClone( - @Nullable KernelHooks kernelHooks) { - if (kernelHooks instanceof UnmodifiableKernelHooks) { - return (UnmodifiableKernelHooks) kernelHooks; - } else if (kernelHooks != null) { - return kernelHooks.unmodifiableClone(); - } else { - return null; - } - } - /** * 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 +178,7 @@ public Builder withKernelHooks( /** * Add prompt execution settings to the builder. + * * @param promptExecutionSettings the settings to add. * @return this {@link Builder} */ @@ -186,6 +190,7 @@ public Builder withPromptExecutionSettings( /** * Add tool call behavior to the builder. + * * @param toolCallBehavior the behavior to add. * @return this {@link Builder} */ @@ -197,6 +202,7 @@ public Builder withToolCallBehavior( /** * 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 4bf7df4fc0b1..4d98d28e9b4d 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 @@ -52,17 +52,18 @@ public class PromptExecutionSettings { /** * 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 @@ -98,8 +99,29 @@ public PromptExecutionSettings( this.tokenSelectionBiases.replaceAll((k, v) -> clamp(v, -100, 100)); } + /** + * Create a new builder for PromptExecutionSettings. + * + * @return A new builder for PromptExecutionSettings. + */ + public static Builder builder() { + return new Builder(); + } + + 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)); + } + /** * 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 +131,7 @@ public String getServiceId() { /** * 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 +142,7 @@ public String getModelId() { /** * 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 +156,7 @@ public double getTemperature() { * 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 +165,10 @@ public double getTopP() { } /** - * 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 +177,9 @@ public double getPresencePenalty() { } /** - * 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 +189,7 @@ public double getFrequencyPenalty() { /** * 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 +198,8 @@ public int getMaxTokens() { } /** - * 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 +208,8 @@ public int getResultsPerPrompt() { } /** - * 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 +220,7 @@ public int getBestOf() { /** * The user to associate with the prompt execution. + * * @return The user to associate with the prompt execution. */ @JsonProperty(USER) @@ -200,6 +230,7 @@ public String getUser() { /** * The stop sequences to use for prompt execution. + * * @return The stop sequences to use for prompt execution. */ @JsonProperty(STOP_SEQUENCES) @@ -212,9 +243,10 @@ public List getStopSequences() { } /** - * 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 +258,6 @@ public Map getTokenSelectionBiases() { 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 +267,7 @@ public static class Builder { /** * 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 +278,7 @@ public Builder withServiceId(String serviceId) { /** * 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 +288,9 @@ public Builder withModelId(String modelId) { } /** - * 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 +304,7 @@ public Builder withTemperature(double temperature) { /** * 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 +318,7 @@ public Builder withTopP(double topP) { /** * 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 +332,7 @@ public Builder withPresencePenalty(double presencePenalty) { /** * 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 +346,7 @@ public Builder withFrequencyPenalty(double frequencyPenalty) { /** * 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 +356,9 @@ public Builder withMaxTokens(int maxTokens) { } /** - * 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 +368,9 @@ public Builder withResultsPerPrompt(int resultsPerPrompt) { } /** - * 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 +381,7 @@ public Builder withBestOf(int bestOf) { /** * Set the user to associate with the prompt execution. + * * @param user The user to associate with the prompt execution. * @return This builder. */ @@ -358,6 +392,7 @@ public Builder withUser(String user) { /** * Set the stop sequences to use for prompt execution. + * * @param stopSequences The stop sequences to use for prompt execution. * @return This builder. */ @@ -371,8 +406,9 @@ public Builder withStopSequences(List stopSequences) { } /** - * 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 +423,7 @@ public Builder withTokenSelectionBiases(Map tokenSelectionBias /** * Build the PromptExecutionSettings. + * * @return A new PromptExecutionSettings from this builder. */ @SuppressWarnings("unchecked") @@ -407,15 +444,4 @@ public PromptExecutionSettings build() { 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 4fd2c7903ef4..c5b8f5c4f16e 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 @@ -13,20 +13,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 +41,13 @@ public ToolCallBehavior(ToolCallBehavior 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 +118,6 @@ public ToolCallBehavior enableFunction(KernelFunction function, boolean enabl 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 +177,28 @@ public int getMaximumAutoInvokeAttempts() { 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 3ace22bd9944..fd70efd615ca 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,7 @@ 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 +20,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 +39,7 @@ public KernelPlugin( /** * Adds a function to the plugin. + * * @param function The function to add. */ public void addFunction(KernelFunction function) { @@ -46,6 +48,7 @@ public void addFunction(KernelFunction function) { /** * Gets the functions in the plugin. + * * @return The functions in the plugin. */ public Map> getFunctions() { @@ -54,8 +57,9 @@ public Map> getFunctions() { /** * 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 +70,7 @@ public KernelFunction get(String functionName) { /** * 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 +80,7 @@ public Iterator> iterator() { /** * Gets the name of the plugin. + * * @return The name of the plugin. */ public String getName() { @@ -83,6 +89,7 @@ public String getName() { /** * 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 1ec977f98b54..e7a7b50e2a72 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 @@ -33,9 +33,8 @@ 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 +43,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 +114,9 @@ private static Class getReturnType(DefineKernelFunction annotation, Method me /** * 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 +127,10 @@ public static KernelPlugin createFromFunctions( /** * 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 +162,9 @@ private static List> getParameters(Method method) { * 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. */ @@ -258,15 +262,16 @@ private static KernelFunction getKernelFunction( } /** - * 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 b76d669fdff2..8a24aa8322c5 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,6 @@ package com.microsoft.semantickernel.plugin; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; - import javax.annotation.Nullable; /** @@ -18,7 +17,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 50589412c07d..b2746ef004e1 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 Plugin(String name, KernelFunction... functions) { /** * 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 0c78715260f8..5a6da07ecddd 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 @@ -5,9 +5,8 @@ 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 8004f8cf1a03..25f62db0996b 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 @@ -5,8 +5,8 @@ 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 556cf832f95d..34e492e93736 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 @@ -25,6 +25,7 @@ public InputConfig(@JsonProperty("parameters") List parameters) /** * Gets the list of input parameters. + * * @return the list of input parameters */ public List getParameters() { 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 7238c1bd3390..7dbb23694a70 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 @@ -16,8 +16,8 @@ public class InputParameter { /** * Creates a new instance of the {@link InputParameter} class. * - * @param name name of the parameter - * @param description description of the parameter + * @param name name of the parameter + * @param description description of the parameter * @param defaultValue default value of the parameter */ @JsonCreator 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 14a7d1bd89dd..6162d7f53dcf 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 @@ -34,11 +34,11 @@ public InputVariable(String name) { /** * 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 +60,7 @@ public InputVariable( /** * Gets the name of the input variable. + * * @return the name of the input variable */ public String getName() { @@ -68,6 +69,7 @@ public String getName() { /** * Gets the type of the input variable. + * * @return the type of the input variable */ public String getType() { @@ -76,6 +78,7 @@ public String getType() { /** * Gets the description of the input variable. + * * @return the description of the input variable */ @Nullable @@ -85,6 +88,7 @@ public String getDescription() { /** * Gets the default value of the input variable. + * * @return the default value of the input variable */ @Nullable @@ -94,6 +98,7 @@ public String getDefaultValue() { /** * Gets whether the input variable is required. + * * @return whether the input variable is required */ public boolean isRequired() { @@ -102,6 +107,7 @@ public boolean isRequired() { /** * 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 171bd596a2d0..f3fcf4b29b5a 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 @@ -54,6 +54,51 @@ protected KernelFunction( } } + /** + * 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 KernelFunctionMetadata getMetadata() { * {@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 - * 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 FunctionInvocation invokeAsync(Kernel kernel) { 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 0bde8308d645..99d26764dfc4 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 @@ 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 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 KernelFunctionArguments() { this.variables = new CaseInsensitiveMap<>(); } + /** + * 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 @@ ContextVariable get(String key, Class clazz) { /** * Return whether the variable with the given name is {@code null} or empty. + * * @param key the key for the variable * @return {@code true} if the variable is {@code null} or empty, {@code false} otherwise */ @@ -187,15 +197,6 @@ public Set>> entrySet() { return variables.entrySet(); } - /** - * Create a new instance of Builder. - * - * @return Builder - */ - public static Builder builder() { - return new KernelFunctionArguments.Builder(); - } - /** * Builder for ContextVariables */ @@ -215,7 +216,7 @@ public Builder() { * Builds an instance with the given content in the default main key * * @param content Entry to place in the "input" slot - * @param 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 Builder withVariables(Map> map) { * * @param key variable name * @param value variable value - * @param 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/KernelFunctionFromMethod.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionFromMethod.java index 64d6b951959b..ff6a139c7fa6 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 @@ -19,6 +19,7 @@ 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; @@ -30,7 +31,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import javax.annotation.Nullable; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; @@ -67,41 +67,6 @@ private KernelFunctionFromMethod( 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. * @@ -294,7 +259,7 @@ private static ContextVariableType getContextVariableType( 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. } } @@ -588,6 +553,41 @@ 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}. */ 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 a9ff6dfaa823..5567d012d22f 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 @@ -70,6 +70,16 @@ private static String getName(PromptTemplateConfig promptConfig) { } } + /** + * 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<>(); + } + private Flux> invokeInternalAsync( Kernel kernel, @Nullable KernelFunctionArguments argumentsIn, @@ -249,16 +259,6 @@ public Mono> invokeAsync( .take(1).single(); } - /** - * 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. * 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 9cd9ac687138..c1827b00ce3d 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 @@ -24,10 +24,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 +50,7 @@ public KernelFunctionMetadata( /** * Get the name of the plugin to which the function belongs + * * @return The name of the function. */ @Nullable @@ -59,6 +60,7 @@ public String getPluginName() { /** * Get the name of the function. + * * @return The name of the function. */ public String getName() { @@ -67,6 +69,7 @@ public String getName() { /** * Get the parameters of the function. + * * @return The parameters of the function. */ public List> getParameters() { @@ -75,6 +78,7 @@ public List> getParameters() { /** * Get the description of the function. + * * @return The description of the function. */ @Nullable @@ -84,6 +88,7 @@ public String getDescription() { /** * 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 077657510257..899f6dbad80f 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 @@ -2,11 +2,6 @@ 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; @@ -16,15 +11,18 @@ 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 static KernelFunction fromPromptYaml( /** * 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 static KernelFunction fromPromptYaml( /** * 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. */ 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 1139f7517ffa..cc7d14be585a 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 @@ -3,9 +3,9 @@ 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 +20,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 +42,7 @@ public KernelParameterMetadata( /** * Gets the name of the parameter. + * * @return The name of the parameter. */ public String getName() { @@ -49,6 +51,7 @@ public String getName() { /** * Gets the description of the parameter. + * * @return The description of the parameter. */ @Nullable @@ -58,6 +61,7 @@ public String getDescription() { /** * Gets the default value of the parameter. + * * @return The default value of the parameter. */ @Nullable @@ -67,6 +71,7 @@ public String getDefaultValue() { /** * Gets whether the parameter is required. + * * @return Whether the parameter is required. */ public boolean isRequired() { @@ -75,6 +80,7 @@ public boolean isRequired() { /** * 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 55c59c2bafc1..07e864fbb5d4 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 @@ -9,8 +9,8 @@ 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 { 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 bdc391b61a94..0c9b54a41553 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 @@ -43,6 +43,7 @@ public MethodDetails( /** * Get the name of the method. + * * @return The name of the method. */ public String getName() { @@ -51,6 +52,7 @@ public String getName() { /** * Get the description of the method. + * * @return The description of the method. */ @Nullable @@ -60,6 +62,7 @@ public String getDescription() { /** * Get the function that implements the method. This is an internal detail. + * * @return The function that implements the method. */ public ImplementationFunc getFunction() { @@ -68,6 +71,7 @@ public ImplementationFunc getFunction() { /** * Get the parameters of the method. + * * @return The parameters of the method. */ public List> getParameters() { @@ -76,6 +80,7 @@ public List> getParameters() { /** * 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 a7c418b26ca3..13bc26d58d4a 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 @@ -32,6 +32,7 @@ public OutputVariable( /** * Get the description of the output variable. + * * @return The description of the output variable. */ @Nullable @@ -41,6 +42,7 @@ public String getDescription() { /** * 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 3c20cb056034..683daaccc13a 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 @@ 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 1156fbd840fe..ae7d026d9984 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 @@ -155,6 +155,41 @@ public PromptTemplateConfig(PromptTemplateConfig promptTemplate) { 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. * @@ -259,21 +294,6 @@ 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. - */ - 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 which is a clone of the current object. * @@ -283,26 +303,6 @@ public Builder copy() { return new Builder(this); } - /** - * 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); - } - /** * Builder for a prompt template config. */ 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 c76134618403..41f793a11f6b 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 @@ -3,39 +3,39 @@ 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}. + * 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. * @return The prompt template. * @throws UnknownTemplateFormatException If the template format is not supported. * @see PromptTemplateConfig#getTemplateFormat() */ - PromptTemplate tryCreate(PromptTemplateConfig templateConfig); + static PromptTemplate build(PromptTemplateConfig templateConfig) { + return new KernelPromptTemplateFactory().tryCreate(templateConfig); + } /** - * Create a prompt template, if possible, from the given configuration. - * This is a convenience method that wraps the - * {@link KernelPromptTemplateFactory#tryCreate(PromptTemplateConfig)} - * method. + * 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() */ - static PromptTemplate build(PromptTemplateConfig templateConfig) { - return new KernelPromptTemplateFactory().tryCreate(templateConfig); - } + 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 84a4422639da..74d933af96ab 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.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 cfd7e6fd9f04..ad212f394be1 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 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 or not 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 b2ed7433ac75..5b3f5ea388b4 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.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 @@
 @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/AIServiceSelection.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/AIServiceSelection.java
index bd15df16c9b2..8e139b8721e4 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 @@
 
 /**
  * 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 T getService() {
     /**
      * 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 8302494295c5..3255d79e0af6 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/BaseAIServiceSelector.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/BaseAIServiceSelector.java
index 55cf8ddf6bb9..9d29c5f84e7f 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
@@ -6,10 +6,10 @@
 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,15 +35,16 @@ public  AIServiceSelection trySelectAIService(
     }
 
     /**
-     * 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.
+     * @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
      */
     @Nullable
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 0d886691fbdf..2eea41b5890b 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
@@ -5,7 +5,8 @@
 
 /**
  * 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 +18,7 @@ public abstract class KernelContent {
     @Nullable
     private final T innerContent;
 
-    /** 
+    /**
      * The model ID used to generate the content.
      */
     @Nullable
@@ -31,9 +32,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 +48,7 @@ public KernelContent(
 
     /**
      * Gets the inner content representation.
+     *
      * @return The inner content representation.
      */
     @Nullable
@@ -55,6 +58,7 @@ public T getInnerContent() {
 
     /**
      * Gets the model identifier used to generate the content.
+     *
      * @return The model identifier used to generate the content.
      */
     @Nullable
@@ -64,6 +68,7 @@ public String getModelId() {
 
     /**
      * Gets the metadata associated with the content.
+     *
      * @return The metadata associated with the content.
      */
     @Nullable
@@ -73,6 +78,7 @@ public FunctionResultMetadata getMetadata() {
 
     /**
      * 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 9e50965b5f4d..8745f054de12 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 @@
 
 /**
  * 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 e8ee798afbc7..39b136a75115 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,10 @@
 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 +15,26 @@
 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 +42,28 @@ public OrderedAIServiceSelector(AIServiceCollection services) {
         super(services);
     }
 
+    @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;
+    }
+
     @Nullable
     @Override
     public  AIServiceSelection trySelectAIService(
@@ -136,28 +158,6 @@ public  AIServiceSelection trySelectAIService(
         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 +188,7 @@ public AIService getService(String serviceId) {
      * 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 7046109ddac3..f4c2be7abe9c 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
@@ -9,6 +9,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 0b05ff05eeae..c42222efb522 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
@@ -6,22 +6,24 @@
 
 /**
  * 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 +36,7 @@ protected StreamingKernelContent(
 
     /**
      * 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 6914e48bf0be..09b3ea1fe544 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 6a1e76a61c85..745a1050f898 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 @@ */ 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 e65495ba48ad..aa7c71c2f8ac 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 @@ 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 @@ 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 @@ Mono>> getChatMessageContentsAsync( /** * 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 @@ Mono>> getChatMessageContentsAsync( @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 43271069ce60..5ac4bc91eea4 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 Spliterator> spliterator() { * 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 void addMessage(AuthorRole authorRole, String content, Charset encoding, * 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 42b71a690a8c..c560cbee674f 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; 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 b734f1e2f7ed..b8c9e56a7796 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,7 @@ 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 +11,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 +28,7 @@ public TextContent( /** * 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 313f393e54d4..6ba5e4f4506f 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 @@ 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 @@ */ 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 @@ Mono> getTextContentsAsync( * @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 @@ Flux getStreamingTextContentsAsync( @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 82e6a563fe40..17d901d9da40 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,16 @@ 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.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; 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 0a60a4197698..6c5779b42e03 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 @@ -57,6 +57,7 @@ public TemplateException( /** * Gets the error code for this exception. + * * @return The error code. */ //spotless:on @@ -113,8 +114,10 @@ public enum ErrorCodes { } // 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 92659a71f50e..7ed3e8c0b09d 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 @@ -166,17 +166,6 @@ && TokenCount(currentParagraph.length()) + TokenCount(line.length()) 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 @@ private static int TokenCount(int inputLength) { // 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; + } + } } From 36292224ab6b0140ad76dfb62ce92539a981088a Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Tue, 20 Feb 2024 16:48:11 +0000 Subject: [PATCH 06/13] Apply code fix suggestions --- .../syntaxexamples/Example69_MutableKernelPlugin.java | 1 + .../main/java/com/microsoft/semantickernel/Kernel.java | 5 ++++- .../NumberVariableContextVariableTypeConverter.java | 1 + .../semantickernel/implementation/ServiceLoadUtil.java | 2 +- .../templateengine/tokenizer/CodeTokenizer.java | 6 +++--- .../templateengine/tokenizer/DefaultPromptTemplate.java | 2 +- .../templateengine/tokenizer/TemplateTokenizer.java | 8 ++++---- .../templateengine/tokenizer/blocks/CodeBlock.java | 2 +- .../templateengine/tokenizer/blocks/ValBlock.java | 2 +- .../semantickernel/orchestration/FunctionResult.java | 5 +++-- .../annotations/KernelFunctionParameter.java | 8 ++++---- .../semantickernel/services/BaseAIServiceSelector.java | 2 +- .../semantickernel/services/OrderedAIServiceSelector.java | 2 +- .../services/chatcompletion/ChatMessageContent.java | 2 ++ .../com/microsoft/semantickernel/text/TextChunker.java | 6 +++--- 15 files changed, 31 insertions(+), 23 deletions(-) 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 8a4bc0f46248..196fd56d4862 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 @@ -31,6 +31,7 @@ public static void main(String[] args) throws NoSuchMethodException { .build()); Kernel kernel = Kernel.builder().build(); + kernel.addPlugin(plugin); var result = kernel.invokeAsync(kernel.getFunction("Plugin", "dateFunction")) 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 91bccb9ae648..f2a7477cef8e 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,10 +3,13 @@ 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.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; @@ -187,7 +190,7 @@ public AIServiceSelector getServiceSelector() { * @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) + * KernelFunction, com.microsoft.semantickernel.semanticfunctions.KernelFunctionArguments) */ public T getService(Class clazz) throws ServiceNotFoundException { AIServiceSelection selector = serviceSelector 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 eeb25abad9d9..a1cdba3bdb35 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 @@ -12,6 +12,7 @@ * 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 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 2f611e0d141f..ede54246215d 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 @@ -36,7 +36,7 @@ public static Supplier findServiceLoader(Class clazz, String alternati 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/templateengine/tokenizer/CodeTokenizer.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/CodeTokenizer.java index b44ccc5f7a54..3fad53bfc17b 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 @@ -19,9 +19,9 @@ * 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 + * ::= [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] ::= "'" 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 2f2848428c12..9c785db23b08 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 @@ -90,7 +90,7 @@ private static List extractBlocks(PromptTemplateConfig promptTemplateConf * referenced in the prompt template. * * @param blocks The blocks to search for input variables. - * @return + * @return The augmented prompt template. */ @SuppressWarnings("NullAway") private static PromptTemplateConfig addMissingInputVariables( 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 693009948453..d0a1653880e5 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 @@ -14,9 +14,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 + * ::= [sk-block] | [text-block] [sk-block] ::= "{{" [variable] "}}" | "{{" [value] "}}" | + * "{{" [function-call] "}}" [text-block] ::= [any-char] | [any-char] [text-block] [any-char] + * ::= any char *

* /// Example using a function to return the result of another inner function * /// - * + * * @DefineKernelFunction(name = "InputStringTaskWithVoidResult") * public FunctionResult NoInputWithFunctionResult() * { @@ -484,7 +502,7 @@ public OffsetDateTime conversionScenarioB() { */ /* - * + * * /// * /// Example using a task function to return the result of another kernel function * /// @@ -498,7 +516,7 @@ public OffsetDateTime conversionScenarioB() { * ); * return result; * } - * + * * /// * /// Example how to inject Kernel in your function * /// This example uses the injected kernel to invoke a plugin from within another function @@ -515,7 +533,7 @@ public OffsetDateTime conversionScenarioB() { * ); * return summary!; * } - * + * * /// * /// Example how to inject the executing KernelFunction as a parameter * /// @@ -530,7 +548,7 @@ public OffsetDateTime conversionScenarioB() { * ); * return result; * } - * + * * /// * /// Example how to inject ILogger in your function * /// @@ -544,7 +562,7 @@ public OffsetDateTime conversionScenarioB() { * ); * return Task.CompletedTask; * } - * + * * /// * /// Example how to inject ILoggerFactory in your function * /// @@ -555,13 +573,13 @@ public OffsetDateTime conversionScenarioB() { * .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 * /// @@ -576,14 +594,14 @@ public OffsetDateTime conversionScenarioB() { * 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 * /// @@ -599,7 +617,7 @@ public OffsetDateTime conversionScenarioB() { * ); * return result; * } - * + * * /// * /// Example how to inject current CancellationToken in your function * /// @@ -613,12 +631,12 @@ public OffsetDateTime conversionScenarioB() { * ); * 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/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 000000000000..05e12e105d7b --- /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 000000000000..fc5ecd88f34e --- /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 000000000000..88bc4d7c3112 --- /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 56e9f20da19c..df1cec0f3c8a 100644 --- a/java/semantickernel-api/pom.xml +++ b/java/semantickernel-api/pom.xml @@ -66,5 +66,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/contextvariables/ContextVariableTypeConverter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/contextvariables/ContextVariableTypeConverter.java index b93bbfb325d2..139a19986edd 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 @@ -114,6 +114,9 @@ public T fromObject(@Nullable Object s) { if (s == null) { return null; } + if (s instanceof ContextVariable) { + return fromObject.apply(((ContextVariable) s).getValue()); + } return fromObject.apply(s); } 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 fa7c2013a0ed..4b4ed52bc170 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 @@ -9,6 +9,7 @@ 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; @@ -29,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), 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 000000000000..f38d33476118 --- /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/orchestration/FunctionInvocation.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionInvocation.java index dbff8e366cd2..350e775a250f 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 @@ -4,6 +4,7 @@ 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; @@ -248,8 +249,8 @@ public FunctionInvocation withToolCallBehavior(@Nullable ToolCallBehavior too * @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()); + public FunctionInvocation withTypeConverter(ContextVariableTypeConverter typeConverter) { + contextVariableTypes.putConverter(typeConverter); return this; } 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 9d5df4ee30b0..96ff677ee872 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 @@ -16,13 +16,13 @@ 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"; @@ -49,7 +49,7 @@ 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. @@ -71,13 +71,13 @@ public class PromptExecutionSettings { 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) { @@ -87,17 +87,17 @@ public 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)); } /** @@ -109,15 +109,17 @@ public static Builder builder() { return new Builder(); } - private static double clamp(double value, double min, double max, double defaultValue) { - if (Double.isNaN(value)) { + private static T clamp(T value, T min, T max, T defaultValue) { + if (value == null) { 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)); + if (value.doubleValue() < min.doubleValue()) { + return min; + } + if (value.doubleValue() > max.doubleValue()) { + return max; + } + return value; } /** @@ -432,13 +434,13 @@ public PromptExecutionSettings build() { 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, 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 7d9940811967..aeec1ca6ebcc 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 @@ -255,7 +255,6 @@ public Mono> invokeAsync( @Nullable KernelFunctionArguments arguments, @Nullable ContextVariableType variableType, @Nullable InvocationContext invocationContext) { - return invokeInternalAsync(kernel, arguments, variableType, invocationContext) .take(1).single(); } @@ -411,10 +410,6 @@ public KernelFunction build() { executionSettings); } - if (template == null) { - throw new IllegalStateException("Template must be provided"); - } - PromptTemplateConfig config = new PromptTemplateConfig( name, template, 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 48bc3370e959..7f1cabe86f09 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 @@ -74,7 +74,7 @@ private static KernelFunction fromYaml( 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/OutputVariable.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/OutputVariable.java index 45f920933b90..b67f3be851cc 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 @@ -26,8 +26,11 @@ 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; } 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 index a38acd949836..81ca99f9cdbe 100644 --- 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 @@ -6,6 +6,7 @@ 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; @@ -46,9 +47,9 @@ public Stream testConvertIntegerToString() { new TestCase<>("IntegerToNumber", Integer.class, Number.class, 100), new TestCase<>("StringToDate", String.class, OffsetDateTime.class, - ZonedDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)), + ZonedDateTime.now(ZoneId.systemDefault()).format(DateTimeFormatter.ISO_DATE_TIME)), new TestCase<>("DateToString", OffsetDateTime.class, String.class, - OffsetDateTime.now())) + OffsetDateTime.now(ZoneId.systemDefault()))) .map(s -> DynamicTest.dynamicTest(s.name, () -> { Assertions.assertNotNull(ContextVariable.ofGlobalType(s.object)); Assertions.assertNotNull(ContextVariable.ofGlobalType(s.object).getValue()); From bae2a895871cbcb39ec49a39975219d901062f39 Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Thu, 22 Feb 2024 13:30:48 +0000 Subject: [PATCH 13/13] More code formatting --- java/api-test/integration-tests/pom.xml | 3 +- .../tests/Example03_ArgumentsTest.java | 2 +- ...xample05_InlineFunctionDefinitionTest.java | 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 +- java/pom.xml | 5 +- java/samples/pom.xml | 7 +- java/samples/sample-code/pom.xml | 3 +- .../plugins/ConversationSummaryPlugin.java | 46 ++++++------- .../syntaxexamples/Example03_Arguments.java | 34 +++++----- .../Example05_InlineFunctionDefinition.java | 2 +- .../Example06_TemplateLanguage.java | 30 ++++----- .../Example07_BingAndGooglePlugins.java | 14 ++-- .../Example09_FunctionTypes.java | 64 +++++++++---------- ...mple10_DescribeAllPluginsAndFunctions.java | 40 ++++++------ .../Example11_WebSearchQueries.java | 2 +- .../Example13_ConversationSummaryPlugin.java | 5 +- .../syntaxexamples/Example26_AADAuth.java | 2 +- ...Example27_PromptFunctionsUsingChatGPT.java | 4 +- .../Example30_ChatWithPrompts.java | 6 +- .../Example42_KernelBuilder.java | 2 +- .../Example43_GetModelResult.java | 2 +- .../Example44_MultiChatCompletion.java | 4 +- .../syntaxexamples/Example49_LogitBias.java | 4 +- ...eMethodFunctionsWithMultipleArguments.java | 4 +- .../syntaxexamples/Example57_KernelHooks.java | 6 +- .../Example58_ConfigureExecutionSettings.java | 4 +- .../Example59_OpenAIFunctionCalling.java | 63 +++++++++--------- .../Example60_AdvancedMethodFunctions.java | 2 +- .../Example62_CustomAIServiceSelector.java | 6 +- .../Example63_ChatCompletionPrompts.java | 2 +- .../Example64_MultiplePromptTemplates.java | 4 +- .../Example69_MutableKernelPlugin.java | 18 +++--- .../samples/syntaxexamples/RunAll.java | 10 +-- java/semantickernel-api/pom.xml | 3 +- .../semanticfunctions/KernelFunctionYaml.java | 1 - .../ContextVariableTypeConverterTest.java | 30 ++++----- java/semantickernel-bom/pom.xml | 3 +- 74 files changed, 1035 insertions(+), 1027 deletions(-) diff --git a/java/api-test/integration-tests/pom.xml b/java/api-test/integration-tests/pom.xml index 381e68e863b4..ce789b633105 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/tests/Example03_ArgumentsTest.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example03_ArgumentsTest.java index 2fa953effac5..de86e82f8c3f 100644 --- a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example03_ArgumentsTest.java +++ b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example03_ArgumentsTest.java @@ -3,10 +3,10 @@ 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/tests/Example05_InlineFunctionDefinitionTest.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example05_InlineFunctionDefinitionTest.java index 028973a74e1a..135a927f36c2 100644 --- a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example05_InlineFunctionDefinitionTest.java +++ b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/Example05_InlineFunctionDefinitionTest.java @@ -7,9 +7,9 @@ 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/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 86f3280d54ce..7026d494b6f1 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 8585ebb647eb..1723fddb0585 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 1267c7cd2ded..dd6f49b4c003 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 70cf03797ca6..7ff593b41687 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 cb7cd5e564fc..03befd18ef3c 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 22ef9679a8f5..8c045a025133 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 43bda291170e..363c24b77b98 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 d5394f0805c7..a1405211313a 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 7555075aa165..f7d797c81284 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 550924807ca4..07c34adc1ceb 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 08b6b22e69bb..ffec06181e03 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 a31f9d20b682..d89da3ea5494 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 35eef27ea856..d11164484713 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 fd64876e3762..17c74af8bd74 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 885e448446d6..f04494d6ad58 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 9c6426445967..8b839fd51b0e 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 d61f14e096cb..ff6af76b9f38 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 d3f82e5c188f..a5a05ec53c3b 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 5115cc110091..2883487c7ade 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 239aeb483fa5..e4985753bce6 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 6664521ab306..36bd24780def 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 b5ac6375fcfb..e3415ef52213 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 746e3e574862..ca3f68c04a67 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 34c657cee5de..ea296f3757e0 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 08b36b629ee8..46455db79b7f 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 2e05edad2b0e..486a8b19cbf4 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 7decc7282d86..d2042ae32343 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 c99bd97f30c9..8422dfec0ea8 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 f57d5e139d82..a47a658d5d81 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 904b360fbd43..21d76e6f02a5 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 eb5f4529520a..ea2b259780ba 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 773a1f60bc8c..348670d755bd 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 894208d1fea7..ae05b7c2f238 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 8f94812356d1..dec6a7087200 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 43a478e7c7f1..22d1bb82c94d 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 99b6a95e6006..ef8e9a60abdc 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 3156d090ae57..73ef9f552e52 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 69bb8b8c3fe3..db7842b0dee9 100644 --- a/java/api-test/pom.xml +++ b/java/api-test/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 diff --git a/java/pom.xml b/java/pom.xml index 5514cb98ec9d..496bbfbd6eee 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 @@ -666,7 +667,7 @@ // Copyright (c) Microsoft. All rights reserved. - + diff --git a/java/samples/pom.xml b/java/samples/pom.xml index 540edd4b33c5..cdda4c498966 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 21efb67c9b34..118d40bf8acf 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 f72d15bae098..089a4941ee51 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 @@ -2,10 +2,10 @@ 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; @@ -61,6 +61,27 @@ public 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. /// @@ -97,25 +118,4 @@ public Mono GetConversationTopicsAsync( 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/syntaxexamples/Example03_Arguments.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example03_Arguments.java index d6fab4495f75..dbca6fd24e15 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 @@ 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 @@ */ 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 static void main(String[] args) { 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 c70882f233f6..bce940b69a0a 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.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 32e8f6522a07..4d5aa71aaecd 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 @@ -8,13 +8,13 @@ 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 { @@ -27,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 ========"); @@ -105,4 +92,17 @@ Is it weekend time (weekend/not weekend)? 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 b859124bbf94..66c2826310b7 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.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 @@ private static void example1Async(Kernel kernel, String searchPluginName) { /* * 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 @@ private static void example2Async(Kernel kernel) { /* * 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 @@ private static void example2Async(Kernel kernel) { * 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/Example09_FunctionTypes.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example09_FunctionTypes.java index e71cbe1ab12c..2ee6e2888360 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 @@ -44,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 ========"); @@ -338,6 +306,38 @@ public String toString() { .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 { /// 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 8adbbdb2db8a..9b9ffd564182 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 @@ -7,14 +7,14 @@ 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.semanticfunctions.annotations.DefineKernelFunction; -import com.microsoft.semantickernel.semanticfunctions.annotations.KernelFunctionParameter; 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.services.textcompletion.TextGenerationService; import java.nio.file.Path; import java.util.Locale; @@ -31,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. @@ -144,4 +128,20 @@ private static void printFunction(KernelFunctionMetadata func) { 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 e38cba46c8b9..6796a7790eb2 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 @@ -2,9 +2,9 @@ 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 84f52e47edd2..78291333b128 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.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/Example26_AADAuth.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example26_AADAuth.java index 6dcf9fc04262..59c607308e00 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 @@ -6,9 +6,9 @@ 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 ea195698d99b..f126aca8041a 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 @@ -6,10 +6,10 @@ 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 a782b1aa7428..5830afce7a10 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 @@ -6,16 +6,16 @@ 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/Example42_KernelBuilder.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example42_KernelBuilder.java index 9a77ece61f43..ddbe5deb5b61 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 @@ -7,10 +7,10 @@ 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 373a97a2c3ff..9d2f371c1f96 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 @@ -7,11 +7,11 @@ 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 { 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 f5d60c72577f..5384291eee6c 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 @@ -6,10 +6,10 @@ 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 3aca0f0dfcea..6d961b9ede0e 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 @@ -6,10 +6,10 @@ 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/Example56_TemplateMethodFunctionsWithMultipleArguments.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example56_TemplateMethodFunctionsWithMultipleArguments.java index edff095baa59..24929e7e9bb9 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 @@ -7,14 +7,14 @@ 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 2a0c6bef8d38..309cbd6d9047 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 @@ -11,7 +11,7 @@ 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; @@ -22,11 +22,11 @@ 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; 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 75451e337664..0315e60fbaf9 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 @@ -7,12 +7,12 @@ 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 { 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 ae56d279b134..76bf55927c28 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 @@ -7,16 +7,16 @@ 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 { @@ -28,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 ========"); @@ -157,4 +130,32 @@ public static void requireFunction(Kernel kernel, KernelPlugin plugin, 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 91d2d7bbf83f..4e7eaac0797d 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 @@ -2,10 +2,10 @@ 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/Example62_CustomAIServiceSelector.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example62_CustomAIServiceSelector.java index 1999859dd093..be296705f576 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 @@ -6,15 +6,15 @@ 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 d775b1f789c3..89006440da7e 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 @@ -6,8 +6,8 @@ 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 { 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 cb79b7792ca7..28fe19d821a9 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 @@ -7,13 +7,13 @@ 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/Example69_MutableKernelPlugin.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example69_MutableKernelPlugin.java index 00be59cf43c0..4200a1688e28 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 @@ -2,20 +2,12 @@ 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 *

@@ -40,4 +32,12 @@ public static void main(String[] args) throws NoSuchMethodException { 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 793ec2ad8ac5..81b933f37705 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 @@ -14,11 +14,6 @@ */ 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, @@ -65,4 +60,9 @@ public static void main(String[] args) { } }); } + + public interface MainMethod { + + void run(String[] args) throws Exception; + } } diff --git a/java/semantickernel-api/pom.xml b/java/semantickernel-api/pom.xml index df1cec0f3c8a..84ed2305d091 100644 --- a/java/semantickernel-api/pom.xml +++ b/java/semantickernel-api/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 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 7f1cabe86f09..0e14fb7073a8 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 @@ -3,7 +3,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.microsoft.semantickernel.templateengine.handlebars.HandlebarsPromptTemplate; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; 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 index 81ca99f9cdbe..1b479753d290 100644 --- 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 @@ -16,21 +16,6 @@ public class ContextVariableTypeConverterTest { - 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; - } - } - @TestFactory public Stream testConvertIntegerToString() { return Stream.of( @@ -66,4 +51,19 @@ public Stream testConvertIntegerToString() { } + 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-bom/pom.xml b/java/semantickernel-bom/pom.xml index e5ae859bb0ff..46861867f7bc 100644 --- a/java/semantickernel-bom/pom.xml +++ b/java/semantickernel-bom/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 com.microsoft.semantic-kernel

* BNF parsed by CodeTokenizer: [template] ::= "" | [variable] " " [template] | [value] " " * [template] | [function-call] " @@ -142,7 +142,7 @@ else if (currentChar == Symbols.BlockEnder && nextChar == Symbols.BlockEnder) { .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 { 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 712866ee6b99..ac81c2edfaf6 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 @@ -47,7 +47,7 @@ public boolean isValid() { 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/ValBlock.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/ValBlock.java index 85199e8afdbe..b251b6bb4e3f 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 @@ -32,7 +32,7 @@ public ValBlock(String quotedValue) { public static boolean hasValPrefix(@Nullable String text) { return text != null - && text.length() > 0 + && !text.isEmpty() && (text.charAt(0) == Symbols.DblQuote || text.charAt(0) == Symbols.SglQuote); } 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 540d0919d955..53d37a4f365a 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,7 @@ package com.microsoft.semantickernel.orchestration; import com.microsoft.semantickernel.contextvariables.ContextVariable; +import com.microsoft.semantickernel.contextvariables.ContextVariableType; import javax.annotation.Nullable; /** @@ -41,8 +42,8 @@ public FunctionResult(ContextVariable of) { /** * 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)} + * 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/semanticfunctions/annotations/KernelFunctionParameter.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/annotations/KernelFunctionParameter.java index ad212f394be1..25bbe83cdee3 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 @@ -38,15 +38,15 @@ * 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. + * @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. + * 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. */ 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 9d29c5f84e7f..24ac21a4449c 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 @@ -45,7 +45,7 @@ public AIServiceSelection trySelectAIService( * {@code null}. * @param services The services to select from. * @param The type of service to select. - * @return + * @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/OrderedAIServiceSelector.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/OrderedAIServiceSelector.java index 39b136a75115..8d14d1f4b733 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 @@ -50,7 +50,7 @@ private static AIServiceSelection castServiceSelection( // unchecked cast return (AIServiceSelection) selection; } catch (ClassCastException e) { - LOGGER.debug("%s", e.getMessage()); + LOGGER.debug("{}", e.getMessage()); return null; } } 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 c560cbee674f..c75c8d2edafb 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 @@ -12,6 +12,8 @@ /** * Represents the content of a chat message + * + * @param the type of the inner content within the messages */ public class ChatMessageContent extends KernelContent { 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 7ed3e8c0b09d..470a2deff8df 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 @@ private static List internalSplitTextParagraphs( List lines, int maxTokensPerParagraph, Function> longLinesSplitter) { - if (lines.size() == 0) { + if (lines.isEmpty()) { return new ArrayList<>(); } @@ -128,11 +128,11 @@ && TokenCount(currentParagraph.length()) + TokenCount(line.length()) 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(); From e674b54c53158f4d696eb1c0703cf287c7c0bf97 Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Tue, 20 Feb 2024 18:34:52 +0000 Subject: [PATCH 07/13] Add converter test --- .../chatcompletion/OpenAIChatCompletion.java | 6 +- .../contextvariables/ContextVariable.java | 2 +- .../ContextVariableTypeConverterTest.java | 67 +++++++++++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) 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/chatcompletion/OpenAIChatCompletion.java b/java/aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatCompletion.java index 8b3ac8c44f5d..a2d2e861942e 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 @@ -134,8 +134,8 @@ private Mono>> internalChatMessageContentsAsync( KernelHooks kernelHooks = invocationContext != null && invocationContext.getKernelHooks() != null - ? invocationContext.getKernelHooks() - : new KernelHooks(); + ? invocationContext.getKernelHooks() + : new KernelHooks(); ChatCompletionsOptions options = kernelHooks .executeHooks(new PreChatCompletionEvent( @@ -320,7 +320,7 @@ private static ChatCompletionsOptions getCompletionsOptions( // Gives back "Validation error at #/stop/str: Input should be a valid string\nValidation error at #/stop/list[str]: List should have at least 1 item after validation, not 0" .setStop(promptExecutionSettings.getStopSequences() == null || promptExecutionSettings.getStopSequences().isEmpty() ? null - : promptExecutionSettings.getStopSequences()) + : promptExecutionSettings.getStopSequences()) .setUser(promptExecutionSettings.getUser()) .setLogitBias(logit); 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 0b517c39698f..232b974cf401 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 @@ -147,7 +147,7 @@ public static ContextVariable convert( 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)); 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 000000000000..6683cea6678a --- /dev/null +++ b/java/semantickernel-api/src/test/java/com/microsoft/semantickernel/contextvariables/converters/ContextVariableTypeConverterTest.java @@ -0,0 +1,67 @@ +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.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 { + + 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; + } + } + + @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().format(DateTimeFormatter.ISO_DATE_TIME)), + new TestCase<>("DateToString", OffsetDateTime.class, String.class, + OffsetDateTime.now())) + .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) { + + } + })); + + } + +} From 152eafa5cf7d42550a5a638f5c65409ffd8957b8 Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Tue, 20 Feb 2024 18:56:27 +0000 Subject: [PATCH 08/13] Format --- .../openai/chatcompletion/OpenAIChatCompletion.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 a2d2e861942e..8b3ac8c44f5d 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 @@ -134,8 +134,8 @@ private Mono>> internalChatMessageContentsAsync( KernelHooks kernelHooks = invocationContext != null && invocationContext.getKernelHooks() != null - ? invocationContext.getKernelHooks() - : new KernelHooks(); + ? invocationContext.getKernelHooks() + : new KernelHooks(); ChatCompletionsOptions options = kernelHooks .executeHooks(new PreChatCompletionEvent( @@ -320,7 +320,7 @@ private static ChatCompletionsOptions getCompletionsOptions( // Gives back "Validation error at #/stop/str: Input should be a valid string\nValidation error at #/stop/list[str]: List should have at least 1 item after validation, not 0" .setStop(promptExecutionSettings.getStopSequences() == null || promptExecutionSettings.getStopSequences().isEmpty() ? null - : promptExecutionSettings.getStopSequences()) + : promptExecutionSettings.getStopSequences()) .setUser(promptExecutionSettings.getUser()) .setLogitBias(logit); From 9d7f0dc28e7f5ec5b3f107f01e2732348903db50 Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Wed, 21 Feb 2024 15:33:05 +0000 Subject: [PATCH 09/13] Apply copyright headers --- .../semantickernel/aiservices/openai/OpenAIRequestSettings.java | 1 + .../aiservices/openai/chatcompletion/OpenAIChatCompletion.java | 1 + .../aiservices/openai/chatcompletion/OpenAIChatResponse.java | 1 + .../aiservices/openai/chatcompletion/OpenAIFunction.java | 1 + .../aiservices/openai/chatcompletion/ParsedPrompt.java | 1 + .../aiservices/openai/chatcompletion/XMLPromptParser.java | 1 + .../openai/textcompletion/OpenAITextGenerationService.java | 1 + .../syntaxexamples/Example01NativeFunctionsTest.java | 1 - .../microsoft/semantickernel/syntaxexamples/WireMockUtil.java | 1 + .../semantickernel/syntaxexamples/WiremockExamplesIT.java | 1 + .../microsoft/semantickernel/syntaxexamples/WiremockRecord.java | 1 + .../semantickernel/connectors/web/bing/BingConnector.java | 1 + .../microsoft/semantickernel/plugins/web/SearchUrlPlugin.java | 1 + java/pom.xml | 2 +- .../samples/plugins/ConversationSummaryPlugin.java | 1 + .../semantickernel/samples/plugins/PromptFunctionConstants.java | 1 + .../samples/syntaxexamples/Example01_NativeFunctions.java | 1 + .../samples/syntaxexamples/Example06_TemplateLanguage.java | 1 + .../samples/syntaxexamples/Example08_RetryHandler.java | 1 + .../samples/syntaxexamples/Example09_FunctionTypes.java | 1 + .../Example10_DescribeAllPluginsAndFunctions.java | 1 + .../samples/syntaxexamples/Example11_WebSearchQueries.java | 1 + .../samples/syntaxexamples/Example17_ChatGPT.java | 1 + .../samples/syntaxexamples/Example26_AADAuth.java | 1 + .../syntaxexamples/Example27_PromptFunctionsUsingChatGPT.java | 1 + .../samples/syntaxexamples/Example30_ChatWithPrompts.java | 1 + .../semantickernel/samples/syntaxexamples/Example33_Chat.java | 1 + .../samples/syntaxexamples/Example41_HttpClientUsage.java | 1 + .../samples/syntaxexamples/Example42_KernelBuilder.java | 1 + .../samples/syntaxexamples/Example43_GetModelResult.java | 1 + .../samples/syntaxexamples/Example44_MultiChatCompletion.java | 1 + .../samples/syntaxexamples/Example49_LogitBias.java | 1 + .../samples/syntaxexamples/Example55_TextChunker.java | 1 + .../Example56_TemplateMethodFunctionsWithMultipleArguments.java | 1 + .../samples/syntaxexamples/Example57_KernelHooks.java | 1 + .../syntaxexamples/Example58_ConfigureExecutionSettings.java | 1 + .../samples/syntaxexamples/Example59_OpenAIFunctionCalling.java | 1 + .../syntaxexamples/Example60_AdvancedMethodFunctions.java | 1 + .../samples/syntaxexamples/Example61_MultipleLLMs.java | 1 + .../syntaxexamples/Example62_CustomAIServiceSelector.java | 1 + .../samples/syntaxexamples/Example63_ChatCompletionPrompts.java | 1 + .../syntaxexamples/Example64_MultiplePromptTemplates.java | 1 + .../samples/syntaxexamples/Example67_KernelStreaming.java | 1 + .../samples/syntaxexamples/Example69_MutableKernelPlugin.java | 1 + .../microsoft/semantickernel/samples/syntaxexamples/RunAll.java | 1 + .../com/microsoft/semantickernel/KernelPluginCollection.java | 1 + .../semantickernel/contextvariables/ContextVariableType.java | 1 + .../contextvariables/ContextVariableTypeConverter.java | 1 + .../semantickernel/contextvariables/ContextVariableTypes.java | 1 + .../converters/BooleanVariableContextVariableTypeConverter.java | 1 + .../CharacterVariableContextVariableTypeConverter.java | 1 + .../ChatHistoryVariableContextVariableTypeConverter.java | 1 + .../converters/CompletionUsageContextVariableTypeConverter.java | 1 + .../converters/DateTimeContextVariableTypeConverter.java | 1 + .../converters/InstantContextVariableTypeConverter.java | 1 + .../converters/NumberVariableContextVariableTypeConverter.java | 1 + .../converters/StringVariableContextVariableTypeConverter.java | 1 + .../converters/VoidVariableContextVariableTypeConverter.java | 1 + .../microsoft/semantickernel/hooks/FunctionInvokedEvent.java | 1 + .../microsoft/semantickernel/hooks/FunctionInvokingEvent.java | 1 + .../java/com/microsoft/semantickernel/hooks/KernelHook.java | 1 + .../com/microsoft/semantickernel/hooks/KernelHookEvent.java | 1 + .../java/com/microsoft/semantickernel/hooks/KernelHooks.java | 1 + .../microsoft/semantickernel/hooks/PreChatCompletionEvent.java | 1 + .../com/microsoft/semantickernel/hooks/PromptRenderedEvent.java | 1 + .../microsoft/semantickernel/hooks/PromptRenderingEvent.java | 1 + .../java/com/microsoft/semantickernel/implementation/Todo.java | 1 + .../templateengine/tokenizer/blocks/NamedArgBlock.java | 1 + .../semantickernel/orchestration/FunctionInvocation.java | 1 + .../microsoft/semantickernel/orchestration/FunctionResult.java | 1 + .../semantickernel/orchestration/FunctionResultMetadata.java | 1 + .../semantickernel/orchestration/InvocationContext.java | 1 + .../semantickernel/orchestration/PromptExecutionSettings.java | 1 + .../semantickernel/orchestration/ToolCallBehavior.java | 1 + .../java/com/microsoft/semantickernel/plugin/KernelPlugin.java | 1 + .../microsoft/semantickernel/plugin/KernelPluginFactory.java | 1 + .../semantickernel/plugin/KernelReturnParameterMetadata.java | 1 + .../semanticfunctions/AggregatorPromptTemplateFactory.java | 1 + .../semanticfunctions/HandlebarsPromptTemplateFactory.java | 1 + .../semantickernel/semanticfunctions/InputVariable.java | 1 + .../semantickernel/semanticfunctions/KernelFunctionFactory.java | 0 .../semanticfunctions/KernelFunctionFromMethod.java | 1 + .../semanticfunctions/KernelFunctionFromPrompt.java | 1 + .../semanticfunctions/KernelFunctionMetadata.java | 1 + .../semantickernel/semanticfunctions/KernelFunctionYaml.java | 1 + .../semanticfunctions/KernelParameterMetadata.java | 1 + .../semanticfunctions/KernelPromptTemplateFactory.java | 1 + .../semantickernel/semanticfunctions/MethodDetails.java | 1 + .../semantickernel/semanticfunctions/OutputVariable.java | 1 + .../semantickernel/semanticfunctions/PromptTemplateFactory.java | 1 + .../microsoft/semantickernel/services/AIServiceCollection.java | 1 + .../semantickernel/services/BaseAIServiceSelector.java | 1 + .../com/microsoft/semantickernel/services/KernelContent.java | 1 + .../semantickernel/services/OrderedAIServiceSelector.java | 1 + .../semantickernel/services/ServiceNotFoundException.java | 1 + .../semantickernel/services/StreamingKernelContent.java | 1 + .../services/textcompletion/StreamingTextContent.java | 1 + .../semantickernel/services/textcompletion/TextContent.java | 1 + .../converters/ContextVariableTypeConverterTest.java | 1 + .../NumberVariableContextVariableTypeConverterTest.java | 1 + 100 files changed, 98 insertions(+), 2 deletions(-) delete mode 100644 java/semantickernel-api/src/main/java/com/microsoft/semantickernel/semanticfunctions/KernelFunctionFactory.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 5be4ff9640d6..6a1aabf917ec 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 8b3ac8c44f5d..2f06787e9d9e 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; 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 aed49c5e4269..3e1df267a5df 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 6064e136d39c..c81f0c1c71bf 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; 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 e93e83cf3bc5..7f49573eeaf9 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 a0eaf08fc1e2..81af20222f4b 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 569cdf73c104..2f09faf0a76d 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/src/test/java/com/microsoft/semantickernel/syntaxexamples/Example01NativeFunctionsTest.java b/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/Example01NativeFunctionsTest.java index 16b82e7e8a41..a87fb8706e20 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/syntaxexamples/Example01NativeFunctionsTest.java @@ -1,5 +1,4 @@ // Copyright (c) Microsoft. All rights reserved. - package com.microsoft.semantickernel.syntaxexamples; import com.microsoft.semantickernel.plugins.text.TextPlugin; 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 index 89fa87c67acd..9bf49d5a015b 100644 --- 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 @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.syntaxexamples; import com.github.tomakehurst.wiremock.client.WireMock; 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/syntaxexamples/WiremockExamplesIT.java index d896595fc223..c2200051451e 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/syntaxexamples/WiremockExamplesIT.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.syntaxexamples; import com.github.tomakehurst.wiremock.WireMockServer; 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/syntaxexamples/WiremockRecord.java index 4fa53d26f07c..6600b3551d96 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/syntaxexamples/WiremockRecord.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.syntaxexamples; import com.fasterxml.jackson.databind.JsonNode; 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 c4b417185549..a2ef62c3662a 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 96280972c24e..cdf906a71aae 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 553e7dbf42fe..5514cb98ec9d 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -662,11 +662,11 @@ true + --> // Copyright (c) Microsoft. All rights reserved. - --> 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 b486c24cad57..f72d15bae098 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.plugins; import com.microsoft.semantickernel.Kernel; 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 324e2bad73cd..e88e6ba34a0f 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 0bc76d47394d..5b71f675b078 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/Example06_TemplateLanguage.java b/java/samples/sample-code/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/Example06_TemplateLanguage.java index 6f305c79b907..32e8f6522a07 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; 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 aceadfce6892..a1881feab30e 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; 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 30a886434cfd..5518bbb7e954 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; 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 a558b1f28186..8adbbdb2db8a 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; 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 486b8bec4eaa..e38cba46c8b9 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.microsoft.semantickernel.Kernel; 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 2e81be0655ec..16b701ef6d42 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 85ee544f5b08..6dcf9fc04262 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; 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 6a0c65ac0269..ea195698d99b 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; 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 f2202d6741cd..a782b1aa7428 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; 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 6f9dca94b6ed..0d498ed2a51e 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 b57937992595..30ddafb77ea1 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 1f2e5a959fd8..9a77ece61f43 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; 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 362ac5e2bd6f..373a97a2c3ff 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; 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 cc81ddac4686..f5d60c72577f 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; 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 fa7599f6e44d..3aca0f0dfcea 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; 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 7738ec9a2e08..8b171d7e0056 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 b5727fd5ae75..edff095baa59 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; 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 cfad72b15d48..2a0c6bef8d38 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; 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 ff9212bc2366..75451e337664 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; 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 3a66d72f6421..ae56d279b134 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; 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 0b564ea75158..91d2d7bbf83f 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.microsoft.semantickernel.Kernel; 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 0dfccce1873c..3ab911b7bdfa 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; 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 b14e0399fde8..1999859dd093 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; 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 00f87860f6a1..d775b1f789c3 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; 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 186504e30817..cb79b7792ca7 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; 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 bbc11dc21ced..36a0a424889d 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 196fd56d4862..00be59cf43c0 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.samples.syntaxexamples; import com.microsoft.semantickernel.Kernel; 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 30b7a96fc5e1..793ec2ad8ac5 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; 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 ec6904122a52..3348e447b8ea 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel; import com.microsoft.semantickernel.contextvariables.CaseInsensitiveMap; 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 c8a8cc19002a..523361e23f1f 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; 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 646e24519c8f..b93bbfb325d2 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; 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 a76dee946c5f..fa7c2013a0ed 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables; import com.microsoft.semantickernel.contextvariables.converters.BooleanVariableContextVariableTypeConverter; 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 4ec5183fe8cd..4769064a192c 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; 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 fa0c479a8678..c6787f908705 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; 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 289c92648eda..ffc6ef9583db 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import static com.microsoft.semantickernel.contextvariables.ContextVariableTypes.convert; 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 9e5edcf4852d..048afc19e624 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; 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 dcba14a20ae5..6a64ccd2984d 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; 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 ffb1c0846801..13fbfb4e191f 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; 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 a1cdba3bdb35..1e4fb45727f5 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import static com.microsoft.semantickernel.contextvariables.ContextVariableTypes.convert; 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 5a2be484a506..f7096b074716 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; 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 0bae5f769980..d3d602c1ccb6 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter; 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 65e4fd48a5c3..495a3742533d 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; 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 670d93c4cd45..31f2b6309229 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; 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 6139274f96c4..a1e8850573db 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; diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/KernelHookEvent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/KernelHookEvent.java index 5695efb1b0c9..00610ddba1e5 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/KernelHookEvent.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/KernelHookEvent.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.hooks; /** diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/KernelHooks.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/KernelHooks.java index 93ec69081437..ea3dc82ee0de 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/KernelHooks.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/KernelHooks.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.hooks; import com.microsoft.semantickernel.hooks.KernelHook.FunctionInvokedHook; diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PreChatCompletionEvent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PreChatCompletionEvent.java index 6977c550e5bf..dba2bb9abc4e 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PreChatCompletionEvent.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PreChatCompletionEvent.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.hooks; import com.azure.ai.openai.models.ChatCompletionsOptions; diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderedEvent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderedEvent.java index f9bc2c48241e..2221ac78d250 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderedEvent.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderedEvent.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.hooks; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; diff --git a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderingEvent.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderingEvent.java index a9f1058649a3..8bec8fed9d66 100644 --- a/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderingEvent.java +++ b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/hooks/PromptRenderingEvent.java @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.hooks; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; 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 bfcfa85f0c2d..fe7113b0b33d 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/templateengine/tokenizer/blocks/NamedArgBlock.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/implementation/templateengine/tokenizer/blocks/NamedArgBlock.java index caeee93663f6..7a27d0aefb89 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; 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 22a49e2a17b3..dbff8e366cd2 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.orchestration; import com.microsoft.semantickernel.Kernel; 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 53d37a4f365a..480121e455c7 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.orchestration; import com.microsoft.semantickernel.contextvariables.ContextVariable; 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 6e7dadf7f611..8295f9514feb 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; 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 257986c8abdf..4e94be080e57 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.orchestration; import com.microsoft.semantickernel.builders.Buildable; 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 4d98d28e9b4d..9d5df4ee30b0 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; 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 c5b8f5c4f16e..f6709cb53245 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; 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 fd70efd615ca..e23495813898 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.plugin; import com.microsoft.semantickernel.contextvariables.CaseInsensitiveMap; 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 e7a7b50e2a72..77104cb0e31b 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; 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 8a24aa8322c5..3bd812143ad0 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.plugin; import com.microsoft.semantickernel.semanticfunctions.KernelFunction; 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 5a6da07ecddd..2c4bf5912d7d 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; 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 25f62db0996b..f988c13fc427 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; 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 6162d7f53dcf..dfdb04522bcf 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; 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 e69de29bb2d1..000000000000 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 ff6a139c7fa6..d7b356d3ab96 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; 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 5567d012d22f..7d9940811967 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import com.azure.core.exception.HttpResponseException; 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 c1827b00ce3d..52d15b11e167 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; 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 899f6dbad80f..48bc3370e959 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import com.fasterxml.jackson.databind.ObjectMapper; 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 cc7d14be585a..c04bf387481b 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import javax.annotation.Nullable; 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 07e864fbb5d4..3606fe9cdd72 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import static com.microsoft.semantickernel.semanticfunctions.HandlebarsPromptTemplateFactory.HANDLEBARS_TEMPLATE_FORMAT; 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 0c9b54a41553..f7dc9aa9f315 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; 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 13bc26d58d4a..45f920933b90 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; 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 41f793a11f6b..5546b8c9d1e1 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.semanticfunctions; import javax.annotation.Nullable; 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 3499033d96ff..48d9def78026 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/BaseAIServiceSelector.java b/java/semantickernel-api/src/main/java/com/microsoft/semantickernel/services/BaseAIServiceSelector.java index 24ac21a4449c..2eaa9404c1d3 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; 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 2eea41b5890b..6e85f34e19be 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; 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 8d14d1f4b733..411ba9877e2b 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.services; import com.microsoft.semantickernel.implementation.Verify; 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 f4c2be7abe9c..3209d89ef284 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; 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 c42222efb522..6c1ddab10082 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; 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 213ee3b0c194..7fdadad79259 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 b8c9e56a7796..d5eb1690af0b 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,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.services.textcompletion; import com.microsoft.semantickernel.orchestration.FunctionResultMetadata; 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 index 6683cea6678a..a38acd949836 100644 --- 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 @@ -1,3 +1,4 @@ +// Copyright (c) Microsoft. All rights reserved. package com.microsoft.semantickernel.contextvariables.converters; import com.microsoft.semantickernel.contextvariables.ContextVariable; 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 b8a06c861ad5..b8852870fbf9 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; From c1b1db0197a401ebc8f348015ef2ad8566286b00 Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Wed, 21 Feb 2024 16:04:28 +0000 Subject: [PATCH 10/13] Fix error in tests --- .../semantickernel/plugin/KernelPluginFactory.java | 2 ++ .../semanticfunctions/KernelPromptTemplateFactory.java | 5 +++++ .../semanticfunctions/PromptTemplateConfig.java | 9 ++++----- .../handlebars/HandlebarsPromptTemplate.java | 5 +++++ 4 files changed, 16 insertions(+), 5 deletions(-) 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 77104cb0e31b..56787870d477 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 @@ -243,6 +243,8 @@ private static KernelFunction getKernelFunction( String template) { PromptTemplate promptTemplate; + config = config.copy().withTemplate(template).build(); + if (promptTemplateFactory != null) { promptTemplate = promptTemplateFactory.tryCreate(config); } else { 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 3606fe9cdd72..e7fb3a52d88d 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 @@ -4,6 +4,7 @@ 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; @@ -17,6 +18,10 @@ public class KernelPromptTemplateFactory implements PromptTemplateFactory { @Override public PromptTemplate tryCreate(@Nonnull PromptTemplateConfig templateConfig) { + if (templateConfig.getTemplate() == null) { + throw new SKException("The prompt template is null."); + } + switch (templateConfig.getTemplateFormat().toLowerCase(Locale.ROOT)) { case SEMANTIC_KERNEL_TEMPLATE_FORMAT: return DefaultPromptTemplate.build(templateConfig); 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 ae7d026d9984..fcde2da7aa3e 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 @@ -41,6 +41,7 @@ public class PromptTemplateConfig implements Buildable { @Nullable private final String name; + @Nullable private final String template; private final String templateFormat; @Nullable @@ -83,7 +84,7 @@ public PromptTemplateConfig(String template) { 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, @@ -122,7 +123,7 @@ public PromptTemplateConfig( */ public PromptTemplateConfig( @Nullable String name, - String template, + @Nullable String template, @Nullable String templateFormat, @Nullable String description, @Nullable List inputVariables, @@ -239,6 +240,7 @@ public String getName() { * * @return The template of the prompt template config. */ + @Nullable public String getTemplate() { return template; } @@ -428,9 +430,6 @@ public Builder withExecutionSettings( * @return The prompt template config. */ public PromptTemplateConfig build() { - if (template == null) { - throw new SKException("Template is required"); - } return new PromptTemplateConfig( name, template, 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 17d901d9da40..9654ae329238 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 @@ -7,6 +7,7 @@ import com.github.jknack.handlebars.ValueResolver; import com.microsoft.semantickernel.Kernel; 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; @@ -54,6 +55,10 @@ public Mono renderAsync( Kernel kernel, @Nullable KernelFunctionArguments arguments, @Nullable InvocationContext context) { + String template = promptTemplate.getTemplate(); + if (template == null) { + return Mono.error(new SKException("The prompt template is null.")); + } HandleBarsPromptTemplateHandler handler = new HandleBarsPromptTemplateHandler(kernel, promptTemplate.getTemplate()); From 7a8db9112a40648addd32b06140f7e222caf61eb Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:31:42 +0000 Subject: [PATCH 11/13] Tidy exceptions --- .../integration-tests/src/test/resources/log4j2.xml | 2 +- .../templateengine/tokenizer/DefaultPromptTemplate.java | 7 +++++++ .../semanticfunctions/KernelPromptTemplateFactory.java | 4 +++- .../handlebars/HandlebarsPromptTemplate.java | 6 ++++-- 4 files changed, 15 insertions(+), 4 deletions(-) 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 50a638f0dc9b..02e288f80024 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/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 9c785db23b08..6ac63c3ce9eb 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; @@ -70,6 +71,12 @@ public static DefaultPromptTemplate build(@Nonnull PromptTemplateConfig promptTe 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); Optional invalid = blocks 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 e7fb3a52d88d..b10c6fb93da7 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 @@ -19,7 +19,9 @@ public class KernelPromptTemplateFactory implements PromptTemplateFactory { @Override public PromptTemplate tryCreate(@Nonnull PromptTemplateConfig templateConfig) { if (templateConfig.getTemplate() == null) { - throw new SKException("The prompt template is null."); + throw new SKException( + String.format("No prompt template was provided for the prompt %s.", + templateConfig.getName())); } switch (templateConfig.getTemplateFormat().toLowerCase(Locale.ROOT)) { 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 9654ae329238..ec6b5aa4a319 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 @@ -57,10 +57,12 @@ public Mono renderAsync( @Nullable InvocationContext context) { String template = promptTemplate.getTemplate(); if (template == null) { - return Mono.error(new SKException("The prompt template is 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(); From a83a681c4f8c3814c1c3ada96b55c56e83f60981 Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Thu, 22 Feb 2024 13:17:55 +0000 Subject: [PATCH 12/13] Add Yaml parsing exampleand fix bugs with templates --- .../syntaxexamples/WireMockUtil.java | 46 ------- .../Example01NativeFunctionsTest.java | 2 +- .../Example03_ArgumentsTest.java | 2 +- ...xample05_InlineFunctionDefinitionTest.java | 2 +- .../semantickernel/tests/KernelHooksTest.java | 103 +++++++++++++++ .../semantickernel/tests/WireMockUtil.java | 125 ++++++++++++++++++ .../WiremockExamplesIT.java | 2 +- .../WiremockRecord.java | 2 +- .../Example09_FunctionTypes.java | 56 +++++--- .../java/KernelFunctionYaml_Example.java | 93 +++++++++++++ .../syntaxexamples/java/GenerateStory.yaml | 17 +++ .../java/GenerateStoryHandlebars.yaml | 23 ++++ java/semantickernel-api/pom.xml | 6 + .../ContextVariableTypeConverter.java | 3 + .../ContextVariableTypes.java | 2 + ...tVariableContextVariableTypeConverter.java | 30 +++++ .../orchestration/FunctionInvocation.java | 5 +- .../PromptExecutionSettings.java | 70 +++++----- .../KernelFunctionFromPrompt.java | 5 - .../semanticfunctions/KernelFunctionYaml.java | 2 +- .../semanticfunctions/OutputVariable.java | 5 +- .../ContextVariableTypeConverterTest.java | 5 +- 22 files changed, 491 insertions(+), 115 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 (99%) rename java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/{syntaxexamples => tests}/WiremockRecord.java (98%) 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 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 9bf49d5a015b..000000000000 --- a/java/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/syntaxexamples/WireMockUtil.java +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -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 a87fb8706e20..bdb24f929662 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,5 +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 745e9ecfd40e..2fa953effac5 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,5 +1,5 @@ // 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; 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 9a7e6bbb7824..028973a74e1a 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; 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 000000000000..a098268c2273 --- /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 000000000000..5bf39de86a1f --- /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 99% 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 c2200051451e..cf3eeaacab2a 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,5 +1,5 @@ // Copyright (c) Microsoft. All rights reserved. -package com.microsoft.semantickernel.syntaxexamples; +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 98% 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 6600b3551d96..90a02f11c910 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,5 +1,5 @@ // Copyright (c) Microsoft. All rights reserved. -package com.microsoft.semantickernel.syntaxexamples; +package com.microsoft.semantickernel.tests; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; 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 5518bbb7e954..e71cbe1ab12c 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 @@ -9,14 +9,14 @@ 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; @@ -162,7 +162,7 @@ public static void main(String[] args) throws InterruptedException { .block(); System.out.println(result.getResult()); - kernel.invokeAsync(plugin.get("MultipleInputsWithVoidResult")) + result = kernel.invokeAsync(plugin.get("MultipleInputsWithVoidResult")) .withArguments( KernelFunctionArguments .builder() @@ -171,7 +171,6 @@ public static void main(String[] args) throws InterruptedException { .withVariable("z", 1.5) .build()) .block(); - System.out.println(result.getResult()); result = kernel .invokeAsync(plugin.get("ComplexInputWithStringResult")) @@ -286,6 +285,15 @@ public String toString() { .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 @@ -293,7 +301,7 @@ public String toString() { * null, * Void.class) * .block(); - * + * */ /* @@ -320,7 +328,7 @@ public String toString() { * 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 @@ -466,11 +474,21 @@ public OffsetDateTime conversionScenarioB() { 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 + "}]"); + } + /* * ///