From 6bac170639fb9044d9cfe4a23d7a53e49d2b99b9 Mon Sep 17 00:00:00 2001 From: Oleh Astappiev Date: Tue, 13 Aug 2024 01:52:24 +0200 Subject: [PATCH] feat: change how title is created --- .../server/features/chat/ChatService.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/interweb-server/src/main/java/de/l3s/interweb/server/features/chat/ChatService.java b/interweb-server/src/main/java/de/l3s/interweb/server/features/chat/ChatService.java index 0ca02dcf..f274967b 100644 --- a/interweb-server/src/main/java/de/l3s/interweb/server/features/chat/ChatService.java +++ b/interweb-server/src/main/java/de/l3s/interweb/server/features/chat/ChatService.java @@ -41,10 +41,19 @@ private Uni completions(CompletionsQuery query, Model model, } public Uni generateTitle(final Chat chat) { + StringBuilder sb = new StringBuilder(); + for (ChatMessage message : chat.getMessages()) { + sb.append(" - [").append(message.role).append("] ").append(message.content); + } + CompletionsQuery query = new CompletionsQuery(); - query.setMessages(new ArrayList<>(chat.getMessages().stream().map(ChatMessage::toMessage).toList())); - query.addMessage("don't use any formatting; length between 80 and 120 characters;", Role.system); - query.addMessage("Give a short name for this conversation", Role.user); + query.addMessage(""" + ---BEGIN Conversation--- + %s + ---END Conversation--- + Summarize the conversation in 5 words or fewer, such that it could be a title of a book. + Don't use any formatting. You can use emojis. Only print the title, nothing else. + """.formatted(sb), Role.user); return completions(query); } }