ContextVariable<T> Class
- java.
lang. Object - com.
microsoft. semantickernel. contextvariables. ContextVariable<T>
- com.
Type Parameters
- T
the type of the context variable
public class ContextVariable<T>
A context variable wraps an arbitrary value and a ContextVariableType. ContextVariableType is used throughout the Semantic Kernel for passing arguments to functions and as function return types.
Constructor Summary
| Constructor | Description |
|---|---|
| ContextVariable(ContextVariableType<T> type, T value) |
Creates a new instance of the ContextVariable<T> class. |
Method Summary
| Modifier and Type | Method and Description |
|---|---|
|
static
Context |
<T,U>convert(U it, ContextVariableType<T> requestedResultType)
Converts the given value to the requested result type. |
|
static
Context |
<T,U>convert(U it, Class<T> requestedResultType, ContextVariableTypes contextVariableTypes)
Converts the given value to the requested result type. |
|
static
Context |
of(T value, ContextVariableTypeConverter<T> converter)
Creates a new instance of the ContextVariable<T> class. |
| U |
getValue(Class<U> clazz)
Get the value of the context variable. |
|
Context |
getType()
Get the type of the context variable. |
| T |
getValue()
Get the value of the context variable. |
| boolean |
isEmpty()
Returns true if the value of this |
|
static
Context |
of(CompletionsUsage x)
Convenience method for creating a |
|
static
Context |
of(String value)
Convenience method for creating a |
|
static
Context |
of(OffsetDateTime x)
Convenience method for creating a |
|
static
Context |
ofGlobalType(Object x)
Convenience method for creating a |
| java.lang.String |
toPromptString()
Use the given |
| java.lang.String |
toPromptString(ContextVariableTypes types)
Use the given |
| java.lang.String |
toPromptString(ContextVariableTypes types, ContextVariableTypeConverter<T> converter)
Use the given |
|
static
Context |
untypedOf(Object value, Class<?> clazz, ContextVariableTypes types)
Creates a new instance of the ContextVariable<T> class without using strong typing. |
Methods inherited from java.lang.Object
Constructor Details
ContextVariable
public ContextVariable(ContextVariableType<T> type, T value)
Creates a new instance of the ContextVariable<T> class.
Parameters:
Method Details
<T,U>convert
public static ContextVariable<T> <T,U>convert(U it, ContextVariableType<T> requestedResultType)
Converts the given value to the requested result type.
Parameters:
Returns:
<T,U>convert
public static ContextVariable<T> <T,U>convert(U it, Class<T> requestedResultType, ContextVariableTypes contextVariableTypes)
Converts the given value to the requested result type. The ContextVariableTypes parameter is used to find the appropriate converter for the input value and the requested result type.
Parameters:
Returns:
of
public static ContextVariable<T> <T>of(T value, ContextVariableTypeConverter<T> converter)
Creates a new instance of the ContextVariable<T> class.
Parameters:
Returns:
getValue
public U getValue(Class clazz)
Get the value of the context variable.
Parameters:
Returns:
getType
public ContextVariableType<T> getType()
Get the type of the context variable.
Returns:
getValue
public T getValue()
Get the value of the context variable.
Returns:
isEmpty
public boolean isEmpty()
Returns true if the value of this ContextVariable is null or empty.
Returns:
null or emptyof
public static ContextVariable<CompletionsUsage> of(CompletionsUsage x)
Convenience method for creating a ContextVariable from the given CompletionsUsage instance.
Parameters:
Returns:
of
public static ContextVariable<String> of(String value)
Convenience method for creating a ContextVariable from the given String instance.
Parameters:
Returns:
of
public static ContextVariable<OffsetDateTime> of(OffsetDateTime x)
Convenience method for creating a ContextVariable from the given OffsetDateTime instance.
Parameters:
Returns:
ofGlobalType
public static ContextVariable<Object> ofGlobalType(Object x)
Convenience method for creating a ContextVariable from the given object.
Parameters:
Returns:
toPromptString
public String toPromptString()
Use the given ContextVariableTypeConverter to convert the value of this ContextVariable to a prompt string. This method is useful when the convert of this ContextVariableType does not create the expected prompt string.
Returns:
ContextVariable as a prompt stringtoPromptString
public String toPromptString(ContextVariableTypes types)
Use the given ContextVariableTypeConverter to convert the value of this ContextVariable to a prompt string. This method is useful when the convert of this ContextVariableType does not create the expected prompt string.
Parameters:
Returns:
ContextVariable as a prompt stringtoPromptString
public String toPromptString(ContextVariableTypes types, ContextVariableTypeConverter<T> converter)
Use the given ContextVariableTypeConverter to convert the value of this ContextVariable to a prompt string. This method is useful when the convert of this ContextVariableType does not create the expected prompt string.
Parameters:
null the global types
are used
Returns:
ContextVariable as a prompt stringuntypedOf
public static ContextVariable untypedOf(Object value, Class clazz, ContextVariableTypes types)
Creates a new instance of the ContextVariable<T> class without using strong typing.
Parameters:
Returns: