UPDATE: Fix chatbot
All checks were successful
Build and Release / release (push) Successful in 1m24s
All checks were successful
Build and Release / release (push) Successful in 1m24s
This commit is contained in:
@@ -43,15 +43,16 @@ func (s *chatbotService) Chat(ctx context.Context, projectID *string, question s
|
|||||||
prompt = fmt.Sprintf(`You are a friendly history assistant chatbot. The user said: "%s"
|
prompt = fmt.Sprintf(`You are a friendly history assistant chatbot. The user said: "%s"
|
||||||
|
|
||||||
Rules:
|
Rules:
|
||||||
- If it is a greeting (like "hello", "hi", "xin chào"), respond with a friendly greeting and briefly introduce yourself as a history assistant.
|
- If it is a greeting (like "hello", "hi", "xin chào"), respond with a friendly greeting and briefly introduce yourself.
|
||||||
- If it is a history question, say that you don't have relevant documents to answer and suggest they ask about topics available in the system.
|
- If it is a history question, say that you don't have relevant documents to answer.
|
||||||
- Do NOT show your reasoning or thinking process. Output ONLY your final response.`, question)
|
- You MUST wrap your final response inside <answer> tags. Example: <answer>Hello!</answer>
|
||||||
|
- Do NOT show your reasoning outside or inside the tags if possible, but the final answer MUST be in <answer> tags.`, question)
|
||||||
} else {
|
} else {
|
||||||
prompt = fmt.Sprintf(`You are a helpful history assistant. Answer the question using ONLY the provided context.
|
prompt = fmt.Sprintf(`You are a helpful history assistant. Answer the question using ONLY the provided context.
|
||||||
|
|
||||||
Rules:
|
Rules:
|
||||||
- If the answer is not in the context, say "I don't have enough historical context to answer that."
|
- If the answer is not in the context, say "I don't have enough historical context to answer that."
|
||||||
- Do NOT show your reasoning, thinking process, or analysis. Output ONLY your final answer.
|
- You MUST wrap your final response inside <answer> tags. Example: <answer>The capital is...</answer>
|
||||||
- Be concise and direct.
|
- Be concise and direct.
|
||||||
|
|
||||||
Context:
|
Context:
|
||||||
|
|||||||
@@ -97,12 +97,24 @@ func (u *RagUtils) GenerateResponse(ctx context.Context, prompt string) (string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stripThinking(raw string) string {
|
func stripThinking(raw string) string {
|
||||||
|
startTag := "<answer>"
|
||||||
|
endTag := "</answer>"
|
||||||
|
startIdx := strings.Index(raw, startTag)
|
||||||
|
endIdx := strings.LastIndex(raw, endTag)
|
||||||
|
|
||||||
|
if startIdx != -1 && endIdx != -1 && endIdx > startIdx {
|
||||||
|
return strings.TrimSpace(raw[startIdx+len(startTag) : endIdx])
|
||||||
|
}
|
||||||
|
|
||||||
|
if startIdx != -1 {
|
||||||
|
return strings.TrimSpace(raw[startIdx+len(startTag):])
|
||||||
|
}
|
||||||
|
|
||||||
if !strings.Contains(raw, "* ") {
|
if !strings.Contains(raw, "* ") {
|
||||||
return strings.TrimSpace(raw)
|
return strings.TrimSpace(raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
lines := strings.Split(raw, "\n")
|
lines := strings.Split(raw, "\n")
|
||||||
|
|
||||||
answerStart := len(lines)
|
answerStart := len(lines)
|
||||||
for i := len(lines) - 1; i >= 0; i-- {
|
for i := len(lines) - 1; i >= 0; i-- {
|
||||||
trimmed := strings.TrimSpace(lines[i])
|
trimmed := strings.TrimSpace(lines[i])
|
||||||
|
|||||||
Reference in New Issue
Block a user