diff --git a/.devfile.yaml b/.devfile.yaml new file mode 100644 index 00000000..08347c23 --- /dev/null +++ b/.devfile.yaml @@ -0,0 +1,26 @@ +schemaVersion: 2.2.2 +metadata: + attributes: + metadata-name-field: generateName + metadata-name-original-value: simple-openai + name: simple-openai + namespace: sashirestela-dev +attributes: + che-theia.eclipse.org/sidecar-policy: mergeImage +projects: + - name: simple-openai + git: + remotes: + origin: https://github.com/sashirestela/simple-openai.git +components: + - name: universal-developer-image + container: + image: quay.io/devfile/universal-developer-image:ubi8-latest + volumeMounts: + - name: m2 + path: /home/user/.m2 + mountSources: true + - name: m2 + volume: + size: 5Gi +commands: [] \ No newline at end of file diff --git a/.sdkmanrc b/.sdkmanrc new file mode 100644 index 00000000..65ab504c --- /dev/null +++ b/.sdkmanrc @@ -0,0 +1,3 @@ +# Enable auto-env through the sdkman_auto_env config +# Add key=value pairs of SDKs to use below +java=11.0.15-tem diff --git a/pom.xml b/pom.xml index 92704e9e..c376394b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.sashirestela simple-openai - 1.2.3 + 1.2.4 jar simple-openai @@ -52,7 +52,7 @@ 11 [2.0.9,3.0.0) - 0.11.1 + 0.12.0 [1.18.30,2.0.0) [2.15.2,3.0.0) [4.31.1,5.0.0) diff --git a/src/main/java/io/github/sashirestela/openai/function/FunctionExecutor.java b/src/main/java/io/github/sashirestela/openai/function/FunctionExecutor.java index 09140c59..2e8a1f8e 100644 --- a/src/main/java/io/github/sashirestela/openai/function/FunctionExecutor.java +++ b/src/main/java/io/github/sashirestela/openai/function/FunctionExecutor.java @@ -57,7 +57,7 @@ public T execute(ChatFunctionCall functionToCall) { } try { var function = mapFunctions.get(functionName); - var object = JsonUtil.jsonToObjectStrict(functionToCall.getArguments(), function.getFunctionalClass()); + var object = JsonUtil.jsonToObject(functionToCall.getArguments(), function.getFunctionalClass()); return (T) object.execute(); } catch (RuntimeException e) { throw new SimpleUncheckedException("Cannot execute the function {0}.", functionName, e); diff --git a/src/test/java/io/github/sashirestela/openai/SimpleOpenAITest.java b/src/test/java/io/github/sashirestela/openai/SimpleOpenAITest.java index a097e7e0..9d2b34b4 100644 --- a/src/test/java/io/github/sashirestela/openai/SimpleOpenAITest.java +++ b/src/test/java/io/github/sashirestela/openai/SimpleOpenAITest.java @@ -22,7 +22,7 @@ import org.mockito.ArgumentCaptor; import io.github.sashirestela.cleverclient.CleverClient; -import io.github.sashirestela.cleverclient.http.HttpInvocationHandler; +import io.github.sashirestela.cleverclient.http.HttpProcessor; import io.github.sashirestela.cleverclient.util.ReflectUtil; import io.github.sashirestela.openai.domain.chat.ChatRequest; @@ -128,7 +128,7 @@ void shouldInstanceAudioServiceOnlyOnceWhenItIsCalledSeveralTimes() { when(cleverClient.create(any())) .thenReturn(ReflectUtil.createProxy( OpenAI.Audios.class, - new HttpInvocationHandler(null))); + new HttpProcessor(null, null, null))); repeat(NUMBER_CALLINGS, () -> openAI.audios()); verify(cleverClient, times(NUMBER_INVOCATIONS)).create(any()); } @@ -138,7 +138,7 @@ void shouldInstanceChatCompletionServiceOnlyOnceWhenItIsCalledSeveralTimes() { when(cleverClient.create(any())) .thenReturn(ReflectUtil.createProxy( OpenAI.ChatCompletions.class, - new HttpInvocationHandler(null))); + new HttpProcessor(null, null, null))); repeat(NUMBER_CALLINGS, () -> openAI.chatCompletions()); verify(cleverClient, times(NUMBER_INVOCATIONS)).create(any()); } @@ -148,7 +148,7 @@ void shouldInstanceCompletionServiceOnlyOnceWhenItIsCalledSeveralTimes() { when(cleverClient.create(any())) .thenReturn(ReflectUtil.createProxy( OpenAI.Completions.class, - new HttpInvocationHandler(null))); + new HttpProcessor(null, null, null))); repeat(NUMBER_CALLINGS, () -> openAI.completions()); verify(cleverClient, times(NUMBER_INVOCATIONS)).create(any()); } @@ -158,7 +158,7 @@ void shouldInstanceEmbeddingServiceOnlyOnceWhenItIsCalledSeveralTimes() { when(cleverClient.create(any())) .thenReturn(ReflectUtil.createProxy( OpenAI.Embeddings.class, - new HttpInvocationHandler(null))); + new HttpProcessor(null, null, null))); repeat(NUMBER_CALLINGS, () -> openAI.embeddings()); verify(cleverClient, times(NUMBER_INVOCATIONS)).create(any()); } @@ -168,7 +168,7 @@ void shouldInstanceFilesServiceOnlyOnceWhenItIsCalledSeveralTimes() { when(cleverClient.create(any())) .thenReturn(ReflectUtil.createProxy( OpenAI.Files.class, - new HttpInvocationHandler(null))); + new HttpProcessor(null, null, null))); repeat(NUMBER_CALLINGS, () -> openAI.files()); verify(cleverClient, times(NUMBER_INVOCATIONS)).create(any()); } @@ -178,7 +178,7 @@ void shouldInstanceFineTunningServiceOnlyOnceWhenItIsCalledSeveralTimes() { when(cleverClient.create(any())) .thenReturn(ReflectUtil.createProxy( OpenAI.FineTunings.class, - new HttpInvocationHandler(null))); + new HttpProcessor(null, null, null))); repeat(NUMBER_CALLINGS, () -> openAI.fineTunings()); verify(cleverClient, times(NUMBER_INVOCATIONS)).create(any()); } @@ -188,7 +188,7 @@ void shouldInstanceImageServiceOnlyOnceWhenItIsCalledSeveralTimes() { when(cleverClient.create(any())) .thenReturn(ReflectUtil.createProxy( OpenAI.Images.class, - new HttpInvocationHandler(null))); + new HttpProcessor(null, null, null))); repeat(NUMBER_CALLINGS, () -> openAI.images()); verify(cleverClient, times(NUMBER_INVOCATIONS)).create(any()); } @@ -198,7 +198,7 @@ void shouldInstanceModelsServiceOnlyOnceWhenItIsCalledSeveralTimes() { when(cleverClient.create(any())) .thenReturn(ReflectUtil.createProxy( OpenAI.Models.class, - new HttpInvocationHandler(null))); + new HttpProcessor(null, null, null))); repeat(NUMBER_CALLINGS, () -> openAI.models()); verify(cleverClient, times(NUMBER_INVOCATIONS)).create(any()); } @@ -208,7 +208,7 @@ void shouldInstanceModerationServiceOnlyOnceWhenItIsCalledSeveralTimes() { when(cleverClient.create(any())) .thenReturn(ReflectUtil.createProxy( OpenAI.Moderations.class, - new HttpInvocationHandler(null))); + new HttpProcessor(null, null, null))); repeat(NUMBER_CALLINGS, () -> openAI.moderations()); verify(cleverClient, times(NUMBER_INVOCATIONS)).create(any()); } diff --git a/src/test/java/io/github/sashirestela/openai/function/FunctionExecutorTest.java b/src/test/java/io/github/sashirestela/openai/function/FunctionExecutorTest.java index a248f2c7..5af8eb6f 100644 --- a/src/test/java/io/github/sashirestela/openai/function/FunctionExecutorTest.java +++ b/src/test/java/io/github/sashirestela/openai/function/FunctionExecutorTest.java @@ -103,7 +103,7 @@ void shouldThrownAnExceptionWhenTryingToExecuteANonEnrolledFunction() { @Test void shouldThrowAnExceptionWhenTryingToExecuteFunctionArgumentsThatDoNotMatchItsClassStructure() { var executor = new FunctionExecutor(functionList); - var functionToCall = new ChatFunctionCall("exponentiation", "{\"base\":2.0,\"power\":10.0}"); + var functionToCall = new ChatFunctionCall("exponentiation", "{\"base\":2.0,\"exponent\":\"ten\"}"); var exception = assertThrows(SimpleUncheckedException.class, () -> executor.execute(functionToCall)); var actualErrorMessage = exception.getMessage();