Skip to content

Commit

Permalink
Merge pull request #128 from sashirestela/fix-minor-issues
Browse files Browse the repository at this point in the history
Fix minor issues
  • Loading branch information
sashirestela authored May 12, 2024
2 parents fcf6c5a + f59fbba commit e4b7555
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 26 deletions.
6 changes: 5 additions & 1 deletion .devfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ components:
- name: m2
path: /home/user/.m2
mountSources: true
memoryRequest: 2G
memoryLimit: 6G
cpuRequest: 2000m
cpuLimit: 4000m
- name: m2
volume:
size: 5Gi
size: 8Gi
commands: []
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ A Java library to use the OpenAI Api in the simplest possible way.
[![codecov](https://codecov.io/gh/sashirestela/simple-openai/graph/badge.svg?token=TYLE5788R3)](https://codecov.io/gh/sashirestela/simple-openai)
![Maven Central](https://img.shields.io/maven-central/v/io.github.sashirestela/simple-openai)
![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/sashirestela/simple-openai/build_java_maven.yml)
[![javadoc](https://javadoc.io/badge2/io.github.sashirestela/simple-openai/javadoc.svg)](https://javadoc.io/doc/io.github.sashirestela/simple-openai)


### Table of Contents
Expand Down Expand Up @@ -36,7 +37,7 @@ Simple-OpenAI uses the [CleverClient](https://github.com/sashirestela/cleverclie


## ✅ Supported Services
Simple-OpenAI seeks to stay up to date with the most recent changes in OpenAI. Currently, it supports all existing features until [May 6th, 2024](https://platform.openai.com/docs/changelog/may-6th-2024) and will continue to update with future changes.
Simple-OpenAI seeks to stay up to date with the most recent changes in OpenAI. Currently, it supports all existing features until [May 9th, 2024](https://platform.openai.com/docs/changelog/may-9th-2024) and will continue to update with future changes.

Full support for all of the OpenAI services:

Expand All @@ -50,13 +51,15 @@ Full support for all of the OpenAI services:
* Image (Generate, Edit, Variation)
* Models (List)
* Moderation (Check Harmful Text)
* Assistants Beta v2 (Assistants, Threads, Messages, Runs, Steps, Vector Stores, Streaming)
* Assistants Beta v2 (Assistants, Threads, Messages, Runs, Steps, Vector Stores, Streaming, Function Calling, Vision)

![OpenAI Services](media/openai_services.png)

![OpenAI Beta Services](media/openai_beta_services.png)

NOTE: All the responses are ```CompletableFuture<ResponseObject>```, which means they are asynchronous, but you can call the join() method to return the result value when complete.
NOTES:
1. The methods's responses are `CompletableFuture<ResponseObject>`, which means they are asynchronous, but you can call the join() method to return the result value when complete.
1. Exceptions for the above point are the methods whose names end with the suffix `AndPoll()`. These methods are synchronous and block until a Predicate function that you provide returns false.


## ⚙ Installation
Expand Down Expand Up @@ -293,15 +296,13 @@ var chatRequest = ChatRequest.builder()
UserMessage.of(List.of(
ContentPartText.of(
"What do you see in the image? Give in details in no more than 100 words."),
ContentPartImage.of(ImageUrl.of(
ContentPartImageUrl.of(ImageUrl.of(
"https://upload.wikimedia.org/wikipedia/commons/e/eb/Machu_Picchu%2C_Peru.jpg"))))))
.temperature(0.0)
.maxTokens(500)
.build();
var chatResponse = openAI.chatCompletions().createStream(chatRequest).join();
chatResponse.filter(chatResp -> chatResp.firstContent() != null)
.map(chatResp -> chatResp.firstContent())
.forEach(System.out::print);
chatResponse.forEach(ChatDemo::processResponseChunk);
System.out.println();
```
Example to call the Chat Completion service to allow the model to take in local images and answer questions about them:
Expand All @@ -312,14 +313,12 @@ var chatRequest = ChatRequest.builder()
UserMessage.of(List.of(
ContentPartText.of(
"What do you see in the image? Give in details in no more than 100 words."),
ContentPartImage.of(loadImageAsBase64("src/demo/resources/machupicchu.jpg"))))))
ContentPartImageUrl.of(loadImageAsBase64("src/demo/resources/machupicchu.jpg"))))))
.temperature(0.0)
.maxTokens(500)
.build();
var chatResponse = openAI.chatCompletions().createStream(chatRequest).join();
chatResponse.filter(chatResp -> chatResp.firstContent() != null)
.map(chatResp -> chatResp.firstContent())
.forEach(System.out::print);
chatResponse.forEach(ChatDemo::processResponseChunk);
System.out.println();

private static ImageUrl loadImageAsBase64(String imagePath) {
Expand Down Expand Up @@ -604,7 +603,7 @@ Write any message (or write 'exit' to finish): Tell me something about the Mistr
=====>> Thread Run: id=run_5u0t8kDQy87p5ouaTRXsCG8m, status=QUEUED
Mistral AI is a French company that specializes in selling artificial intelligence products. It was established in April 2023 by former employees of Meta Platforms and Google DeepMind. Notably, the company secured a significant amount of funding, raising €385 million in October 2023, and achieved a valuation exceeding $2 billion by December of the same year.
The prime focus of Mistral AI is on developing and producing open-source large language models. This approach underscores the foundational role of open-source software as a counter to proprietary models. As of March 2024, Mistral AI has published two models, which are available in terms of weights, while three more models—categorized as Small, Medium, and Large—are accessible only through an API【11:0†mistral-ai.txt】.
The prime focus of Mistral AI is on developing and producing open-source large language models. This approach underscores the foundational role of open-source software as a counter to proprietary models. As of March 2024, Mistral AI has published two models, which are available in terms of weights, while three more models—categorized as Small, Medium, and Large—are accessible only through an API[1].
=====>> Thread Run: id=run_5u0t8kDQy87p5ouaTRXsCG8m, status=COMPLETED
Write any message (or write 'exit' to finish): exit
Expand Down
10 changes: 5 additions & 5 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.1.0</version>
<version>3.2.0</version>
<packaging>jar</packaging>

<name>simple-openai</name>
Expand Down Expand Up @@ -51,14 +51,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<!-- Dependencies Versions -->
<slf4j.version>2.0.12</slf4j.version>
<slf4j.version>2.0.13</slf4j.version>
<cleverclient.version>1.4.2</cleverclient.version>
<slimvalidator.version>1.2.1</slimvalidator.version>
<lombok.version>1.18.32</lombok.version>
<jackson.version>2.17.0</jackson.version>
<jackson.version>2.17.1</jackson.version>
<json.schema.version>4.35.0</json.schema.version>
<junit.version>5.10.2</junit.version>
<mockito.version>5.11.0</mockito.version>
<junit.version>5.11.0-M1</junit.version>
<mockito.version>5.12.0</mockito.version>
<!-- Plugins Versions -->
<compiler.version>3.13.0</compiler.version>
<enforcer.version>3.4.1</enforcer.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static class ToolFunctionDef {
private String description;

@Required
JsonNode parameters;
private JsonNode parameters;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static class CodeInterpreterTool {
@JsonSubTypes.Type(value = Output.ImageOutput.class, name = "image")
})
@Getter
public static class Output {
public abstract static class Output {

protected Integer index;
protected OutputType type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class ThreadModifyRequest {

protected ToolResource toolResources;
private ToolResource toolResources;

@Size(max = 16)
protected Map<String, String> metadata;
private Map<String, String> metadata;

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class ThreadRequest {
@Singular
private List<ThreadMessageRequest> messages;

protected ToolResourceFull toolResources;
private ToolResourceFull toolResources;

@Size(max = 16)
protected Map<String, String> metadata;
private Map<String, String> metadata;

}
4 changes: 2 additions & 2 deletions src/main/resources/simplelogger.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
org.slf4j.simpleLogger.logFile=demo.log
org.slf4j.simpleLogger.defaultLogLevel=debug
#org.slf4j.simpleLogger.logFile=simple-openai.log
#org.slf4j.simpleLogger.defaultLogLevel=debug
org.slf4j.simpleLogger.showDateTime=true
org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSSZ
org.slf4j.simpleLogger.log.com.github.victools=off
Expand Down

0 comments on commit e4b7555

Please sign in to comment.