Share via


ContextVariableTypeConverter<T> Class

  • java.lang.Object
    • com.microsoft.semantickernel.contextvariables.ContextVariableTypeConverter<T>

Type Parameters

T

the type of the context variable

public class ContextVariableTypeConverter<T>

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.

Constructor Summary

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

Modifier and Type Method and Description
static Builder<T> builder(Class<T> clazz)

Create a new builder for a context variable type converter.

U toObject(ContextVariableTypes types, Object t, Class<U> clazz)

Use this converter to convert the object to the type of the context variable.

U toObject(ContextVariableTypes types, Object t, Class<U> clazz, boolean logWarnings)

Use this converter to convert the object to the type of the context variable.

static java.lang.String escapeXmlString(String value)

To be used when toPromptString is called

T fromObject(Object s)

Convert the object to the type of the context variable using the fromObject function provided to the constructor.

T fromPromptString(String t)

Convert the prompt string to the type using the fromPromptString function provided to the constructor.

java.lang.Class<T> getType()

Get the class of the type.

java.lang.String toPromptString(ContextVariableTypes types, T t)

Convert the type to a prompt string using the toPromptString function provided to the constructor.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

ContextVariableTypeConverter

public ContextVariableTypeConverter(Class clazz, Function fromObject, ContextVariableTypeConverter.ToPromptStringFunction toPromptString, Function fromPromptString)

Create a new context variable type converter.

Parameters:

clazz - the class of the type
fromObject - a function to convert an object to the type
toPromptString - a function to convert the type to a prompt string
fromPromptString - a function to convert a prompt string to the type

ContextVariableTypeConverter

public ContextVariableTypeConverter(Class clazz, Function fromObject, ContextVariableTypeConverter.ToPromptStringFunction toPromptString, Function fromPromptString, List> toObjects)

Create a new context variable type converter.

Parameters:

clazz - the class of the type
fromObject - a function to convert an object to the type
toPromptString - a function to convert the type to a prompt string
fromPromptString - a function to convert a prompt string to the type
toObjects - a list of converters to convert the type to other types

ContextVariableTypeConverter

public ContextVariableTypeConverter(Class clazz, Function fromObject, Function toPromptString, Function fromPromptString)

Create a new context variable type converter.

Parameters:

clazz - the class of the type
fromObject - a function to convert an object to the type
toPromptString - a function to convert the type to a prompt string
fromPromptString - a function to convert a prompt string to the type

ContextVariableTypeConverter

public ContextVariableTypeConverter(Class clazz, Function fromObject, Function toPromptString, Function fromPromptString, List> toObjects)

Create a new context variable type converter.

Parameters:

clazz - the class of the type
fromObject - a function to convert an object to the type
toPromptString - a function to convert the type to a prompt string
fromPromptString - a function to convert a prompt string to the type
toObjects - a list of converters to convert the type to other types

Method Details

builder

public static ContextVariableTypeConverter.Builder builder(Class clazz)

Create a new builder for a context variable type converter.

Parameters:

clazz - the class of the type

Returns:

the builder

toObject

public U toObject(ContextVariableTypes types, Object t, Class clazz)

Use this converter to convert the object to the type of the context variable.

Parameters:

types - the context variable types
t - the object to convert
clazz - the class of the type to convert to

Returns:

the converted object

toObject

public U toObject(ContextVariableTypes types, Object t, Class clazz, boolean logWarnings)

Use this converter to convert the object to the type of the context variable.

Parameters:

types - the context variable types
t - the object to convert
clazz - the class of the type to convert to
logWarnings - whether to log warnings

Returns:

the converted object

escapeXmlString

public static String escapeXmlString(String value)

To be used when toPromptString is called

Parameters:

value - the value to escape

Returns:

the escaped value

fromObject

public T fromObject(Object s)

Convert the object to the type of the context variable using the fromObject function provided to the constructor.

Parameters:

s - the object to convert

Returns:

the converted object

fromPromptString

public T fromPromptString(String t)

Convert the prompt string to the type using the fromPromptString function provided to the constructor.

Parameters:

t - the prompt string to convert

Returns:

the type

getType

public Class getType()

Get the class of the type.

Returns:

the class of the type

toPromptString

public String toPromptString(ContextVariableTypes types, T t)

Convert the type to a prompt string using the toPromptString function provided to the constructor.

Parameters:

types - the context variable types, if null the global types are used
t - the type to convert

Returns:

the prompt string

Applies to