Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -149,7 +150,13 @@ public Map<String, JsonNode> getProperties() {
private static String getSchemaForFunctionParameter(@Nullable InputVariable parameter) {
List<String> entries = new ArrayList<>();

entries.add("\"type\":\"string\"");
String type = "string";

if (parameter != null && parameter.getType() != null) {
type = getJavaTypeToOpenAiFunctionType(parameter.getType());
}

entries.add("\"type\":\"" + type + "\"");

// Add description if present
if (parameter != null && parameter.getDescription() != null && !parameter.getDescription()
Expand Down Expand Up @@ -179,4 +186,28 @@ private static String getSchemaForFunctionParameter(@Nullable InputVariable para

return "{" + schema + "}";
}

private static String getJavaTypeToOpenAiFunctionType(String javaType) {
switch (javaType.toLowerCase(Locale.ROOT)) {
case "boolean":
return "boolean";
case "integer":
case "int":
case "long":
case "short":
case "byte":
return "integer";
case "double":
case "float":
return "number";
case "string":
return "string";
case "array":
return "array";
case "void":
return "null";
default:
return "object";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public List<LightModel> getLights() {

@DefineKernelFunction(name = "change_state", description = "Changes the state of the light")
public LightModel changeState(
@KernelFunctionParameter(name = "id", description = "The ID of the light to change") int id,
@KernelFunctionParameter(name = "isOn", description = "The new state of the light") boolean isOn) {
@KernelFunctionParameter(name = "id", description = "The ID of the light to change", type = int.class) int id,
@KernelFunctionParameter(name = "isOn", description = "The new state of the light", type = boolean.class) boolean isOn) {
System.out.println("Changing light " + id + " " + isOn);
Optional<LightModel> light = lights.stream()
.filter(l -> l.getId() == id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ private static Object toObjectType(
ContextVariableTypeConverter<?> c = sourceType.getConverter();

Object converted = c.toObject(invocationContext.getContextVariableTypes(), sourceValue,
targetArgType);
targetArgType, false);
if (converted != null) {
return converted;
}
Expand Down