Class ContextVariableTypeConverter<T>
- java.lang.Object
-
- com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter<T>
-
- Type Parameters:
T- the type of the context variable
- Direct Known Subclasses:
BooleanVariableContextVariableTypeConverter,CharacterVariableContextVariableTypeConverter,ChatHistoryVariableContextVariableTypeConverter,CollectionVariableContextVariableTypeConverter,CompletionUsageContextVariableTypeConverter,ContextVariableTypeConverter.NoopConverter,DateTimeContextVariableTypeConverter,InstantContextVariableTypeConverter,PrimitiveVariableContextVariableTypeConverter,StringVariableContextVariableTypeConverter,TextContentVariableContextVariableTypeConverter,VoidVariableContextVariableTypeConverter
public class ContextVariableTypeConverter<T> extends Object
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classContextVariableTypeConverter.Builder<T>A builder for a context variable type converter.static interfaceContextVariableTypeConverter.Converter<T,U>A converter from one type to another.static classContextVariableTypeConverter.DefaultConverter<T,U>A base class for concrete implementations ofContextVariableTypeConverter.Converter.static classContextVariableTypeConverter.NoopConverter<T>A converter that does no conversion.static interfaceContextVariableTypeConverter.ToPromptStringFunction<T>
-
Constructor Summary
Constructors Constructor Description ContextVariableTypeConverter(Class<T> clazz, Function<Object,T> fromObject, ContextVariableTypeConverter.ToPromptStringFunction<T> toPromptString, Function<String,T> fromPromptString)Create a new context variable type converter.ContextVariableTypeConverter(Class<T> clazz, Function<Object,T> fromObject, ContextVariableTypeConverter.ToPromptStringFunction<T> toPromptString, Function<String,T> fromPromptString, List<ContextVariableTypeConverter.Converter<T,?>> toObjects)Create a new context variable type converter.ContextVariableTypeConverter(Class<T> clazz, Function<Object,T> fromObject, Function<T,String> toPromptString, Function<String,T> fromPromptString)Create a new context variable type converter.ContextVariableTypeConverter(Class<T> clazz, Function<Object,T> fromObject, Function<T,String> toPromptString, Function<String,T> fromPromptString, List<ContextVariableTypeConverter.Converter<T,?>> toObjects)Create a new context variable type converter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> ContextVariableTypeConverter.Builder<T>builder(Class<T> clazz)Create a new builder for a context variable type converter.static StringescapeXmlString(String value)To be used when toPromptString is calledTfromObject(Object s)Convert the object to the type of the context variable using thefromObjectfunction provided to the constructor.TfromPromptString(String t)Convert the prompt string to the type using thefromPromptStringfunction provided to the constructor.Class<T>getType()Get the class of the type.<U> UtoObject(ContextVariableTypes types, Object t, Class<U> clazz)Use this converter to convert the object to the type of the context variable.StringtoPromptString(ContextVariableTypes types, T t)Convert the type to a prompt string using thetoPromptStringfunction provided to the constructor.
-
-
-
Constructor Detail
-
ContextVariableTypeConverter
public ContextVariableTypeConverter(Class<T> clazz, Function<Object,T> fromObject, Function<T,String> toPromptString, Function<String,T> fromPromptString)
Create a new context variable type converter.- Parameters:
clazz- the class of the typefromObject- a function to convert an object to the typetoPromptString- a function to convert the type to a prompt stringfromPromptString- a function to convert a prompt string to the type
-
ContextVariableTypeConverter
public ContextVariableTypeConverter(Class<T> clazz, Function<Object,T> fromObject, ContextVariableTypeConverter.ToPromptStringFunction<T> toPromptString, Function<String,T> fromPromptString)
Create a new context variable type converter.- Parameters:
clazz- the class of the typefromObject- a function to convert an object to the typetoPromptString- a function to convert the type to a prompt stringfromPromptString- a function to convert a prompt string to the type
-
ContextVariableTypeConverter
public ContextVariableTypeConverter(Class<T> clazz, Function<Object,T> fromObject, ContextVariableTypeConverter.ToPromptStringFunction<T> toPromptString, Function<String,T> fromPromptString, List<ContextVariableTypeConverter.Converter<T,?>> toObjects)
Create a new context variable type converter.- Parameters:
clazz- the class of the typefromObject- a function to convert an object to the typetoPromptString- a function to convert the type to a prompt stringfromPromptString- a function to convert a prompt string to the typetoObjects- a list of converters to convert the type to other types
-
ContextVariableTypeConverter
public ContextVariableTypeConverter(Class<T> clazz, Function<Object,T> fromObject, Function<T,String> toPromptString, Function<String,T> fromPromptString, List<ContextVariableTypeConverter.Converter<T,?>> toObjects)
Create a new context variable type converter.- Parameters:
clazz- the class of the typefromObject- a function to convert an object to the typetoPromptString- a function to convert the type to a prompt stringfromPromptString- a function to convert a prompt string to the typetoObjects- a list of converters to convert the type to other types
-
-
Method Detail
-
toObject
@Nullable public <U> U toObject(ContextVariableTypes types, @Nullable Object t, Class<U> clazz)
Use this converter to convert the object to the type of the context variable.- Type Parameters:
U- the type to convert to- Parameters:
t- the object to convertclazz- the class of the type to convert to- Returns:
- the converted object
-
fromObject
@Nullable public T fromObject(@Nullable Object s)
Convert the object to the type of the context variable using thefromObjectfunction provided to the constructor.- Parameters:
s- the object to convert- Returns:
- the converted object
-
toPromptString
public String toPromptString(@Nullable ContextVariableTypes types, @Nullable T t)
Convert the type to a prompt string using thetoPromptStringfunction provided to the constructor.- Parameters:
types- the context variable types, ifnullthe global types are usedt- the type to convert- Returns:
- the prompt string
-
fromPromptString
@Nullable public T fromPromptString(@Nullable String t)
Convert the prompt string to the type using thefromPromptStringfunction provided to the constructor.- Parameters:
t- the prompt string to convert- Returns:
- the type
-
builder
public static <T> ContextVariableTypeConverter.Builder<T> builder(Class<T> clazz)
Create a new builder for a context variable type converter.- Type Parameters:
T- the type of the context variable- Parameters:
clazz- the class of the type- Returns:
- the builder
-
-