From 50a288ac9b4c59c4555e86bbf7f88b86c6d7a4af Mon Sep 17 00:00:00 2001 From: Arnaud Mengus Date: Thu, 6 Jun 2024 10:08:54 +0000 Subject: [PATCH] Models reponse for RaaG --- .../raag/OpenAiCompatibleV1ApiController.java | 16 ++++++++++++++++ .../ai/dragon/dto/openai/model/OpenAiModel.java | 15 +++++++++++++++ .../dto/openai/model/OpenAiModelsReponse.java | 15 +++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 backend/src/main/java/ai/dragon/dto/openai/model/OpenAiModel.java create mode 100644 backend/src/main/java/ai/dragon/dto/openai/model/OpenAiModelsReponse.java diff --git a/backend/src/main/java/ai/dragon/controller/api/raag/OpenAiCompatibleV1ApiController.java b/backend/src/main/java/ai/dragon/controller/api/raag/OpenAiCompatibleV1ApiController.java index f3d73564..23afdcc1 100644 --- a/backend/src/main/java/ai/dragon/controller/api/raag/OpenAiCompatibleV1ApiController.java +++ b/backend/src/main/java/ai/dragon/controller/api/raag/OpenAiCompatibleV1ApiController.java @@ -5,6 +5,7 @@ import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -18,6 +19,8 @@ import ai.dragon.dto.openai.completion.OpenAiCompletionRequest; import ai.dragon.dto.openai.completion.OpenAiCompletionResponse; import ai.dragon.dto.openai.completion.OpenAiCompletionUsage; +import ai.dragon.dto.openai.model.OpenAiModel; +import ai.dragon.dto.openai.model.OpenAiModelsReponse; import ai.dragon.service.SseService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -30,6 +33,19 @@ public class OpenAiCompatibleV1ApiController { @Autowired private SseService sseService; + @GetMapping("/models") + @Operation(summary = "List models", description = "Lists available models.") + public OpenAiModelsReponse models() { + return OpenAiModelsReponse.builder() + .data(List.of(OpenAiModel + .builder() + .created(System.currentTimeMillis() / 1000) + .id("dragon-ppx") + .owned_by("dRAGon") + .build())) + .build(); + } + @PostMapping("/completions") @Operation(summary = "Creates a completion", description = "Creates a completion for the provided prompt and parameters.") public Object completions(@Valid @RequestBody OpenAiCompletionRequest request) diff --git a/backend/src/main/java/ai/dragon/dto/openai/model/OpenAiModel.java b/backend/src/main/java/ai/dragon/dto/openai/model/OpenAiModel.java new file mode 100644 index 00000000..f3de29e9 --- /dev/null +++ b/backend/src/main/java/ai/dragon/dto/openai/model/OpenAiModel.java @@ -0,0 +1,15 @@ +package ai.dragon.dto.openai.model; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class OpenAiModel { + private String id; + private Long created; + private String owned_by; + + @Builder.Default + private String object = "model"; +} diff --git a/backend/src/main/java/ai/dragon/dto/openai/model/OpenAiModelsReponse.java b/backend/src/main/java/ai/dragon/dto/openai/model/OpenAiModelsReponse.java new file mode 100644 index 00000000..da4b423e --- /dev/null +++ b/backend/src/main/java/ai/dragon/dto/openai/model/OpenAiModelsReponse.java @@ -0,0 +1,15 @@ +package ai.dragon.dto.openai.model; + +import java.util.List; + +import lombok.Builder; +import lombok.Data; + +@Builder +@Data +public class OpenAiModelsReponse { + @Builder.Default + private String object = "list"; + + private List data; +}