From 37762cfbabce82d7ad2c26cf0f9047c5a97e840f Mon Sep 17 00:00:00 2001 From: Jean Schmitz Date: Tue, 6 Feb 2024 17:26:15 +0100 Subject: [PATCH] Added Button to cancel run requests --- .../controller/AssistantController.java | 8 +++++++- .../assistant/service/AssistantService.java | 6 +++++- frontend/src/components/chat/ChatControl.vue | 19 +++++++++++++------ frontend/src/components/chat/ChatMessage.vue | 9 +++++++-- frontend/src/service/assistant.service.ts | 6 +++++- frontend/src/store/chat-store.ts | 18 +++++++++++++++--- .../assistant/OpenAIAssistantService.java | 15 +++++++++++++-- 7 files changed, 65 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/com/talkforgeai/backend/assistant/controller/AssistantController.java b/backend/src/main/java/com/talkforgeai/backend/assistant/controller/AssistantController.java index b7a38382..e13758d2 100644 --- a/backend/src/main/java/com/talkforgeai/backend/assistant/controller/AssistantController.java +++ b/backend/src/main/java/com/talkforgeai/backend/assistant/controller/AssistantController.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Jean Schmitz. + * Copyright (c) 2023-2024 Jean Schmitz. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -183,6 +183,12 @@ public Run getRun(@PathVariable("threadId") String threadId, return assistantService.retrieveRun(threadId, runId); } + @PostMapping("/threads/{threadId}/runs/{runId}/cancel") + public Run cancelRun(@PathVariable("threadId") String threadId, + @PathVariable("runId") String runId) { + return assistantService.cancelRun(threadId, runId); + } + @PostMapping("/threads/{threadId}/messages/{messageId}/postprocess") public ParsedMessageDto postProcessMessage(@PathVariable("threadId") String threadId, @PathVariable("messageId") String messageId) { diff --git a/backend/src/main/java/com/talkforgeai/backend/assistant/service/AssistantService.java b/backend/src/main/java/com/talkforgeai/backend/assistant/service/AssistantService.java index c4a6af7c..b86dc24d 100644 --- a/backend/src/main/java/com/talkforgeai/backend/assistant/service/AssistantService.java +++ b/backend/src/main/java/com/talkforgeai/backend/assistant/service/AssistantService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Jean Schmitz. + * Copyright (c) 2023-2024 Jean Schmitz. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -239,6 +239,10 @@ public Run retrieveRun(String threadId, String runId) { return this.openAIAssistantService.retrieveRun(threadId, runId); } + public Run cancelRun(String threadId, String runId) { + return openAIAssistantService.cancelRun(threadId, runId); + } + private ThreadDto mapToDto(ThreadEntity threadEntity) { return new ThreadDto(threadEntity.getId(), threadEntity.getTitle(), threadEntity.getCreatedAt()); diff --git a/frontend/src/components/chat/ChatControl.vue b/frontend/src/components/chat/ChatControl.vue index 2474300f..fad2c5cd 100644 --- a/frontend/src/components/chat/ChatControl.vue +++ b/frontend/src/components/chat/ChatControl.vue @@ -17,9 +17,9 @@