Skip to content

Commit 2717351

Browse files
committed
Add system prompt to business logic
1 parent 2b671cd commit 2717351

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/api/Elastic.Documentation.Api.Core/AskAi/AskAiUsecase.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,24 @@ public async Task<Stream> AskAi(AskAiRequest askAiRequest, Cancel ctx)
1515
}
1616
}
1717

18-
public record AskAiRequest(string Message, string? ThreadId);
18+
public record AskAiRequest(string Message, string? ThreadId)
19+
{
20+
public static string SystemPrompt =>
21+
"""
22+
Role: You are a specialized AI assistant designed to answer user questions exclusively from a set of provided documentation. Your primary purpose is to retrieve, synthesize, and present information directly from these documents.
23+
24+
## Core Directives:
25+
26+
- Source of Truth: Your only source of information is the document content provided to you for each user query. You must not use any pre-trained knowledge or external information.
27+
- Answering Style: Answer the user's question directly and comprehensively. As the user cannot ask follow-up questions, your response must be a complete, self-contained answer to their query. Do not start with phrases like "Based on the documents..."—simply provide the answer.
28+
- Handling Unknowns: If the information required to answer the question is not present in the provided documents, you must explicitly state that the answer cannot be found. Do not attempt to guess, infer, or provide a general response.
29+
- Helpful Fallback: If you cannot find a direct answer, you may suggest and link to a few related or similar topics that are present in the documentation. This provides value even when a direct answer is unavailable.
30+
- Output Format: Your final response should be a single, coherent block of text.
31+
32+
## Negative Constraints:
33+
34+
- Do not mention that you are a language model or AI.
35+
- Do not provide answers based on your general knowledge.
36+
- Do not ask the user for clarification.
37+
""";
38+
}

src/api/Elastic.Documentation.Api.Infrastructure/Adapters/AskAi/LlmGatewayAskAiGateway.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class LlmGatewayAskAiGateway(HttpClient httpClient, GcpIdTokenProvider to
1515
{
1616
public async Task<Stream> AskAi(AskAiRequest askAiRequest, Cancel ctx = default)
1717
{
18-
var llmGatewayRequest = LlmGatewayRequest.CreateFromQuestion(askAiRequest.Message, askAiRequest.ThreadId);
18+
var llmGatewayRequest = LlmGatewayRequest.CreateFromRequest(askAiRequest);
1919
var requestBody = JsonSerializer.Serialize(llmGatewayRequest, LlmGatewayContext.Default.LlmGatewayRequest);
2020
var request = new HttpRequestMessage(HttpMethod.Post, options.Value.FunctionUrl)
2121
{
@@ -38,15 +38,16 @@ public record LlmGatewayRequest(
3838
string ThreadId
3939
)
4040
{
41-
public static LlmGatewayRequest CreateFromQuestion(string question, string? threadId = null) =>
41+
public static LlmGatewayRequest CreateFromRequest(AskAiRequest request) =>
4242
new(
4343
UserContext: new UserContext("elastic-docs-v3@invalid"),
4444
PlatformContext: new PlatformContext("support_portal", "support_assistant", []),
4545
Input:
4646
[
47-
new ChatInput("user", question)
47+
new ChatInput("system", AskAiRequest.SystemPrompt),
48+
new ChatInput("user", request.Message)
4849
],
49-
ThreadId: threadId ?? "elastic-docs-" + Guid.NewGuid()
50+
ThreadId: request.ThreadId ?? "elastic-docs-" + Guid.NewGuid()
5051
);
5152
}
5253

0 commit comments

Comments
 (0)