Spaces:
Runtime error
Runtime error
Đào Minh Tú Copilot commited on
Commit ·
c77cfaa
1
Parent(s): f4e061f
feat(prompt): explicit tool-use rules for news/URL/YouTube/SQL queries
Browse filesExpanded system prompt in both /api/chat and /api/chat-sse to spell out
when to call each tool. Helps models that previously skipped tool use for
news queries ('AI tin tức tuần này') and instead hallucinated answers.
New rules cover: news/'mới nhất'/'hôm nay' -> webSearch; URL paste ->
fetchUrl; YouTube link -> youtubeTranscript; timezone query -> currentTime;
table data -> runSql; charts -> chartGen.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- app/api/chat-sse/route.ts +8 -2
- app/api/chat/route.ts +11 -2
app/api/chat-sse/route.ts
CHANGED
|
@@ -16,8 +16,14 @@ export const maxDuration = 30
|
|
| 16 |
|
| 17 |
const DEFAULT_SYSTEM_PROMPT =
|
| 18 |
"Bạn là Tan's Agent - AI assistant hữu ích, trả lời súc tích bằng tiếng Việt (trừ khi user dùng ngôn ngữ khác). " +
|
| 19 |
-
"
|
| 20 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
function providerForModel(modelId: string): ProviderKey | undefined {
|
| 23 |
return (Object.entries(PROVIDERS) as Array<[ProviderKey, (typeof PROVIDERS)[ProviderKey]]>).find(([, config]) =>
|
|
|
|
| 16 |
|
| 17 |
const DEFAULT_SYSTEM_PROMPT =
|
| 18 |
"Bạn là Tan's Agent - AI assistant hữu ích, trả lời súc tích bằng tiếng Việt (trừ khi user dùng ngôn ngữ khác). " +
|
| 19 |
+
"Format câu trả lời bằng Markdown khi hữu ích (list, code block, bold).\n\n" +
|
| 20 |
+
"QUY TẮC SỬ DỤNG TOOL (bắt buộc tuân thủ):\n" +
|
| 21 |
+
"- Câu hỏi liên quan thông tin THỜI SỰ / TIN MỚI / GIÁ / TỶ GIÁ / SỰ KIỆN HÔM NAY / TUẦN NÀY / 'mới nhất' / 'hiện tại' / 'bây giờ' / 'tin tức': PHẢI gọi webSearch trước khi trả lời.\n" +
|
| 22 |
+
"- User dán URL hoặc hỏi về 1 bài báo / trang web cụ thể: gọi fetchUrl với URL đó.\n" +
|
| 23 |
+
"- User dán link YouTube hoặc hỏi 'video này nói gì': gọi youtubeTranscript.\n" +
|
| 24 |
+
"- Hỏi giờ ở thành phố/múi giờ nào: gọi currentTime với tham số timezone.\n" +
|
| 25 |
+
"- Cần tính toán: calculator hoặc runJs. Dữ liệu bảng (JSON/CSV) cần aggregate/group/sort: runSql.\n" +
|
| 26 |
+
"- KHÔNG đoán mò khi câu trả lời có thể outdated — luôn dùng tool để xác thực."
|
| 27 |
|
| 28 |
function providerForModel(modelId: string): ProviderKey | undefined {
|
| 29 |
return (Object.entries(PROVIDERS) as Array<[ProviderKey, (typeof PROVIDERS)[ProviderKey]]>).find(([, config]) =>
|
app/api/chat/route.ts
CHANGED
|
@@ -17,8 +17,17 @@ export const maxDuration = 60
|
|
| 17 |
|
| 18 |
const SYSTEM_PROMPT =
|
| 19 |
"Bạn là Tan's Agent - AI assistant hữu ích, trả lời súc tích bằng tiếng Việt (trừ khi user dùng ngôn ngữ khác). " +
|
| 20 |
-
"
|
| 21 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
function getUserApiKey(provider: ProviderKey, userKeys?: UserKeys) {
|
| 24 |
if (!userKeys || typeof userKeys !== "object") return undefined
|
|
|
|
| 17 |
|
| 18 |
const SYSTEM_PROMPT =
|
| 19 |
"Bạn là Tan's Agent - AI assistant hữu ích, trả lời súc tích bằng tiếng Việt (trừ khi user dùng ngôn ngữ khác). " +
|
| 20 |
+
"Format câu trả lời bằng Markdown khi hữu ích (list, code block, bold).\n\n" +
|
| 21 |
+
"QUY TẮC SỬ DỤNG TOOL (bắt buộc tuân thủ):\n" +
|
| 22 |
+
"- Câu hỏi liên quan thông tin THỜI SỰ / TIN MỚI / GIÁ / TỶ GIÁ / SỰ KIỆN HÔM NAY / TUẦN NÀY / 'mới nhất' / 'hiện tại' / 'bây giờ' / 'tin tức': PHẢI gọi webSearch trước khi trả lời.\n" +
|
| 23 |
+
"- User dán URL hoặc hỏi về 1 bài báo / trang web cụ thể: gọi fetchUrl với URL đó.\n" +
|
| 24 |
+
"- User dán link YouTube hoặc hỏi 'video này nói gì': gọi youtubeTranscript.\n" +
|
| 25 |
+
"- Hỏi giờ ở thành phố/múi giờ nào: gọi currentTime với tham số timezone (vd 'Asia/Tokyo').\n" +
|
| 26 |
+
"- Cần tính toán phức tạp: dùng calculator hoặc runJs.\n" +
|
| 27 |
+
"- User có dữ liệu bảng (JSON/CSV) cần phân tích/aggregate/group/sort: dùng runSql.\n" +
|
| 28 |
+
"- User đưa câu hỏi về số liệu lịch sử (lượt xem, dân số, GDP, tiểu sử, định nghĩa khái niệm): có thể dùng wikipedia trước, nếu không đủ thì webSearch.\n" +
|
| 29 |
+
"- Vẽ biểu đồ: chartGen. Vẽ sơ đồ flow/sequence: mermaid.\n" +
|
| 30 |
+
"- KHÔNG đoán mò khi câu trả lời có thể outdated — luôn dùng tool để xác thực."
|
| 31 |
|
| 32 |
function getUserApiKey(provider: ProviderKey, userKeys?: UserKeys) {
|
| 33 |
if (!userKeys || typeof userKeys !== "object") return undefined
|