File tree Expand file tree Collapse file tree 2 files changed +10
-16
lines changed
openai-java-example/src/main/java/com/openai/example Expand file tree Collapse file tree 2 files changed +10
-16
lines changed Original file line number Diff line number Diff line change 22
33import com .openai .client .OpenAIClientAsync ;
44import com .openai .client .okhttp .OpenAIOkHttpClientAsync ;
5- import com .openai .core .MultipartField ;
65import com .openai .models .AudioModel ;
76import com .openai .models .AudioTranscriptionCreateParams ;
8- import java .io .IOException ;
7+ import java .nio .file .Path ;
8+ import java .nio .file .Paths ;
99
1010public final class AudioTranscriptionsAsyncExample {
1111 private AudioTranscriptionsAsyncExample () {}
1212
13- public static void main (String [] args ) throws IOException {
13+ public static void main (String [] args ) throws Exception {
1414 // Configures using one of:
1515 // - The `OPENAI_API_KEY` environment variable
1616 // - The `AZURE_OPENAI_ENDPOINT` and `AZURE_OPENAI_KEY` environment variables
1717 OpenAIClientAsync client = OpenAIOkHttpClientAsync .fromEnv ();
1818
1919 ClassLoader classloader = Thread .currentThread ().getContextClassLoader ();
20- String filename = "sports.wav" ;
20+ Path path = Paths . get ( classloader . getResource ( "sports.wav" ). toURI ()) ;
2121
2222 AudioTranscriptionCreateParams createParams = AudioTranscriptionCreateParams .builder ()
23- .file (MultipartField .<byte []>builder ()
24- .value (classloader .getResourceAsStream (filename ).readAllBytes ())
25- .filename (filename )
26- .build ())
23+ .file (path )
2724 .model (AudioModel .WHISPER_1 )
2825 .build ();
2926
Original file line number Diff line number Diff line change 22
33import com .openai .client .OpenAIClient ;
44import com .openai .client .okhttp .OpenAIOkHttpClient ;
5- import com .openai .core .MultipartField ;
65import com .openai .models .AudioModel ;
76import com .openai .models .AudioTranscriptionCreateParams ;
87import com .openai .models .Transcription ;
9- import java .io .IOException ;
8+ import java .nio .file .Path ;
9+ import java .nio .file .Paths ;
1010
1111public final class AudioTranscriptionsExample {
1212 private AudioTranscriptionsExample () {}
1313
14- public static void main (String [] args ) throws IOException {
14+ public static void main (String [] args ) throws Exception {
1515 // Configures using one of:
1616 // - The `OPENAI_API_KEY` environment variable
1717 // - The `AZURE_OPENAI_ENDPOINT` and `AZURE_OPENAI_KEY` environment variables
1818 OpenAIClient client = OpenAIOkHttpClient .fromEnv ();
1919
2020 ClassLoader classloader = Thread .currentThread ().getContextClassLoader ();
21- String filename = "sports.wav" ;
21+ Path path = Paths . get ( classloader . getResource ( "sports.wav" ). toURI ()) ;
2222
2323 AudioTranscriptionCreateParams createParams = AudioTranscriptionCreateParams .builder ()
24- .file (MultipartField .<byte []>builder ()
25- .value (classloader .getResourceAsStream (filename ).readAllBytes ())
26- .filename (filename )
27- .build ())
24+ .file (path )
2825 .model (AudioModel .WHISPER_1 )
2926 .build ();
3027
You can’t perform that action at this time.
0 commit comments