Skip to content

Commit 8d8e54c

Browse files
committed
feature: Add JVM sample
1 parent b9dce3d commit 8d8e54c

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

sample/jvm/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,14 @@ This endpoint retrieve a list of currently available artificial intelligence mod
8181

8282
##### Example:
8383

84-
`GET http://localhost:8080/api/ychat/models`
84+
`GET http://localhost:8080/api/ychat/models`
85+
86+
### Model Endpoint
87+
88+
This endpoint retrieve the artificial intelligence model based on the given ID.
89+
90+
##### Endpoint: http://localhost:[port_number]/api/ychat/models/{modelID}
91+
92+
##### Example:
93+
94+
`GET http://localhost:8080/api/ychat/models/babbage`

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.springframework.beans.factory.annotation.Autowired;
77
import org.springframework.http.ResponseEntity;
88
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.PathVariable;
910
import org.springframework.web.bind.annotation.RequestMapping;
1011
import org.springframework.web.bind.annotation.RequestParam;
1112
import org.springframework.web.bind.annotation.RestController;
@@ -57,6 +58,12 @@ public ResponseEntity<List<AIModel>> models() throws Exception {
5758
return ResponseEntity.ok(result);
5859
}
5960

61+
@GetMapping("models/{id}")
62+
public ResponseEntity<AIModel> model(@PathVariable String id) throws Exception {
63+
AIModel result = YChatService.getModel(id);
64+
return ResponseEntity.ok(result);
65+
}
66+
6067
private static class Defaults {
6168
static final String COMPLETION_INPUT = "Say this is a test.";
6269
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package co.yml.ychat.jvm.services;
22

3+
import co.yml.ychat.YChat;
34
import co.yml.ychat.domain.model.AIModel;
45
import co.yml.ychat.domain.model.ChatMessage;
56
import java.util.List;
7+
import java.util.concurrent.CompletableFuture;
68
import org.jetbrains.annotations.NotNull;
79
import org.springframework.beans.factory.annotation.Autowired;
810
import org.springframework.stereotype.Service;
9-
import java.util.concurrent.CompletableFuture;
10-
import co.yml.ychat.YChat;
1111

1212
@Service
1313
public class YChatService {
@@ -58,6 +58,13 @@ public List<AIModel> getModels() throws Exception {
5858
return future.get();
5959
}
6060

61+
public AIModel getModel(String id) throws Exception {
62+
final CompletableFuture<AIModel> future = new CompletableFuture<>();
63+
ychat.retrieveModel()
64+
.execute(id, new CompletionCallbackResult<>(future));
65+
return future.get();
66+
}
67+
6168
private static class CompletionCallbackResult<T> implements YChat.Callback<T> {
6269

6370
private final CompletableFuture<T> future;

0 commit comments

Comments
 (0)