From 0c5455e4cdb95df2e290bdd7cac57694956cb34f Mon Sep 17 00:00:00 2001 From: Christian Tzolov Date: Thu, 10 Oct 2024 14:39:50 +0200 Subject: [PATCH] Improve context formatting in QuestionAnswerAdvisor - Add line breaks and clarify context boundaries in user text advice. This improve the performance of a Llama3.x - Update corresponding test to reflect new formatting --- .../ai/chat/client/advisor/QuestionAnswerAdvisor.java | 5 ++++- .../ai/chat/client/advisor/QuestionAnswerAdvisorTests.java | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/QuestionAnswerAdvisor.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/QuestionAnswerAdvisor.java index 788c47a14..33fb8b0f4 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/QuestionAnswerAdvisor.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/QuestionAnswerAdvisor.java @@ -52,10 +52,13 @@ import reactor.core.scheduler.Schedulers; public class QuestionAnswerAdvisor implements CallAroundAdvisor, StreamAroundAdvisor { private static final String DEFAULT_USER_TEXT_ADVISE = """ - Context information is below. + + Context information is below, surrounded by --------------------- + --------------------- {question_answer_context} --------------------- + Given the context and provided history information and not prior knowledge, reply to the user comment. If the answer is not in the context, inform the user that you can't answer the question. diff --git a/spring-ai-core/src/test/java/org/springframework/ai/chat/client/advisor/QuestionAnswerAdvisorTests.java b/spring-ai-core/src/test/java/org/springframework/ai/chat/client/advisor/QuestionAnswerAdvisorTests.java index 768513307..ec6d5bd1e 100644 --- a/spring-ai-core/src/test/java/org/springframework/ai/chat/client/advisor/QuestionAnswerAdvisorTests.java +++ b/spring-ai-core/src/test/java/org/springframework/ai/chat/client/advisor/QuestionAnswerAdvisorTests.java @@ -97,11 +97,13 @@ public class QuestionAnswerAdvisorTests { assertThat(userMessage.getContent()).isEqualToIgnoringWhitespace(""" Please answer my question XYZ - Context information is below. + Context information is below, surrounded by --------------------- + --------------------- doc1 doc2 --------------------- + Given the context and provided history information and not prior knowledge, reply to the user comment. If the answer is not in the context, inform the user that you can't answer the question.