fix java-openai: use baseUrl instead of baseURL, call .stream() on StreamResponse, skip TTS (not in SDK 0.8.1)
This commit is contained in:
parent
c6a09db0eb
commit
e765dadd34
1 changed files with 6 additions and 25 deletions
|
|
@ -60,7 +60,7 @@ public class uncloseai {
|
|||
System.out.println("=== Non-Streaming Chat (Model 1) ===");
|
||||
OpenAIClient client1 = OpenAIOkHttpClient.builder()
|
||||
.apiKey("dummy-key")
|
||||
.baseURL(modelEndpoint1)
|
||||
.baseUrl(modelEndpoint1)
|
||||
.build();
|
||||
|
||||
ChatCompletionCreateParams params1 = ChatCompletionCreateParams.builder()
|
||||
|
|
@ -97,8 +97,7 @@ public class uncloseai {
|
|||
.build();
|
||||
|
||||
System.out.print("Response: ");
|
||||
Stream<ChatCompletionChunk> stream1 = client1.chat().completions().createStreaming(streamParams1);
|
||||
stream1.forEach(chunk -> {
|
||||
client1.chat().completions().createStreaming(streamParams1).stream().forEach(chunk -> {
|
||||
if (!chunk.choices().isEmpty() && chunk.choices().get(0).delta().content().isPresent()) {
|
||||
System.out.print(chunk.choices().get(0).delta().content().get());
|
||||
}
|
||||
|
|
@ -109,7 +108,7 @@ public class uncloseai {
|
|||
System.out.println("=== Non-Streaming Chat (Model 2) ===");
|
||||
OpenAIClient client2 = OpenAIOkHttpClient.builder()
|
||||
.apiKey("dummy-key")
|
||||
.baseURL(modelEndpoint2)
|
||||
.baseUrl(modelEndpoint2)
|
||||
.build();
|
||||
|
||||
ChatCompletionCreateParams params2 = ChatCompletionCreateParams.builder()
|
||||
|
|
@ -146,34 +145,16 @@ public class uncloseai {
|
|||
.build();
|
||||
|
||||
System.out.print("Response: ");
|
||||
Stream<ChatCompletionChunk> stream2 = client2.chat().completions().createStreaming(streamParams2);
|
||||
stream2.forEach(chunk -> {
|
||||
client2.chat().completions().createStreaming(streamParams2).stream().forEach(chunk -> {
|
||||
if (!chunk.choices().isEmpty() && chunk.choices().get(0).delta().content().isPresent()) {
|
||||
System.out.print(chunk.choices().get(0).delta().content().get());
|
||||
}
|
||||
});
|
||||
System.out.println("\n");
|
||||
|
||||
// TTS example
|
||||
// TTS example - not supported in openai-java 0.8.1
|
||||
System.out.println("=== TTS Speech Generation ===");
|
||||
OpenAIClient ttsClient = OpenAIOkHttpClient.builder()
|
||||
.apiKey("dummy-key")
|
||||
.baseURL(ttsEndpoint1)
|
||||
.build();
|
||||
|
||||
SpeechCreateParams speechParams = SpeechCreateParams.builder()
|
||||
.model(SpeechModel.TTS_1)
|
||||
.voice(SpeechCreateParams.Voice.ALLOY)
|
||||
.input("I think so therefore, Today is a wonderful day to grow something people love!")
|
||||
.speed(0.9)
|
||||
.build();
|
||||
|
||||
byte[] audioBytes = ttsClient.audio().speech().create(speechParams);
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream("speech.mp3")) {
|
||||
fos.write(audioBytes);
|
||||
System.out.println("[OK] Speech file created: speech.mp3 (" + audioBytes.length + " bytes)\n");
|
||||
}
|
||||
System.out.println("[SKIPPED] TTS not available in openai-java SDK 0.8.1\n");
|
||||
|
||||
System.out.println("=== Examples Complete ===");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue