Skip to content

Commit 5a70cb5

Browse files
committed
chore: add jvm sample
1 parent 62b0830 commit 5a70cb5

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

sample/jvm/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,19 @@ curl -X POST \
106106
-H "Content-Type: multipart/form-data" \
107107
-F "file=@/path/to/audio/file" \
108108
"http://localhost:8080/api/ychat/audio/transcriptions"
109+
```
110+
111+
### Audio Translations Endpoint
112+
113+
This endpoint translates audio into English
114+
115+
##### Endpoint: http://localhost:[port_number]/api/ychat/audio/translations
116+
117+
##### Example:
118+
119+
```
120+
curl -X POST \
121+
-H "Content-Type: multipart/form-data" \
122+
-F "file=@/path/to/audio/file" \
123+
"http://localhost:8080/api/ychat/audio/translations"
109124
```

sample/jvm/src/main/java/co/yml/ychat/jvm/controller/YChatController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ public ResponseEntity<String> audioTranscriptions(
7474
return ResponseEntity.ok(result);
7575
}
7676

77+
@PostMapping("audio/translations")
78+
public ResponseEntity<String> audioTranslations(
79+
@RequestParam("file") MultipartFile multipartFile
80+
) throws Exception {
81+
String result = YChatService.getAudioTranscription(multipartFile);
82+
return ResponseEntity.ok(result);
83+
}
84+
7785
private static class Defaults {
7886
static final String COMPLETION_INPUT = "Say this is a test.";
7987
static final String CHAT_COMPLETION_INPUT = "Tell me one strength exercise";

sample/jvm/src/main/java/co/yml/ychat/jvm/services/YChatService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public String getAudioTranscription(MultipartFile multipartFile) throws Exceptio
7676
return future.get();
7777
}
7878

79+
public String getAudioTranslations(MultipartFile multipartFile) throws Exception {
80+
final CompletableFuture<String> future = new CompletableFuture<>();
81+
String filename = Optional.ofNullable(multipartFile.getOriginalFilename())
82+
.orElseThrow(() -> new IllegalStateException("Filename not found"));
83+
byte[] bytes = multipartFile.getBytes();
84+
ychat.audioTranslations().execute(filename, bytes, new CompletionCallbackResult<>(future));
85+
return future.get();
86+
}
87+
7988
private static class CompletionCallbackResult<T> implements YChat.Callback<T> {
8089

8190
private final CompletableFuture<T> future;

0 commit comments

Comments
 (0)