Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.14.0 #256

Merged
merged 8 commits into from
Jan 3, 2025
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
51 changes: 20 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ A Java library to use the OpenAI Api in the simplest possible way.
- [Chat Completion with Structured Outputs](#chat-completion-with-structured-outputs)
- [Chat Completion Conversation Example](#chat-completion-conversation-example)
- [Assistant v2 Conversation Example](#assistant-v2-conversation-example)
- [Realtime Conversation Example](#realtime-conversation-example) **UPDATED**
- [Realtime Conversation Example](#realtime-conversation-example)
- [Exception Handling](#-exception-handling)
- [Support for Additional OpenAI Providers](#-support-for-additional-openai-providers)
- [Mistral API](#mistral-api) **NEW**
- [Azure OpenAI](#azure-openai)
- [Anyscale](#anyscale)
- [Run Examples](#-run-examples)
Expand Down Expand Up @@ -57,8 +58,8 @@ Full support for most of the OpenAI services:
* Image (Generate, Edit, Variation)
* Models (List)
* Moderation (Check Harmful Text)
* Realtime Beta (Speech-to-Speech Conversation, Multimodality, Function Calling) **UPDATED**
* Session Token (Create Ephemeral Tokens) **NEW**
* Realtime Beta (Speech-to-Speech Conversation, Multimodality, Function Calling)
* Session Token (Create Ephemeral Tokens)
* Upload (Upload Large Files in Parts)
* Assistants Beta v2 (Assistants, Threads, Messages, Runs, Steps, Vector Stores, Streaming, Function Calling, Vision, Structured Outputs)

Expand Down Expand Up @@ -966,6 +967,20 @@ This exception handling mechanism allows you to handle API errors and provide fe
## ✴ Support for Additional OpenAI Providers
Simple-OpenAI can be used with additional providers that are compatible with the OpenAI API. At this moment, there is support for the following additional providers:

### Mistral API
[Mistral API](https://docs.mistral.ai/getting-started/quickstart/) is supported by Simple-OpenAI. We can use the class `SimpleOpenAIMistral` to start using this provider.
```java
var openai = SimpleOpenAIMistral.builder()
.apiKey(System.getenv("MISTRAL_API_KEY"))
//.baseUrl(customUrl) Optionally you could pass a custom baseUrl
//.httpClient(customHttpClient) Optionally you could pass a custom HttpClient
.build();
```
Currently we are supporting the following services:
- `chatCompletionService` (text generation, streaming, function calling, vision)
- `embeddingService` (float format)
- `modelService` (list, detail, delete)

### Azure OpenAI
[Azure OpenIA](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference) is supported by Simple-OpenAI. We can use the class `SimpleOpenAIAzure` to start using this provider.
```java
Expand Down Expand Up @@ -1006,7 +1021,7 @@ Examples for each OpenAI service have been created in the folder [demo](https://
```
mvn clean install
```
* Create an environment variable for your OpenAI Api Key:
* Create an environment variable for your OpenAI Api Key (the variable varies according to the OpenAI provider that we want to run):
```
export OPENAI_API_KEY=<here goes your api key>
```
Expand All @@ -1020,33 +1035,7 @@ Examples for each OpenAI service have been created in the folder [demo](https://
```
Where:

* ```<demo>``` Is mandatory and must be one of the values:
* Audio
* Batch
* Chat
* Completion
* Embedding
* Exception
* File
* Finetuning
* Image
* Model
* Moderation
* Realtime
* SessionToken
* Upload
* Conversation
* AssistantV2
* ThreadV2
* ThreadMessageV2
* ThreadRunV2
* ThreadRunStepV2
* VectorStoreV2
* VectorStoreFileV2
* VectorStoreFileBatchV2
* ConversationV2
* ChatAnyscale
* ChatAzure
* ```<demo>``` Is mandatory and must be one of the Java files in the folder demo without the suffix `Demo`, for example: _Audio, Chat, ChatMistral, Realtime, AssistantV2, Conversation, ConversationV2, etc._

* ```[debug]``` Is optional and creates the ```demo.log``` file where you can see log details for each execution.
* For example, to run the chat demo with a log file: ```./rundemo.sh Chat debug```
Expand Down
95 changes: 62 additions & 33 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.sashirestela</groupId>
<artifactId>simple-openai</artifactId>
<version>3.13.0</version>
<version>3.14.0</version>
<packaging>jar</packaging>

<name>simple-openai</name>
Expand Down Expand Up @@ -47,19 +47,24 @@
</distributionManagement>

<properties>
<!-- General -->
<!-- Build Properties -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.version>3.6.3</maven.version>
<maven.compiler.release>11</maven.compiler.release>
<maven.compiler.proc>full</maven.compiler.proc>
<!-- Dependencies Versions -->
<slf4j.version>2.0.16</slf4j.version>
<cleverclient.version>1.6.2</cleverclient.version>
<slimvalidator.version>1.2.2</slimvalidator.version>

<!-- Library Versions -->
<cleverclient.version>1.6.3</cleverclient.version>
<slimvalidator.version>1.2.3</slimvalidator.version>
<lombok.version>1.18.36</lombok.version>
<jackson.version>2.18.2</jackson.version>
<json.schema.version>4.37.0</json.schema.version>
<junit.version>5.11.4</junit.version>
<mockito.version>5.14.2</mockito.version>
<slf4j.version>2.0.16</slf4j.version>

<!-- Test Library Versions-->
<junit.version>[5.11.0,6.0.0)</junit.version>
<mockito.version>[5.14.0,6.0.0)</mockito.version>

<!-- Plugins Versions -->
<compiler.version>3.13.0</compiler.version>
<enforcer.version>3.5.0</enforcer.version>
Expand All @@ -73,6 +78,7 @@
<gpg.version>3.2.7</gpg.version>
<sonatype.version>1.7.0</sonatype.version>
<spotless.version>2.43.0</spotless.version>
<dependency.version>3.8.1</dependency.version>
</properties>

<profiles>
Expand All @@ -81,6 +87,12 @@
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -192,6 +204,7 @@

<dependencyManagement>
<dependencies>
<!-- Core Dependencies -->
<dependency>
<groupId>io.github.sashirestela</groupId>
<artifactId>cleverclient</artifactId>
Expand All @@ -202,17 +215,6 @@
<artifactId>slimvalidator</artifactId>
<version>${slimvalidator.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand All @@ -224,6 +226,8 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>

<!-- Json Schema Dependencies -->
<dependency>
<groupId>com.github.victools</groupId>
<artifactId>jsonschema-generator</artifactId>
Expand All @@ -240,6 +244,21 @@
<artifactId>jsonschema-module-jackson</artifactId>
<version>${json.schema.version}</version>
</dependency>

<!-- Logging Dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand All @@ -257,17 +276,12 @@
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Core Dependencies -->
<dependency>
<groupId>io.github.sashirestela</groupId>
<artifactId>cleverclient</artifactId>
Expand All @@ -284,6 +298,8 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<!-- Json Schema Dependencies -->
<dependency>
<groupId>com.github.victools</groupId>
<artifactId>jsonschema-generator</artifactId>
Expand All @@ -292,6 +308,14 @@
<groupId>com.github.victools</groupId>
<artifactId>jsonschema-module-jackson</artifactId>
</dependency>

<!-- Logging Dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand All @@ -304,14 +328,6 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
</dependencies>

<build>
Expand All @@ -321,6 +337,19 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${dependency.version}</version>
<executions>
<execution>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.github.sashirestela.openai.SimpleOpenAI;
import io.github.sashirestela.openai.SimpleOpenAIAnyscale;
import io.github.sashirestela.openai.SimpleOpenAIAzure;
import io.github.sashirestela.openai.service.ChatCompletionServices;
import io.github.sashirestela.openai.SimpleOpenAIMistral;
import lombok.NonNull;

import java.util.ArrayList;
Expand All @@ -14,8 +14,7 @@ public abstract class AbstractDemo {
protected SimpleOpenAI openAI;
protected SimpleOpenAIAzure openAIAzure;
protected SimpleOpenAIAnyscale openAIAnyscale;

protected ChatCompletionServices chatProvider;
protected SimpleOpenAIMistral openAIMistral;

private static List<TitleAction> titleActions = new ArrayList<>();
private static final int TIMES = 80;
Expand All @@ -31,21 +30,23 @@ protected AbstractDemo(String provider) {
.apiKey(System.getenv("OPENAI_API_KEY"))
.organizationId(System.getenv("OPENAI_ORGANIZATION_ID"))
.build();
chatProvider = openAI;
break;
case "azure":
openAIAzure = SimpleOpenAIAzure.builder()
.apiKey(System.getenv("AZURE_OPENAI_API_KEY"))
.apiVersion(System.getenv("AZURE_OPENAI_API_VERSION"))
.baseUrl(System.getenv("AZURE_OPENAI_BASE_URL"))
.build();
chatProvider = openAIAzure;
break;
case "anyscale":
openAIAnyscale = SimpleOpenAIAnyscale.builder()
.apiKey(System.getenv("ANYSCALE_API_KEY"))
.build();
chatProvider = openAIAnyscale;
break;
case "mistral":
openAIMistral = SimpleOpenAIMistral.builder()
.apiKey(System.getenv("MISTRAL_API_KEY"))
.build();
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

public class ChatAnyscaleDemo extends ChatDemo {

public ChatAnyscaleDemo(String provider, String model) {
super(provider, model, null);
public ChatAnyscaleDemo(String model) {
super("anyscale", model, null);
this.chatProvider = this.openAIAnyscale;
}

public static void main(String[] args) {
var demo = new ChatAnyscaleDemo("anyscale", "mistralai/Mixtral-8x7B-Instruct-v0.1");
var demo = new ChatAnyscaleDemo("mistralai/Mixtral-8x7B-Instruct-v0.1");

demo.addTitleAction("Call Chat (Streaming Approach)", demo::demoCallChatStreaming);
demo.addTitleAction("Call Chat (Blocking Approach)", demo::demoCallChatBlocking);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

public class ChatAzureDemo extends ChatDemo {

public ChatAzureDemo(String provider, String model) {
super(provider, model, null);
public ChatAzureDemo() {
super("azure", "N/A", null);
this.chatProvider = this.openAIAzure;
}

@Override
Expand Down Expand Up @@ -51,7 +52,7 @@ public void demoCallChatWithVisionLocalImage() {
}

public static void main(String[] args) {
var demo = new ChatAzureDemo("azure", "N/A");
var demo = new ChatAzureDemo();

demo.addTitleAction("Call Chat (Streaming Approach)", demo::demoCallChatStreaming);
demo.addTitleAction("Call Chat (Blocking Approach)", demo::demoCallChatBlocking);
Expand Down
Loading
Loading