Fix typos

This commit is contained in:
John Oliver
2024-05-02 16:51:12 +01:00
parent 40706571fd
commit 7689013de3
15 changed files with 56 additions and 57 deletions
@@ -105,7 +105,7 @@ class XMLPromptParser {
XMLEventReader reader = factory.createXMLEventReader(is);
FunctionDefinition functionDefinition = null;
Map<String, String> parameters = new HashMap<>();
List<String> requiredParmeters = new ArrayList<>();
List<String> requiredParameters = new ArrayList<>();
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
@@ -113,7 +113,7 @@ class XMLPromptParser {
if (elementName.equals("function")) {
assert functionDefinition == null;
assert parameters.isEmpty();
assert requiredParmeters.isEmpty();
assert requiredParameters.isEmpty();
String pluginName = getAttributeValue(event, "pluginName");
String name = getAttributeValue(event, "name");
String description = getAttributeValue(event, "description");
@@ -132,7 +132,7 @@ class XMLPromptParser {
String isRequired = getAttributeValue(event, "isRequired");
if (Boolean.parseBoolean(isRequired)) {
requiredParmeters.add(name);
requiredParameters.add(name);
}
}
} else if (event.isEndElement()) {
@@ -169,9 +169,9 @@ class XMLPromptParser {
});
// strip off trailing comma and close the properties object
sb.replace(sb.length() - 1, sb.length(), "}");
if (!requiredParmeters.isEmpty()) {
if (!requiredParameters.isEmpty()) {
sb.append(", \"required\": [");
requiredParmeters.forEach(name -> {
requiredParameters.forEach(name -> {
sb.append(String.format("\"%s\",", name));
});
// strip off trailing comma and close the required array
@@ -188,7 +188,7 @@ class XMLPromptParser {
functionDefinitions.add(functionDefinition);
functionDefinition = null;
parameters.clear();
requiredParmeters.clear();
requiredParameters.clear();
}
}
}
+2 -3
View File
@@ -7,7 +7,6 @@
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="10"/>
<setting id="org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines" value="2147483647"/>
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
@@ -400,10 +399,10 @@
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration"
value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statement" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_method_declaration" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause" value="common_lines"/>
@@ -42,13 +42,13 @@ public class Example08_RetryHandler {
String question = "How popular is the Polly library?";
KernelFunction<String> fuction = KernelFunctionFromPrompt.<String>builder()
KernelFunction<String> function = KernelFunctionFromPrompt.<String>builder()
.withTemplate(question)
.build();
try {
// Will retry 3 times with exponential backoff
kernel.invokeAsync(fuction).block();
kernel.invokeAsync(function).block();
} catch (Exception e) {
System.out.println("Hit max retries");
}
@@ -264,17 +264,17 @@ public class Example09_FunctionTypes {
.block();
var result10 = kernel
.invokeAsync(plugin.get("WithPrimativeReturnType"))
.invokeAsync(plugin.get("WithPrimitiveReturnType"))
.block();
System.out.println(result10.getResult());
var result11 = kernel
.invokeAsync(plugin.get("WithBoxedPrimativeReturnType"))
.invokeAsync(plugin.get("WithBoxedPrimitiveReturnType"))
.block();
System.out.println(result11.getResult());
var result12 = kernel
.invokeAsync(plugin.get("AsyncWithBoxedPrimativeReturnType"))
.invokeAsync(plugin.get("AsyncWithBoxedPrimitiveReturnType"))
.block();
System.out.println(result12.getResult());
@@ -520,18 +520,18 @@ public class Example09_FunctionTypes {
+ "}, y = {" + y + "}]");
}
@DefineKernelFunction(name = "WithPrimativeReturnType", returnType = "int")
public int WithPrimativeReturnType() {
@DefineKernelFunction(name = "WithPrimitiveReturnType", returnType = "int")
public int WithPrimitiveReturnType() {
return 1;
}
@DefineKernelFunction(name = "WithBoxedPrimativeReturnType", returnType = "int")
public Integer WithBoxedPrimativeReturnType() {
@DefineKernelFunction(name = "WithBoxedPrimitiveReturnType", returnType = "int")
public Integer WithBoxedPrimitiveReturnType() {
return Integer.valueOf(1);
}
@DefineKernelFunction(name = "AsyncWithBoxedPrimativeReturnType", returnType = "int")
public Mono<Integer> AsyncWithBoxedPrimativeReturnType() {
@DefineKernelFunction(name = "AsyncWithBoxedPrimitiveReturnType", returnType = "int")
public Mono<Integer> AsyncWithBoxedPrimitiveReturnType() {
return Mono.just(Integer.valueOf(1));
}
@@ -102,7 +102,7 @@ public class Example13_ConversationSummaryPlugin {
Jane: Lorem ipsum dolor sit amet, con
Jane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam
Jane: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc sit amet aliquam
Jane: Darn, it's just repeating stuf now.
Jane: Darn, it's just repeating stuff now.
John: I think we're done.
Jane: We're not though! We need like 1500 more characters.
John: Oh Cananda, our home and native land.
@@ -144,7 +144,7 @@ public class SemanticKernelOpenAPIImporter {
@Nullable HttpHeaders httpHeaders,
@Nullable HttpClient client) {
// Currently this does not apply as the Netty client does not obay the headers provided in the
// Currently this does not apply as the Netty client does not obey the headers provided in the
// HttpClientOptions, however they may do one day
if (httpHeaders != null && client != null) {
throw new IllegalArgumentException(
@@ -234,7 +234,7 @@ public class ContextVariableTypeConverter<T> {
/**
* A converter that does no conversion. This converter is often used as a default when no other
* conveter can be found for the type.
* converter can be found for the type.
*
* @param <T> the type of the context variable
*/
@@ -110,12 +110,12 @@ public class ContextVariableTypes {
/**
* Add a converter to the global collection of context variable type converters.
*
* @param conveter The converter to add.
* @param converter The converter to add.
* @see #getGlobalVariableTypeForClass(Class)
*/
public static void addGlobalConverter(
ContextVariableTypeConverter<?> conveter) {
DEFAULT_TYPES.putConverter(conveter);
ContextVariableTypeConverter<?> converter) {
DEFAULT_TYPES.putConverter(converter);
}
/**
@@ -10,7 +10,7 @@ import java.util.function.Function;
import javax.annotation.Nullable;
/**
* A {@link ContextVariableTypeConverter} for primative variables.
* A {@link ContextVariableTypeConverter} for primitive variables.
*
* @param <T> the type of the variable
*/
@@ -24,7 +24,7 @@ public class PrimitiveVariableContextVariableTypeConverter<T> extends
*
* @param clazz the class
* @param fromPromptString the function to convert from a prompt string
* @param fromObject the function to convert from an object to primative
* @param fromObject the function to convert from an object to primitive
*/
public PrimitiveVariableContextVariableTypeConverter(
Class<T> clazz,
@@ -311,7 +311,7 @@ public class FunctionInvocation<T> extends Mono<FunctionResult<T>> {
}
/**
* This method hanldes the reactive stream when the KernelFunciton is invoked.
* This method handles the reactive stream when the KernelFunction is invoked.
*
* @param coreSubscriber The subscriber to subscribe to the function invocation.
*/
@@ -227,7 +227,7 @@ public class PromptExecutionSettings {
/**
* Presence penalty encourages the model to use a more or less diverse range of tokens in the
* output. A higher value means that the model will try to use a greater variety of tokens in
* the ouput.
* the output.
*
* @return The presence penalty setting.
*/
@@ -45,20 +45,20 @@ public class KernelPluginFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(KernelPluginFactory.class);
private static final String CONFIG_FILE = "config.json";
private static final String PROMPT_FILE = "skprompt.txt";
private static final CaseInsensitiveMap<Class<?>> PRIMATIVE_CLASS_NAMES = new CaseInsensitiveMap<>();
private static final CaseInsensitiveMap<Class<?>> PRIMITIVE_CLASS_NAMES = new CaseInsensitiveMap<>();
private static final CaseInsensitiveMap<Class<?>> COMMON_CLASS_NAMES = new CaseInsensitiveMap<>();
private static final Map<Class<?>, Class<?>> BOXED_FROM_PRIMATIVE = new HashMap<>();
private static final Map<Class<?>, Class<?>> BOXED_FROM_PRIMITIVE = new HashMap<>();
static {
PRIMATIVE_CLASS_NAMES.put("void", void.class);
PRIMATIVE_CLASS_NAMES.put("int", int.class);
PRIMATIVE_CLASS_NAMES.put("double", double.class);
PRIMATIVE_CLASS_NAMES.put("boolean", boolean.class);
PRIMATIVE_CLASS_NAMES.put("float", float.class);
PRIMATIVE_CLASS_NAMES.put("long", long.class);
PRIMATIVE_CLASS_NAMES.put("short", short.class);
PRIMATIVE_CLASS_NAMES.put("byte", byte.class);
PRIMATIVE_CLASS_NAMES.put("char", char.class);
PRIMITIVE_CLASS_NAMES.put("void", void.class);
PRIMITIVE_CLASS_NAMES.put("int", int.class);
PRIMITIVE_CLASS_NAMES.put("double", double.class);
PRIMITIVE_CLASS_NAMES.put("boolean", boolean.class);
PRIMITIVE_CLASS_NAMES.put("float", float.class);
PRIMITIVE_CLASS_NAMES.put("long", long.class);
PRIMITIVE_CLASS_NAMES.put("short", short.class);
PRIMITIVE_CLASS_NAMES.put("byte", byte.class);
PRIMITIVE_CLASS_NAMES.put("char", char.class);
COMMON_CLASS_NAMES.put("integer", int.class);
COMMON_CLASS_NAMES.put("string", String.class);
@@ -66,15 +66,15 @@ public class KernelPluginFactory {
COMMON_CLASS_NAMES.put("map", HashMap.class);
COMMON_CLASS_NAMES.put("set", HashSet.class);
BOXED_FROM_PRIMATIVE.put(void.class, Void.class);
BOXED_FROM_PRIMATIVE.put(int.class, Integer.class);
BOXED_FROM_PRIMATIVE.put(double.class, Double.class);
BOXED_FROM_PRIMATIVE.put(boolean.class, Boolean.class);
BOXED_FROM_PRIMATIVE.put(float.class, Float.class);
BOXED_FROM_PRIMATIVE.put(long.class, Long.class);
BOXED_FROM_PRIMATIVE.put(short.class, Short.class);
BOXED_FROM_PRIMATIVE.put(byte.class, Byte.class);
BOXED_FROM_PRIMATIVE.put(char.class, Character.class);
BOXED_FROM_PRIMITIVE.put(void.class, Void.class);
BOXED_FROM_PRIMITIVE.put(int.class, Integer.class);
BOXED_FROM_PRIMITIVE.put(double.class, Double.class);
BOXED_FROM_PRIMITIVE.put(boolean.class, Boolean.class);
BOXED_FROM_PRIMITIVE.put(float.class, Float.class);
BOXED_FROM_PRIMITIVE.put(long.class, Long.class);
BOXED_FROM_PRIMITIVE.put(short.class, Short.class);
BOXED_FROM_PRIMITIVE.put(byte.class, Byte.class);
BOXED_FROM_PRIMITIVE.put(char.class, Character.class);
}
@@ -205,7 +205,7 @@ public class KernelPluginFactory {
*/
@Nullable
private static Class<?> getCommonTypeAlias(Method method, String className) {
Class<?> returnType = PRIMATIVE_CLASS_NAMES.get(className);
Class<?> returnType = PRIMITIVE_CLASS_NAMES.get(className);
if (returnType == null) {
returnType = COMMON_CLASS_NAMES.get(className);
@@ -216,7 +216,7 @@ public class KernelPluginFactory {
}
if (returnType != null && !returnType.isAssignableFrom(method.getReturnType())) {
returnType = BOXED_FROM_PRIMATIVE.get(returnType);
returnType = BOXED_FROM_PRIMITIVE.get(returnType);
}
return returnType;
@@ -229,7 +229,7 @@ public class KernelPluginFactory {
* @return The class for the type name.
*/
public static Class<?> getTypeForName(String className) {
Class<?> clazz = PRIMATIVE_CLASS_NAMES.get(className);
Class<?> clazz = PRIMITIVE_CLASS_NAMES.get(className);
if (clazz == null) {
clazz = COMMON_CLASS_NAMES.get(className);
@@ -451,7 +451,7 @@ public class KernelFunctionFromMethod<T> extends KernelFunction<T> {
return arg.getValue();
}
if (isPrimative(arg.getType().getClazz(), parameter.getType())) {
if (isPrimitive(arg.getType().getClazz(), parameter.getType())) {
return arg.getValue();
}
@@ -492,7 +492,7 @@ public class KernelFunctionFromMethod<T> extends KernelFunction<T> {
}
@SuppressWarnings("OperatorPrecedence")
private static boolean isPrimative(Class<?> argType, Class<?> param) {
private static boolean isPrimitive(Class<?> argType, Class<?> param) {
return (argType == Byte.class || argType == byte.class) && (param == Byte.class
|| param == byte.class) ||
(argType == Integer.class || argType == int.class) && (param == Integer.class
@@ -112,7 +112,7 @@ public class KernelFunctionFromPrompt<T> extends KernelFunction<T> {
KernelFunctionArguments arguments = preRenderingHookResult.getArguments();
// TOOD: put in method, add catch for classcastexception, fallback to noopconverter
// TODO: put in method, add catch for classcastexception, fallback to noopconverter
ContextVariableType<T> variableType = contextVariableType != null
? contextVariableType
: context.getContextVariableTypes().getVariableTypeForClass(
@@ -71,7 +71,7 @@ public class PromptExecutionSettingsTest {
}
@Test
void testJsonDeserialze() throws Exception {
void testJsonDeserialize() throws Exception {
String json = "{"
+ "\"service_id\":\"custom-service\","
+ "\"max_tokens\":512,"