File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
sample/jvm/src/main/java/co/yml/ychat/jvm Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 77import org .springframework .http .ResponseEntity ;
88import org .springframework .web .bind .annotation .GetMapping ;
99import org .springframework .web .bind .annotation .PathVariable ;
10+ import org .springframework .web .bind .annotation .PostMapping ;
1011import org .springframework .web .bind .annotation .RequestMapping ;
1112import org .springframework .web .bind .annotation .RequestParam ;
1213import org .springframework .web .bind .annotation .RestController ;
14+ import org .springframework .web .multipart .MultipartFile ;
1315
1416@ RestController
1517@ RequestMapping ("api/ychat" )
@@ -64,6 +66,14 @@ public ResponseEntity<AIModel> model(@PathVariable String id) throws Exception {
6466 return ResponseEntity .ok (result );
6567 }
6668
69+ @ PostMapping ("audio/transcriptions" )
70+ public ResponseEntity <String > audioTranscriptions (
71+ @ RequestParam ("file" ) MultipartFile multipartFile
72+ ) throws Exception {
73+ String result = YChatService .getAudioTranscription (multipartFile );
74+ return ResponseEntity .ok (result );
75+ }
76+
6777 private static class Defaults {
6878 static final String COMPLETION_INPUT = "Say this is a test." ;
6979 static final String CHAT_COMPLETION_INPUT = "Tell me one strength exercise" ;
Original file line number Diff line number Diff line change 44import co .yml .ychat .domain .model .AIModel ;
55import co .yml .ychat .domain .model .ChatMessage ;
66import java .util .List ;
7+ import java .util .Optional ;
78import java .util .concurrent .CompletableFuture ;
89import org .jetbrains .annotations .NotNull ;
910import org .springframework .beans .factory .annotation .Autowired ;
1011import org .springframework .stereotype .Service ;
12+ import org .springframework .web .multipart .MultipartFile ;
1113
1214@ Service
1315public class YChatService {
@@ -65,6 +67,14 @@ public AIModel getModel(String id) throws Exception {
6567 return future .get ();
6668 }
6769
70+ public String getAudioTranscription (MultipartFile multipartFile ) throws Exception {
71+ final CompletableFuture <String > future = new CompletableFuture <>();
72+ String filename = Optional .ofNullable (multipartFile .getOriginalFilename ()).orElse ("" );
73+ byte [] bytes = multipartFile .getBytes ();
74+ ychat .audioTranscriptions ().execute (filename , bytes , new CompletionCallbackResult <>(future ));
75+ return future .get ();
76+ }
77+
6878 private static class CompletionCallbackResult <T > implements YChat .Callback <T > {
6979
7080 private final CompletableFuture <T > future ;
You can’t perform that action at this time.
0 commit comments