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); } }