From 23883caac2b2c5faa8af6c4868d98284530b1163 Mon Sep 17 00:00:00 2001 From: nedko112 Date: Mon, 29 Jan 2024 17:08:01 +0200 Subject: [PATCH] Create readMe , refactor code and change class names --- README.md | 261 ++++++++++++++++++ .../api/examples/assistant/AssistantAsk.java | 3 +- .../examples/assistant/CreateAssistant.java | 3 +- .../openai/api/examples/file/UploadFile.java | 6 +- .../api/examples/message/CreateMessage.java | 1 + .../ai/openai/api/examples/run/CreateRun.java | 2 +- .../examples/thread/CreateEmptyThread.java | 15 + .../api/examples/thread/CreateThread.java | 7 +- .../http/assistant/AssistantHttpExecutor.java | 1 + .../api/http/message/MessageHttpExecutor.java | 1 + .../RetrieveListMessagesHttpExecutor.java | 1 + .../api/http/run/RunnableHttpExecutor.java | 1 + .../http/thread/ModifyThreadHttpExecutor.java | 1 + openai-api-payload/pom.xml | 228 ++++++++++++++- .../{AiModelStage.java => AIModelStage.java} | 4 +- .../openai/api/sdk/assistant/Assistants.java | 12 +- .../{AiModelStage.java => AIModelStage.java} | 4 +- .../RunnableAdvancedConfigurationStage.java | 4 +- ...elStageTest.java => AIModelStageTest.java} | 6 +- ...elStageTest.java => AIModelStageTest.java} | 6 +- 20 files changed, 528 insertions(+), 39 deletions(-) create mode 100644 openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/thread/CreateEmptyThread.java rename openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/{AiModelStage.java => AIModelStage.java} (96%) rename openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/{AiModelStage.java => AIModelStage.java} (96%) rename openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/assistant/{AiModelStageTest.java => AIModelStageTest.java} (95%) rename openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/run/{AiModelStageTest.java => AIModelStageTest.java} (95%) diff --git a/README.md b/README.md index d748ac9..263d47f 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,13 @@ Of course, due to its native SDK, objects of any kind are easily created. There * [Additional Prompting](#additional-prompting) * [Translation API SDK](#translation-api-sdk) * [Example](#example) +* [Assistants API SDK](#assistant-api-sdk) + * [Create assistant](#create-assistant) + * [Upload file](#upload-file) + * [Create thread](#create-thread) + * [Create message](#create-message) + * [Create run](#create-run) + * [Usage](#usage) * [Contributing](#contributing) * [License](#license) @@ -2610,6 +2617,260 @@ API. In other words, an example use case can be: ... or you can just ask the `Chat` SDK to translate the English to German :) +## Assistant API SDK + +Assistants API gives you the opportunity of building your own AI assistants. +The functionality offered by the assistant provides users with the opportunity to engage in a conversation within an +already established context. This context involves two participants: the user and the assistant created by the user. +One assistant can have instructions, different models and tools in order to respond to user queries. However, the +assistants API doesn't rely only on itself. +In order to achieve the functionality of an AI assistant, there are various APIs, such as Threads, Messages, Runs and +Files, which are working together, to provide the available functionality that one assistant can have. + +### Create assistant + +At first, assistant needs to be created. It, can have its custom instructions, model, tools, metadata and file. The +following code is showing how this can be done: + +```java +public class CreateAssistant { + + public static void main(String[] args) { + var file = new File(CreateAssistant.class.getClassLoader() + .getResource("fake-file.txt") + .getPath()); + + var assistant = Assistants.defaults() + .and() + .turboPowered() + .from( + new CodeInterpreter(), + new Retrieval() + ) + .called("Codexio") + .instruct("You are the best java developer," + " you are going to " + + "participate in new " + "interesting projects.") + + .meta() + .awareOf( + "key1", + "value1", + "key2", + "value2" + ) + .file() + .feed(file) + .andRespond(); + + System.out.println(assistant); + } +} +``` + +### Upload file + +In order to upload a file, we are using the Files API to upload it and then using the returned file id we can easily +attach it to the assistant. +Creating a file is looking like this: + +```java +public class UploadFile { + public static void main(String[] args) { + var file = new File(UploadFile.class.getClassLoader() + .getResource("fake-file.txt") + .getPath()); + var fileId = Files.defaults() + .and() + .targeting(new AssistantPurpose()) + .feedRaw(file); + + System.out.println(fileResponse); + } +} +``` + +### Create thread + +Since the assistant is created and user wants to start a conversation the Threads API comes in use. Threads represents a +conversation session between user and his assistant. A thread can be created using either the empty() method, +which generates a thread without additional information, or it can be configured to include files and metadata. +Messages can be added to the thread, during creation, which will be processed by the Messages API. +The following code is showing the extended way of thread creation: + +```java +public class CreateThread { + + public static void main(String[] args) { + var file = new File(CreateThread.class.getClassLoader() + .getResource("fake-file.txt") + .getPath()); + + var thread = Threads.defaults() + .and() + .creating() + .deepConfigure() + .meta() + .awareOf( + "key1", + "value1", + "key2", + "value2" + ) + .file() + .attach(file) + .message() + .startWith("You're java developer.") + .feed(file); + + System.out.println(thread); + } +} +``` + +And here is the simplified one: + +```java +public class CreateEmptyThread { + + public static void main(String[] args) { + var thread = Threads.defaults() + .and() + .creating() + .empty(); + + System.out.println(thread); + } +} +``` + +### Create message + +After the thread is created, messages can be added. A message can be added during the thread creation process as +demonstrated in the previous example. +Alternatively, Messages API can be used to add messages to existing thread. +If the second approach is the preferred one , the message creation is looking like this : + +```java +public class CreateMessage { + + public static void main(String[] args) { + var messageResponse = Messages.defaults(Threads.defaults() + .and() + .creating() + .empty()) + .and() + .chat() + .withContent("How are you?") + .andRespond(); + + System.out.println(messageResponse); + } +} +``` + +The thread can be supplied using the thread response object or only the thread id. One message can have not only +content, +but its own metadata and file. + +### Create run + +Since we already have assistant, files, threads, messages there is one final step to conclude the conversation +between the user and the assistant - using the Runs API. It executes the assistant on the thread to trigger +responses. Similar to messages, runs rely on the id of already created thread, and it also requires the id of the +created assistant. Run use the model and tools configured by the assistant, but they can be overridden, during the run +creation process. +Run creation is looking like this : + +```java +public class CreateRun { + + public static void main(String[] args) { + var run = Runnables.defaults(Threads.defaults() + .and() + .creating() + .empty()) + .and() + .deepConfigure(Assistants.defaults() + .and() + .poweredByGPT40() + .from(new CodeInterpreter()) + .called("Cody") + .instruct("Be intuitive") + .andRespond()) + .andRespond(); + + System.out.println(run); + } +} +``` + +### Usage + +In order to achieve give the user better experience, all the functionality provided by the aforementioned APIs the +assistant usage is simplified trough single method chain, where everything that can be added/configured, when each +component is created individually, can also be done directly from one place. +Chained it looks like this : + +```java +public class AssistantAsk { + + public static void main(String[] args) { + var file = new File(AssistantAsk.class.getClassLoader() + .getResource("fake-file.txt") + .getPath()); + + var answer = Threads.defaults() + .and() + .creating() + .deepConfigure() + .message() + .startWith("You are developer at Codexio.") + .attach(file) + .chat() + .withContent("Your language of choice is Java.") + .meta() + .awareOf( + "key", + "value" + ) + .assistant() + .assist(Assistants.defaults() + .and() + .poweredByGPT40() + .from(new CodeInterpreter()) + .called("Cody") + .instruct("Please focus on " + "explaining" + " the " + "topics as " + + "senior " + "developer.") + .andRespond()) + .instruction() + .instruct("It would be better to show me some " + "DevOps skills.") + .finish() + .waitForCompletion() + .result() + .answers(); + + System.out.println(answer); + } +} +``` + +Which outputs: + +```text +MessageResult[message=The file contains the single word "test" and no other data. With respect to showcasing some DevOps +skills, we could talk about various aspects. Given we have Python in our environment, one critical aspect could be +Infrastructure as Code(IaC). And in Python, we can use libraries like Ansible, Terraform, and more, for IaC. Also, +Python is extensively used for automation scripts in build, testing, and deployment. +If we had a more complex file, we could have used Python to parse and manipulate data, demonstrating a scenario of data +processing, a common need in DevOps. Another example could be analyzing logs to spot errors or patterns. +Given this context, please let me know what specific aspects you're interested in so I can provide a more tailored +explanation. Would you like more information on IaC, Continuous Integration/Continuous Deployment (CI/CD) processes, +monitoring, logging, or something else?, fileId=null] +``` + +The uploaded file `fake-file.txt` is only used for testing scenarios, and it contains only the word `test`. The response +given from the for now is returned by MessageResult object, which contains information about the content of the message +and id of a generated file, if the assistant has created one. ## Contributing This project is in its very early stage and contributors are very welcomed. If you feel that something has to be diff --git a/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/assistant/AssistantAsk.java b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/assistant/AssistantAsk.java index fc671e7..59710d5 100644 --- a/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/assistant/AssistantAsk.java +++ b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/assistant/AssistantAsk.java @@ -1,6 +1,5 @@ package bg.codexio.ai.openai.api.examples.assistant; -import bg.codexio.ai.openai.api.examples.file.UploadFile; import bg.codexio.ai.openai.api.payload.assistant.tool.CodeInterpreter; import bg.codexio.ai.openai.api.sdk.assistant.Assistants; import bg.codexio.ai.openai.api.sdk.thread.Threads; @@ -10,7 +9,7 @@ public class AssistantAsk { public static void main(String[] args) { - var file = new File(UploadFile.class.getClassLoader() + var file = new File(AssistantAsk.class.getClassLoader() .getResource("fake-file.txt") .getPath()); diff --git a/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/assistant/CreateAssistant.java b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/assistant/CreateAssistant.java index fe723c9..9c86f7e 100644 --- a/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/assistant/CreateAssistant.java +++ b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/assistant/CreateAssistant.java @@ -1,6 +1,5 @@ package bg.codexio.ai.openai.api.examples.assistant; -import bg.codexio.ai.openai.api.examples.file.UploadFile; import bg.codexio.ai.openai.api.payload.assistant.tool.CodeInterpreter; import bg.codexio.ai.openai.api.payload.assistant.tool.Retrieval; import bg.codexio.ai.openai.api.sdk.assistant.Assistants; @@ -10,7 +9,7 @@ public class CreateAssistant { public static void main(String[] args) { - var file = new File(UploadFile.class.getClassLoader() + var file = new File(CreateAssistant.class.getClassLoader() .getResource("fake-file.txt") .getPath()); diff --git a/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/file/UploadFile.java b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/file/UploadFile.java index fb33350..aa992e6 100644 --- a/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/file/UploadFile.java +++ b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/file/UploadFile.java @@ -11,11 +11,11 @@ public static void main(String[] args) { var file = new File(UploadFile.class.getClassLoader() .getResource("fake-file.txt") .getPath()); - var fileResponse = Files.defaults() + var fileId = Files.defaults() .and() .targeting(new AssistantPurpose()) - .feedRaw(file); + .feed(file); - System.out.println(fileResponse); + System.out.println(fileId); } } diff --git a/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/message/CreateMessage.java b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/message/CreateMessage.java index 4150a8b..fb06507 100644 --- a/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/message/CreateMessage.java +++ b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/message/CreateMessage.java @@ -4,6 +4,7 @@ import bg.codexio.ai.openai.api.sdk.thread.Threads; public class CreateMessage { + public static void main(String[] args) { var messageResponse = Messages.defaults(Threads.defaults() .and() diff --git a/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/run/CreateRun.java b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/run/CreateRun.java index dbb72ec..1a926c6 100644 --- a/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/run/CreateRun.java +++ b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/run/CreateRun.java @@ -7,7 +7,7 @@ public class CreateRun { - public static void main(String[] args) throws InterruptedException { + public static void main(String[] args) { var run = Runnables.defaults(Threads.defaults() .and() .creating() diff --git a/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/thread/CreateEmptyThread.java b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/thread/CreateEmptyThread.java new file mode 100644 index 0000000..1df779c --- /dev/null +++ b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/thread/CreateEmptyThread.java @@ -0,0 +1,15 @@ +package bg.codexio.ai.openai.api.examples.thread; + +import bg.codexio.ai.openai.api.sdk.thread.Threads; + +public class CreateEmptyThread { + + public static void main(String[] args) { + var thread = Threads.defaults() + .and() + .creating() + .empty(); + + System.out.println(thread); + } +} diff --git a/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/thread/CreateThread.java b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/thread/CreateThread.java index b40e012..4e01b2e 100644 --- a/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/thread/CreateThread.java +++ b/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/thread/CreateThread.java @@ -1,6 +1,5 @@ package bg.codexio.ai.openai.api.examples.thread; -import bg.codexio.ai.openai.api.examples.file.UploadFile; import bg.codexio.ai.openai.api.sdk.thread.Threads; import java.io.File; @@ -8,11 +7,11 @@ public class CreateThread { public static void main(String[] args) { - var file = new File(UploadFile.class.getClassLoader() + var file = new File(CreateThread.class.getClassLoader() .getResource("fake-file.txt") .getPath()); - var emptyThread = Threads.defaults() + var thread = Threads.defaults() .and() .creating() .deepConfigure() @@ -29,6 +28,6 @@ public static void main(String[] args) { .startWith("You're java developer.") .feed(file); - System.out.println(emptyThread); + System.out.println(thread); } } \ No newline at end of file diff --git a/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/assistant/AssistantHttpExecutor.java b/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/assistant/AssistantHttpExecutor.java index f698c31..8715dfd 100644 --- a/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/assistant/AssistantHttpExecutor.java +++ b/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/assistant/AssistantHttpExecutor.java @@ -12,6 +12,7 @@ public class AssistantHttpExecutor extends DefaultOpenAIHttpExecutor { + private static final Class RESPONSE_TYPE = AssistantResponse.class; private static final String RESOURCE_URI = "/assistants"; diff --git a/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/message/MessageHttpExecutor.java b/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/message/MessageHttpExecutor.java index 0fc5628..e40abcc 100644 --- a/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/message/MessageHttpExecutor.java +++ b/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/message/MessageHttpExecutor.java @@ -12,6 +12,7 @@ public class MessageHttpExecutor extends DefaultOpenAIHttpExecutor { + private static final Class RESPONSE_TYPE = MessageResponse.class; private static final String RESOURCE_URI = "/threads/%s/messages"; diff --git a/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/message/RetrieveListMessagesHttpExecutor.java b/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/message/RetrieveListMessagesHttpExecutor.java index 50ba9c0..8d00453 100644 --- a/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/message/RetrieveListMessagesHttpExecutor.java +++ b/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/message/RetrieveListMessagesHttpExecutor.java @@ -11,6 +11,7 @@ public class RetrieveListMessagesHttpExecutor extends DefaultOpenAIHttpExecutor { + private static final Class RESPONSE_TYPE = ListMessagesResponse.class; private static final String RESOURCE_URI = "/threads/%s/messages"; diff --git a/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/run/RunnableHttpExecutor.java b/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/run/RunnableHttpExecutor.java index 99107c5..a946215 100644 --- a/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/run/RunnableHttpExecutor.java +++ b/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/run/RunnableHttpExecutor.java @@ -12,6 +12,7 @@ public class RunnableHttpExecutor extends DefaultOpenAIHttpExecutor { + private static final Class RESPONSE_TYPE = RunnableResponse.class; private static final String RESOURCE_URI = "/threads/%s/runs"; diff --git a/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/thread/ModifyThreadHttpExecutor.java b/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/thread/ModifyThreadHttpExecutor.java index ec60076..e8ef02c 100644 --- a/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/thread/ModifyThreadHttpExecutor.java +++ b/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/thread/ModifyThreadHttpExecutor.java @@ -13,6 +13,7 @@ public class ModifyThreadHttpExecutor extends DefaultOpenAIHttpExecutor { + private static final Class RESPONSE_TYPE = ThreadResponse.class; private static final String RESOURCE_URI = "/threads/%s"; diff --git a/openai-api-payload/pom.xml b/openai-api-payload/pom.xml index eca91fb..c08db46 100644 --- a/openai-api-payload/pom.xml +++ b/openai-api-payload/pom.xml @@ -4,17 +4,227 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - bg.codexio.ai - openai-api - 0.8.2.BETA-SNAPSHOT - + bg.codexio.ai + openai-api + 0.8.2.BETA-SNAPSHOT + pom + + Codexio Ltd. OpenAI API + OpenAI API SDK with fluent interface for different AI models. + https://github.com/CodexioLtd/openai-api-sdk + + + + The Apache License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + + + Ivan Yonkov + ivan.yonkov@codexio.bg + Codexio Ltd. + https://codexio.bg + + + + Yoana Borissova + yoana.borissova@codexio.bg + Codexio Ltd. + https://codexio.bg + + + + + + scm:git:git://github.com/CodexioLtd/openai-api-sdk.git + scm:git:ssh://github.com:CodexioLtd/openai-api-sdk.git + https://github.com/CodexioLtd/openai-api-sdk/tree/master + + + + openai-api-models + openai-api-payload + openai-api-sdk + openai-api-http + openai-api-coverage + openai-api-examples + - openai-api-payload - jar + 21 + ${java.version} + ${java.version} + + 5.10.1 + 5.8.0 + + 1.6.13 + 3.1.0 + 3.6.3 + 3.3.0 + 0.8.11 + false - com.fasterxml.jackson.corejackson-annotations2.16.0compile + + + + + + + org.junit + junit-bom + ${junit.version} + pom + import + + + + org.mockito + mockito-core + ${mockito.version} + test + + + + + + + + org.junit.jupiter + junit-jupiter + test + + + + org.mockito + mockito-core + ${mockito.version} + + + + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.3 + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + + + + + + + + + mvn-deploy + + false + + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.plugin.version} + + + jacoco-initialize + + prepare-agent + + + + + jacoco-report + test + + report + + + + + + + org.apache.maven.plugins + maven-source-plugin + ${source.plugin.version} + + + attach-sources + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${javadoc.plugin.version} + + + attach-javadocs + + jar + + + false + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${gpg.plugin.version} + + + sign-artifacts + verify + + sign + + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus.plugin.version} + true + + ${skipDeploy} + ossrh + https://s01.oss.sonatype.org/ + true + + + + + + + + - + \ No newline at end of file diff --git a/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/AiModelStage.java b/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/AIModelStage.java similarity index 96% rename from openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/AiModelStage.java rename to openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/AIModelStage.java index 76277de..e537b78 100644 --- a/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/AiModelStage.java +++ b/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/AIModelStage.java @@ -7,9 +7,9 @@ import bg.codexio.ai.openai.api.models.v40.GPT40Model; import bg.codexio.ai.openai.api.payload.assistant.request.AssistantRequest; -public class AiModelStage +public class AIModelStage extends AssistantConfigurationStage { - AiModelStage( + AIModelStage( AssistantHttpExecutor httpExecutor, AssistantRequest.Builder requestBuilder ) { diff --git a/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/Assistants.java b/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/Assistants.java index e2ab10f..aa6ad6a 100644 --- a/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/Assistants.java +++ b/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/Assistants.java @@ -13,17 +13,17 @@ public class Assistants { private Assistants() { } - public static AiModelStage throughHttp(AssistantHttpExecutor httpExecutor) { - return new AiModelStage( + public static AIModelStage throughHttp(AssistantHttpExecutor httpExecutor) { + return new AIModelStage( httpExecutor, AssistantRequest.builder() ); } - public static HttpBuilder authenticate(HttpExecutorContext context) { + public static HttpBuilder authenticate(HttpExecutorContext context) { return new HttpBuilder<>( context, - (httpExecutorContext, objectMapper) -> new AiModelStage( + (httpExecutorContext, objectMapper) -> new AIModelStage( new AssistantHttpExecutor( httpExecutorContext, objectMapper @@ -34,11 +34,11 @@ public static HttpBuilder authenticate(HttpExecutorContext context ); } - public static HttpBuilder authenticate(SdkAuth auth) { + public static HttpBuilder authenticate(SdkAuth auth) { return authenticate(new HttpExecutorContext(auth.credentials())); } - public static HttpBuilder defaults() { + public static HttpBuilder defaults() { return autoAuthenticate(Assistants::authenticate); } } \ No newline at end of file diff --git a/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/AiModelStage.java b/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/AIModelStage.java similarity index 96% rename from openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/AiModelStage.java rename to openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/AIModelStage.java index 7483af8..220e9bd 100644 --- a/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/AiModelStage.java +++ b/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/AIModelStage.java @@ -7,10 +7,10 @@ import bg.codexio.ai.openai.api.models.v40.GPT40Model; import bg.codexio.ai.openai.api.payload.run.request.RunnableRequest; -public class AiModelStage +public class AIModelStage extends RunnableConfigurationStage { - AiModelStage( + AIModelStage( RunnableHttpExecutor httpExecutor, RunnableRequest.Builder requestBuilder, String threadId diff --git a/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/RunnableAdvancedConfigurationStage.java b/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/RunnableAdvancedConfigurationStage.java index 3fff4f5..5671332 100644 --- a/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/RunnableAdvancedConfigurationStage.java +++ b/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/RunnableAdvancedConfigurationStage.java @@ -27,8 +27,8 @@ public RunnableMetaStage meta() { ); } - public AiModelStage aiModel() { - return new AiModelStage( + public AIModelStage aiModel() { + return new AIModelStage( this.httpExecutor, this.requestBuilder, this.threadId diff --git a/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/assistant/AiModelStageTest.java b/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/assistant/AIModelStageTest.java similarity index 95% rename from openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/assistant/AiModelStageTest.java rename to openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/assistant/AIModelStageTest.java index c330c5a..9598d22 100644 --- a/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/assistant/AiModelStageTest.java +++ b/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/assistant/AIModelStageTest.java @@ -11,13 +11,13 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; -public class AiModelStageTest { +public class AIModelStageTest { - private AiModelStage aiModelStage; + private AIModelStage aiModelStage; @BeforeEach void setUp() { - this.aiModelStage = new AiModelStage( + this.aiModelStage = new AIModelStage( null, AssistantRequest.builder() ); diff --git a/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/run/AiModelStageTest.java b/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/run/AIModelStageTest.java similarity index 95% rename from openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/run/AiModelStageTest.java rename to openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/run/AIModelStageTest.java index 8ee82d2..1ed12af 100644 --- a/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/run/AiModelStageTest.java +++ b/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/run/AIModelStageTest.java @@ -13,13 +13,13 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; -public class AiModelStageTest { +public class AIModelStageTest { - private AiModelStage aiModelStage; + private AIModelStage aiModelStage; @BeforeEach void setUp() { - this.aiModelStage = new AiModelStage( + this.aiModelStage = new AIModelStage( null, RunnableRequest.builder() .withAssistantId(ASSISTANT_ID),