Remove corpus counts from chat chrome

This commit is contained in:
2026-08-10 17:26:58 +07:00
parent 46469468bb
commit 97cb6d16f4
31 changed files with 2192 additions and 424 deletions
+13 -19
View File
@@ -12,14 +12,6 @@ interface ComposerProps {
className?: string;
}
const SAMPLE_SUGGESTIONS = [
"Liều dùng Paracetamol người lớn và trẻ em theo cân nặng",
"Chống chỉ định và tác dụng không mong muốn của Amoxicillin",
"Tương tác thuốc giữa Metformin và thuốc cản quang",
"Thận trọng khi dùng Aspirin cho bệnh nhân loét dạ dày",
"Hướng dẫn liều dùng Ibuprofen và giới hạn tối đa ngày",
];
export function Composer({
onSubmit,
isLoading = false,
@@ -76,13 +68,9 @@ export function Composer({
return;
}
}
// Fallback filter local suggestions
const filtered = SAMPLE_SUGGESTIONS.filter((s) =>
s.toLowerCase().includes(term.toLowerCase())
);
if (cancelled) return;
setSuggestions(filtered);
setShowSuggestions(filtered.length > 0);
setSuggestions([]);
setShowSuggestions(false);
} catch {
if (!cancelled) {
setSuggestions([]);
@@ -122,6 +110,15 @@ export function Composer({
setShowSuggestions(false);
};
const applySuggestion = (suggestion: string) => {
// Keep the clinical intent already typed and replace only the unfinished
// final token: "liều para" -> "liều Paracetamol", not "Paracetamol".
const prefix = value.match(/^([\s\S]*\s)[^\s]*$/)?.[1] ?? "";
setValue(`${prefix}${suggestion}`);
setShowSuggestions(false);
setSelectedIndex(-1);
};
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (showSuggestions && suggestions.length > 0) {
if (e.key === "ArrowDown") {
@@ -136,9 +133,7 @@ export function Composer({
}
if (e.key === "Enter" && selectedIndex >= 0) {
e.preventDefault();
setValue(suggestions[selectedIndex]);
setShowSuggestions(false);
setSelectedIndex(-1);
applySuggestion(suggestions[selectedIndex]);
return;
}
}
@@ -166,8 +161,7 @@ export function Composer({
<button
key={idx}
onClick={() => {
setValue(item);
setShowSuggestions(false);
applySuggestion(item);
inputRef.current?.focus();
}}
className={cn(