Skip to content

Commit

Permalink
Merge pull request #20 from sashirestela/18-use-with-lombok-annotation
Browse files Browse the repository at this point in the history
Immutable request objects using Lombok @with
  • Loading branch information
sashirestela authored Nov 22, 2023
2 parents db4387c + 48c822c commit 9e34dda
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 114 deletions.
4 changes: 2 additions & 2 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>1.0.0</version>
<version>1.1.0</version>
<packaging>jar</packaging>

<name>simple-openai</name>
Expand Down Expand Up @@ -52,7 +52,7 @@
<maven.compiler.release>11</maven.compiler.release>
<!-- Dependencies Versions -->
<slf4j.version>[2.0.9,3.0.0)</slf4j.version>
<cleverclient.version>0.8.1</cleverclient.version>
<cleverclient.version>0.9.0</cleverclient.version>
<lombok.version>[1.18.30,2.0.0)</lombok.version>
<jackson.version>[2.15.2,3.0.0)</jackson.version>
<json.schema.version>[4.31.1,5.0.0)</json.schema.version>
Expand Down
170 changes: 68 additions & 102 deletions src/main/java/io/github/sashirestela/openai/OpenAI.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
package io.github.sashirestela.openai.domain.audio;

import java.nio.file.Path;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Builder;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import lombok.NonNull;
import lombok.With;

@Getter
@SuperBuilder
public class AudioTranscribeRequest extends AudioTranslateRequest {
@Builder
public class AudioTranscribeRequest {

@NonNull
protected Path file;

@NonNull
protected String model;

@JsonInclude(Include.NON_NULL)
protected String prompt;

@JsonInclude(Include.NON_NULL)
protected Double temperature;

@JsonInclude(Include.NON_NULL)
private String language;

@With
@JsonInclude(Include.NON_NULL)
@JsonProperty("response_format")
protected AudioRespFmt responseFormat;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.experimental.SuperBuilder;
import lombok.With;

@Getter
@SuperBuilder
@Builder
public class AudioTranslateRequest {

@NonNull
Expand All @@ -24,10 +25,11 @@ public class AudioTranslateRequest {
protected String prompt;

@JsonInclude(Include.NON_NULL)
@JsonProperty("response_format")
protected AudioRespFmt responseFormat;
protected Double temperature;

@With
@JsonInclude(Include.NON_NULL)
protected Double temperature;
@JsonProperty("response_format")
protected AudioRespFmt responseFormat;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.With;

@Getter
public class ChatRequest {
Expand Down Expand Up @@ -49,6 +50,7 @@ public class ChatRequest {
@JsonInclude(Include.NON_NULL)
private Integer n;

@With
@JsonInclude(Include.NON_NULL)
private Boolean stream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.With;

@Getter
public class CompletionRequest {
Expand Down Expand Up @@ -38,6 +39,7 @@ public class CompletionRequest {
@JsonInclude(Include.NON_NULL)
private Integer n;

@With
@JsonInclude(Include.NON_NULL)
private Boolean stream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.With;

@Getter
public class EmbeddingRequest {
Expand All @@ -22,6 +23,7 @@ public class EmbeddingRequest {
@NonNull
private Object input;

@With
@JsonInclude(Include.NON_NULL)
@JsonProperty("encoding_format")
private EncodingFormat encodingFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void testAudiosTranscribe() throws IOException {
@Test
void testAudiosTranslate() throws IOException {
DomainTestingHelper.get().mockForObject(httpClient, "src/test/resources/audios_translate.json");
var audioRequest = AudioTranscribeRequest.builder()
var audioRequest = AudioTranslateRequest.builder()
.file(Paths.get(fileName))
.model("whisper-1")
.prompt("It is a greeting")
Expand Down Expand Up @@ -94,7 +94,7 @@ void testAudiosTranscribePlain() throws IOException {
@Test
void testAudiosTranslatePlain() throws IOException {
DomainTestingHelper.get().mockForObject(httpClient, "src/test/resources/audios_translate_plain.txt");
var audioRequest = AudioTranscribeRequest.builder()
var audioRequest = AudioTranslateRequest.builder()
.file(Paths.get(fileName))
.model("whisper-1")
.prompt("It is a greeting")
Expand Down

0 comments on commit 9e34dda

Please sign in to comment.