-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdb7a69
commit bb974c2
Showing
17 changed files
with
406 additions
and
58 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/example/java/io/github/sashirestela/cleverclient/example/AbstractExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.github.sashirestela.cleverclient.example; | ||
|
||
import io.github.sashirestela.cleverclient.client.HttpClientAdapter; | ||
import io.github.sashirestela.cleverclient.client.JavaHttpClientAdapter; | ||
import io.github.sashirestela.cleverclient.client.OkHttpClientAdapter; | ||
import okhttp3.OkHttpClient; | ||
|
||
import java.net.http.HttpClient; | ||
|
||
public abstract class AbstractExample { | ||
|
||
protected HttpClientAdapter clientAdapter; | ||
|
||
protected AbstractExample(String clientAlias) { | ||
switch (clientAlias.toLowerCase()) { | ||
case "javahttp": | ||
clientAdapter = new JavaHttpClientAdapter(); | ||
break; | ||
case "okhttp": | ||
clientAdapter = new OkHttpClientAdapter(); | ||
break; | ||
default: | ||
clientAdapter = null; | ||
break; | ||
} | ||
} | ||
|
||
protected AbstractExample(HttpClient httpClient) { | ||
clientAdapter = new JavaHttpClientAdapter(httpClient); | ||
} | ||
|
||
protected AbstractExample(OkHttpClient okHttpClient) { | ||
clientAdapter = new OkHttpClientAdapter(okHttpClient); | ||
} | ||
|
||
protected void showTitle(String title) { | ||
final var times = 50; | ||
System.out.println("=".repeat(times)); | ||
System.out.println(title); | ||
System.out.println("-".repeat(times)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/example/java/io/github/sashirestela/cleverclient/example/BasicExampleOkHttp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.sashirestela.cleverclient.example; | ||
|
||
public class BasicExampleOkHttp extends BasicExample { | ||
|
||
public BasicExampleOkHttp() { | ||
super("okhttp"); | ||
} | ||
|
||
public static void main(String[] args) { | ||
var example = new BasicExampleOkHttp(); | ||
example.run(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/example/java/io/github/sashirestela/cleverclient/example/FileDownloadExampleOkHttp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.github.sashirestela.cleverclient.example; | ||
|
||
import java.io.IOException; | ||
|
||
public class FileDownloadExampleOkHttp extends FileDownloadExample { | ||
|
||
public FileDownloadExampleOkHttp() { | ||
super("okhttp"); | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
var example = new FileDownloadExampleOkHttp(); | ||
example.run(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/example/java/io/github/sashirestela/cleverclient/example/HeaderExampleOkHttp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.sashirestela.cleverclient.example; | ||
|
||
public class HeaderExampleOkHttp extends HeaderExample { | ||
|
||
public HeaderExampleOkHttp() { | ||
super("okhttp"); | ||
} | ||
|
||
public static void main(String[] args) { | ||
var example = new HeaderExampleOkHttp(); | ||
example.run(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/example/java/io/github/sashirestela/cleverclient/example/MultiServiceExampleOkHttp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.sashirestela.cleverclient.example; | ||
|
||
public class MultiServiceExampleOkHttp extends MultiServiceExample { | ||
|
||
public MultiServiceExampleOkHttp() { | ||
super("okhttp"); | ||
} | ||
|
||
public static void main(String[] args) { | ||
var example = new MultiServiceExampleOkHttp(); | ||
example.run(); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/example/java/io/github/sashirestela/cleverclient/example/MultipartExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.github.sashirestela.cleverclient.example; | ||
|
||
import io.github.sashirestela.cleverclient.CleverClient; | ||
import io.github.sashirestela.cleverclient.example.openai.AudioService; | ||
import io.github.sashirestela.cleverclient.example.openai.TranscriptionRequest; | ||
import io.github.sashirestela.cleverclient.example.openai.TranscriptionRequest.AudioResponseFormat; | ||
import io.github.sashirestela.cleverclient.example.openai.TranscriptionRequest.TimestampGranularity; | ||
|
||
import java.nio.file.Paths; | ||
|
||
public class MultipartExample extends AbstractExample { | ||
|
||
public MultipartExample(String clientAlias) { | ||
super(clientAlias); | ||
} | ||
|
||
public MultipartExample() { | ||
this("javahttp"); | ||
} | ||
|
||
public void run() { | ||
var cleverClient = CleverClient.builder() | ||
.baseUrl("https://api.openai.com") | ||
.clientAdapter(clientAdapter) | ||
.header("Authorization", "Bearer " + System.getenv("OPENAI_API_KEY")) | ||
.endOfStream("[DONE]") | ||
.build(); | ||
var audioService = cleverClient.create(AudioService.class); | ||
var audioRequest = TranscriptionRequest.builder() | ||
.file(Paths.get("src/test/resources/hello_audio.mp3")) | ||
.model("whisper-1") | ||
.responseFormat(AudioResponseFormat.VERBOSE_JSON) | ||
.temperature(0.2) | ||
.timestampGranularity(TimestampGranularity.WORD) | ||
.timestampGranularity(TimestampGranularity.SEGMENT) | ||
.build(); | ||
var audioResponse = audioService.transcribe(audioRequest); | ||
System.out.println(audioResponse.getText()); | ||
} | ||
|
||
public static void main(String[] args) { | ||
var example = new MultipartExample(); | ||
example.run(); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/example/java/io/github/sashirestela/cleverclient/example/MultipartExampleOkHttp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.sashirestela.cleverclient.example; | ||
|
||
public class MultipartExampleOkHttp extends MultipartExample { | ||
|
||
public MultipartExampleOkHttp() { | ||
super("okhttp"); | ||
} | ||
|
||
public static void main(String[] args) { | ||
var example = new MultipartExampleOkHttp(); | ||
example.run(); | ||
} | ||
|
||
} |
Oops, something went wrong.