Skip to content

Commit f6fa602

Browse files
committed
Enhance language handling and formatting in ChatService
Updated system prompts in ChatService to emphasize that responses must match the user's question language. Added formatting requirements for answers, including the need for a period before citations. Clarified citation format and adjusted prompt construction for improved readability.
1 parent caa2ed4 commit f6fa602

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

SqlDatabaseVectorSearch/Services/ChatService.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public class ChatService(IChatCompletionService chatCompletionService, Tokenizer
1919
You are a helpful assistant that reformulates questions to perform embeddings search.
2020
Your task is to reformulate the question taking into account the context of the chat.
2121
The reformulated question must always explicitly contain the subject of the question.
22-
You must reformulate the question in the same language of the user's question. For example, if the user asks a question in English, the answer must be in English.
22+
You MUST reformulate the question in the SAME language as the user's question. For example, if the user asks a question in English, the reformulated question MUST be in English. If the user asks in Italian, the reformulated question MUST be in Italian.
23+
2324
Never add "in this chat", "in the context of this chat", "in the context of our conversation", "search for" or something like that in your answer.
2425
""";
2526

@@ -35,15 +36,16 @@ The reformulated question must always explicitly contain the subject of the ques
3536
- I'm sorry, I don't have enough information to answer that question.
3637
3738
Never answer questions that are not related to this chat.
38-
You must answer in the same language as the user's question. For example, if the user asks a question in English, the answer must be in English, no matter the language of the documents.
39+
40+
LANGUAGE RULE: You MUST ALWAYS answer in the SAME language as the user's question. For example, if the user asks a question in English, the answer MUST be in English. If the user asks in Italian, the answer MUST be in Italian. This rule applies NO MATTER what language the documents are written in. The language of your response must match the language of the question, NOT the language of the documents.
3941
4042
FORMATTING REQUIREMENT: Your answer MUST ALWAYS end with a period followed by a space before the citations block.
4143
If your answer doesn't naturally end with a period, you MUST add one followed by a space.
4244
4345
After the answer, you need to include citations following the XML format below ONLY IF you know the answer and are providing information from the context. If you do NOT know the answer, DO NOT include the citations section at all.
4446
45-
【<citation document-id="document_id" chunk-id="chunk_id" filename="string" page-number="page_number" index-on-page="index_on-page">exact quote here</citation>
46-
<citation document-id="document_id" chunk-id="chunk_id" filename="string" page-number="page_number" index-on-page="index_on-page">exact quote here</citation>】
47+
【<citation document-id="document_id" chunk-id="chunk_id" filename="string" page-number="page_number" index-on-page="index_on_page">exact quote here</citation>
48+
<citation document-id="document_id" chunk-id="chunk_id" filename="string" page-number="page_number" index-on-page="index_on_page">exact quote here</citation>】
4749
4850
The entire list of XML citations MUST be enclosed between 【 and 】 (U+3010 and U+3011) and must exactly match the above format.
4951
The quote in each <citation> MUST be MAXIMUM 5 words, taken word-for-word from the search result.
@@ -175,7 +177,7 @@ message.InnerContent is StreamingChatCompletionUpdate content && content.Usage i
175177
var prompt = new StringBuilder($"""
176178
Answer the following question:
177179
---
178-
{question}
180+
{question}
179181
=====
180182
Using the following information:
181183

0 commit comments

Comments
 (0)