Skip to content

Commit f864c37

Browse files
committed
feature: add showcase on JVM sample
1 parent 7c10c10 commit f864c37

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

sample/jvm/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ This endpoint generates images based on the provided prompt.
5656

5757
##### Example:
5858

59-
`GET http://localhost:8080/api/ychat/generations?prompt="ocean"
59+
`GET http://localhost:8080/api/ychat/generations?prompt="ocean"`
6060

6161
### Edits Endpoint
6262

@@ -71,4 +71,14 @@ This endpoint edits the prompt based on the provided instruction.
7171

7272
##### Example:
7373

74-
`GET http://localhost:8080/api/ychat/edits?input=What day of the wek is it?&instruction=Fix the spelling mistakes
74+
`GET http://localhost:8080/api/ychat/edits?input=What day of the wek is it?&instruction=Fix the spelling mistakes`
75+
76+
### List Models Endpoint
77+
78+
This endpoint retrieve a list of currently available artificial intelligence models.
79+
80+
##### Endpoint: http://localhost:[port_number]/api/ychat/models
81+
82+
##### Example:
83+
84+
`GET http://localhost:8080/api/ychat/models`

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package co.yml.ychat.jvm.controller;
22

3+
import co.yml.ychat.domain.model.AIModel;
4+
import co.yml.ychat.jvm.services.YChatService;
5+
import java.util.List;
36
import org.springframework.beans.factory.annotation.Autowired;
47
import org.springframework.http.ResponseEntity;
58
import org.springframework.web.bind.annotation.GetMapping;
69
import org.springframework.web.bind.annotation.RequestMapping;
710
import org.springframework.web.bind.annotation.RequestParam;
811
import org.springframework.web.bind.annotation.RestController;
9-
import co.yml.ychat.jvm.services.YChatService;
1012

1113
@RestController
1214
@RequestMapping("api/ychat")
@@ -49,6 +51,12 @@ public ResponseEntity<String> edits(
4951
return ResponseEntity.ok(result);
5052
}
5153

54+
@GetMapping("models")
55+
public ResponseEntity<List<AIModel>> models() throws Exception {
56+
List<AIModel> result = YChatService.getModels();
57+
return ResponseEntity.ok(result);
58+
}
59+
5260
private static class Defaults {
5361
static final String COMPLETION_INPUT = "Say this is a test.";
5462
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package co.yml.ychat.jvm.services;
22

3+
import co.yml.ychat.domain.model.AIModel;
34
import co.yml.ychat.domain.model.ChatMessage;
45
import java.util.List;
56
import org.jetbrains.annotations.NotNull;
@@ -50,6 +51,13 @@ public String getEditsAnswer(String input, String instruction) throws Exception
5051
return future.get().get(0);
5152
}
5253

54+
public List<AIModel> getModels() throws Exception {
55+
final CompletableFuture<List<AIModel>> future = new CompletableFuture<>();
56+
ychat.listModels()
57+
.execute(new CompletionCallbackResult<>(future));
58+
return future.get();
59+
}
60+
5361
private static class CompletionCallbackResult<T> implements YChat.Callback<T> {
5462

5563
private final CompletableFuture<T> future;

0 commit comments

Comments
 (0)