changes for Map<String,Object> for variables

This commit is contained in:
David Grieve
2023-11-21 10:22:52 -05:00
parent 2c5e9a5202
commit d9255458c9
12 changed files with 118 additions and 39 deletions
@@ -53,6 +53,7 @@ public interface Kernel extends Buildable {
*
* @param pipeline List of functions
* @return Result of the function composition
* @apiNote Breaking change: s/SKFunction<?>/SKFunction/
*/
@Deprecated
Mono<SKContext> runAsync(SKFunction... pipeline);
@@ -63,6 +64,7 @@ public interface Kernel extends Buildable {
* @param input Input to process
* @param pipeline List of functions
* @return Result of the function composition
* @apiNote Breaking change: s/SKFunction<?>/SKFunction/
*/
@Deprecated
Mono<SKContext> runAsync(String input, SKFunction... pipeline);
@@ -73,10 +75,21 @@ public interface Kernel extends Buildable {
* @param variables variables to initialise the context with
* @param pipeline List of functions
* @return Result of the function composition
* @apiNote Breaking change: s/SKFunction<?>/SKFunction/
*/
@Deprecated
Mono<SKContext> runAsync(ContextVariables variables, SKFunction... pipeline);
/**
* Run a pipeline composed of synchronous and asynchronous functions.
* @param streaming Whether to stream the results of the pipeline
* @param variables variables to initialise the context with
* @param pipeline List of functions
* @return Result of the function composition
* @since 1.0.0
*/
Mono<SKContext> runAsync(boolean streaming, ContextVariables variables, SKFunction... pipeline);
/**
* Register a semantic function on this kernel
*
@@ -101,12 +114,16 @@ public interface Kernel extends Buildable {
<T extends AIService> T getService(@Nullable String name, Class<T> clazz)
throws KernelException;
/** Registers a semantic function on this kernel */
/** Registers a semantic function on this kernel
* @apiNote Breaking change: s/<RequestConfiguration, FunctionType extends SKFunction<RequestConfiguration>>/<FunctionType extends SKFunction>/
*/
@Deprecated
<RequestConfiguration, FunctionType extends SKFunction<RequestConfiguration>>
<FunctionType extends SKFunction>
FunctionType registerSemanticFunction(FunctionType semanticFunctionDefinition);
/** Obtains a semantic function with the given name */
/** Obtains a semantic function with the given name
* @apiNote Breaking change: s/SKFunction<?>/SKFunction/
*/
@Deprecated
SKFunction getFunction(String skill, String function);
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.chatcompletion;
import javax.annotation.Nullable;
import com.azure.ai.openai.OpenAIAsyncClient;
import com.azure.ai.openai.models.ChatCompletions;
import com.microsoft.semantickernel.builders.Buildable;
@@ -8,7 +10,7 @@ import com.microsoft.semantickernel.builders.BuildersSingleton;
import com.microsoft.semantickernel.builders.SemanticKernelBuilder;
import com.microsoft.semantickernel.services.AIService;
import com.microsoft.semantickernel.textcompletion.TextCompletion;
import javax.annotation.Nullable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -30,8 +32,18 @@ public interface ChatCompletion<ChatHistoryType extends ChatHistory>
*
* @param instructions Optional chat instructions for the AI service
* @return Chat object
* @apiNote Breaking change: s/@Nullable String instructions/String instructions/
*/
ChatHistoryType createNewChat(@Nullable String instructions);
ChatHistoryType createNewChat(String instructions);
/**
* Create a new empty chat instance
*
* @return Chat object
* @since 1.0.0
*/
ChatHistoryType createNewChat();
Flux<String> generateMessageStream(
ChatHistoryType chatHistory, @Nullable ChatRequestSettings requestSettings);
@@ -96,6 +96,7 @@ public class ChatHistory {
*
* @param content Message content
* @since 1.0.0
* @
*/
public void addUserMessage(String content) {
this.messages.add(new Message(AuthorRoles.User, content));
@@ -26,7 +26,7 @@ public abstract class AbstractSKContext implements SKContext {
@Nullable
@Override
public String getResult() {
public Object getResult() {
return getVariables().asMap().get(ContextVariables.MAIN_KEY);
}
@@ -1,6 +1,14 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.orchestration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import com.microsoft.semantickernel.SKBuilders;
import com.microsoft.semantickernel.memory.NullMemory;
import com.microsoft.semantickernel.memory.SemanticTextMemory;
@@ -9,17 +17,12 @@ import com.microsoft.semantickernel.skilldefinition.KernelSkillsSupplier;
import com.microsoft.semantickernel.skilldefinition.ParameterView;
import com.microsoft.semantickernel.skilldefinition.ReadOnlySkillCollection;
import com.microsoft.semantickernel.skilldefinition.annotations.SKFunctionParameters;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import reactor.core.publisher.Mono;
/** Abstract implementation of the SKFunction interface. */
public abstract class AbstractSkFunction<RequestConfiguration>
implements SKFunction<RequestConfiguration>, RegistrableSkFunction {
public abstract class AbstractSkFunction
implements SKFunction, RegistrableSkFunction {
private final List<ParameterView> parameters;
private final String skillName;
@@ -84,11 +87,12 @@ public abstract class AbstractSkFunction<RequestConfiguration>
return skillsSupplier;
}
/** @apiNote Breaking change: s/RequestConfiguration settings/Object settings/ */
@Override
public Mono<SKContext> invokeAsync(
@Nullable String input,
@Nullable SKContext context,
@Nullable RequestConfiguration settings) {
@Nullable Object settings) {
if (context == null) {
assertSkillSupplierRegistered();
@@ -113,9 +117,10 @@ public abstract class AbstractSkFunction<RequestConfiguration>
return invokeAsync(input, null, null);
}
/** @apiNote Breaking change: s/RequestConfiguration settings/Object settings/ */
@Override
public Mono<SKContext> invokeAsync(
@Nullable SKContext context, @Nullable RequestConfiguration settings) {
@Nullable SKContext context, @Nullable Object settings) {
if (context == null) {
context =
SKBuilders.context()
@@ -135,9 +140,10 @@ public abstract class AbstractSkFunction<RequestConfiguration>
* @param context The context.
* @param settings The settings.
* @return A mono of the context with the result.
* @apiNote Breaking change: s/RequestConfiguration settings/Object settings/
*/
protected abstract Mono<SKContext> invokeAsyncInternal(
SKContext context, @Nullable RequestConfiguration settings);
SKContext context, @Nullable Object settings);
@Override
public String getSkillName() {
@@ -24,8 +24,9 @@ public interface ContextVariables extends Buildable {
* Get variables as a map
*
* @return Map of variables
* @apiNote Breaking change: s/Map<String,String>/Map<String,Object>/
*/
Map<String, String> asMap();
Map<String, Object> asMap();
/**
* Get a clone of the variables that can be modified
@@ -69,6 +70,7 @@ public interface ContextVariables extends Buildable {
*
* @param map Existing variables
* @return an instantiation of ContextVariables
* @apiNote Breaking change: s/Map<String,String>/Map<String,Object>/
*/
Builder withVariables(Map<String, Object> map);
@@ -78,6 +80,7 @@ public interface ContextVariables extends Buildable {
* @param key variable name
* @param value variable value
* @return builder for fluent chaining
* @apiNote Breaking change: s/String value/Object value/
*/
Builder withVariable(String key, Object value);
}
@@ -87,7 +90,8 @@ public interface ContextVariables extends Buildable {
*
* @param key variable name
* @return content of the variable
* @apiNote Breaking change: s/String get(String key)/Object get(String key)/
*/
@Nullable
String get(String key);
Object get(String key);
}
@@ -27,9 +27,10 @@ public interface SKContext extends Buildable {
* in the variables.
*
* @return the "input" entry in the variables
* @apiNote Breaking change: s/String/Object/
*/
@Nullable
String getResult();
Object getResult();
/**
* Return a copy of all variables within the context
@@ -12,6 +12,7 @@ import reactor.core.publisher.Mono;
/**
* Semantic Kernel callable function interface
* @apiNote Breaking change: s/SKFunction<RequestConfiguration>/SKFunction/
*/
public interface SKFunction {
/**
@@ -29,9 +30,11 @@ public interface SKFunction {
* @param context Request context
* @param settings Configuration of the request
* @return an updated context with the result of the request
@CheckReturnValue
Mono<SKContext> invokeAsync(String input, SKContext context, RequestConfiguration settings);
* @apiNote Breaking change: s/RequestConfiguration settings/Object settings/
*/
@CheckReturnValue
@Deprecated
Mono<SKContext> invokeAsync(String input, SKContext context, Object settings);
/**
* Invokes the function
@@ -72,9 +75,11 @@ public interface SKFunction {
* @param context Request context
* @param settings Configuration of the request
* @return an updated context with the result of the request
* @apiNote Breaking change: s/RequestConfiguration settings/Object settings/
*/
@CheckReturnValue
Mono<SKContext> invokeAsync(SKContext context, @Nullable RequestConfiguration settings);
@Deprecated
Mono<SKContext> invokeAsync(SKContext context, @Nullable Object settings);
/**
* @return The name of the skill that this function is within
@@ -15,10 +15,19 @@ public interface WritableContextVariables extends ContextVariables {
* @param key variable name
* @param content value to set
* @return Context for fluent calls
* @apiNote Breaking change: s/String content/Object content/
*/
ContextVariables setVariable(String key, String content);
ContextVariables setVariable(String key, Object content);
ContextVariables appendToVariable(String key, String content);
/**
* Append to the variable's value
*
* @param key variable name
* @param content value to append
* @return Context for fluent calls
* @apiNote Breaking change: s/String content/Object content/
*/
ContextVariables appendToVariable(String key, Object content);
/**
* Updates the main input text with the new value after a function is complete.
@@ -26,8 +35,9 @@ public interface WritableContextVariables extends ContextVariables {
* @param content The new input value, for the next function in the pipeline, or as a result for
* the user if the pipeline reached the end.
* @return The current instance
* @apiNote Breaking change: s/String content/Object content/
*/
ContextVariables update(String content);
ContextVariables update(Object content);
/**
* Updates the variables merging or overwriting in the new values.
@@ -46,7 +56,8 @@ public interface WritableContextVariables extends ContextVariables {
*
* @param map Existing variables
* @return an instantiation of ContextVariables
* @apiNote Breaking change: s/String content/Object content/
*/
WritableContextVariables build(Map<String, String> map);
WritableContextVariables build(Map<String, Object> map);
}
}
@@ -1,16 +1,26 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.skilldefinition;
import com.microsoft.semantickernel.orchestration.SKFunction;
import java.util.List;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import com.microsoft.semantickernel.orchestration.SKFunction;
public interface ReadOnlyFunctionCollection {
String getSkillName();
SKFunction<?> getFunction(String functionName);
/**
* Get function with the given name.
*
* @param functionName the name of the function to retrieve
* @return The given function
* @throws RuntimeException if the given entry is not of the expected type
* @apiNote Breaking change: s/SKFunciton<?>/SKFunction/
*/
SKFunction getFunction(String functionName);
/**
* Get function with the given SKFunction type argument.
@@ -31,6 +41,7 @@ public interface ReadOnlyFunctionCollection {
/**
* @return An unmodifiable list of all functions
* @apiNote Breaking change: s/SKFunciton<?>/SKFunction/
*/
List<SKFunction<?>> getAll();
List<SKFunction> getAll();
}
@@ -1,13 +1,15 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.skilldefinition;
import java.util.Map;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import com.microsoft.semantickernel.builders.Buildable;
import com.microsoft.semantickernel.builders.BuildersSingleton;
import com.microsoft.semantickernel.builders.SemanticKernelBuilder;
import com.microsoft.semantickernel.orchestration.SKFunction;
import java.util.Map;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
/**
* Skill collection interface.
@@ -34,12 +36,17 @@ public interface ReadOnlySkillCollection extends Buildable {
ReadOnlyFunctionCollection getAllFunctions();
/** Get function with name from the global scope */
/** Get function with name from the global scope
* @apiNote Breaking change: s/SKFunciton<?>/SKFunction/
*/
@Nullable
<T extends SKFunction<?>> T getFunction(String functionName, @Nullable Class<T> functionType);
<T extends SKFunction> T getFunction(String functionName, @Nullable Class<T> functionType);
/**
* @apiNote Breaking change: s/SKFunciton<?>/SKFunction/
*/
@Nullable
<T extends SKFunction<?>> T getFunction(
<T extends SKFunction> T getFunction(
String skillName, String funName, @Nullable Class<T> functionClazz);
@Nullable
@@ -1,6 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.textcompletion;
import java.util.List;
import javax.annotation.Nullable;
import com.microsoft.semantickernel.Kernel;
import com.microsoft.semantickernel.builders.Buildable;
import com.microsoft.semantickernel.builders.BuildersSingleton;
@@ -9,12 +13,11 @@ import com.microsoft.semantickernel.orchestration.SKContext;
import com.microsoft.semantickernel.orchestration.SKFunction;
import com.microsoft.semantickernel.semanticfunctions.PromptTemplateConfig;
import com.microsoft.semantickernel.semanticfunctions.SemanticFunctionConfig;
import java.util.List;
import javax.annotation.Nullable;
import reactor.core.publisher.Mono;
/** Semantic function for text completion */
public interface CompletionSKFunction extends SKFunction<CompletionRequestSettings>, Buildable {
public interface CompletionSKFunction extends SKFunction, Buildable {
/**
* Method to aggregate partitioned results of a semantic function.
@@ -23,6 +26,7 @@ public interface CompletionSKFunction extends SKFunction<CompletionRequestSettin
* @param context Semantic Kernel context
* @return Aggregated results
*/
@Deprecated
Mono<SKContext> aggregatePartitionedResultsAsync(
List<String> partitionedInput, @Nullable SKContext context);