Giao diện
@tasco/ai/prompts
Prompt library có version. Đổi nội dung prompt thì tăng version và thêm eval case — xem MCP & AI review.
Biến
extractJson
ts
const extractJson: PromptDef<"content" | "schema">;Trích xuất dữ liệu có cấu trúc — ép model trả JSON thuần.
promptLibrary
ts
const promptLibrary: readonly [PromptDef<"app_name">, PromptDef<"max_points" | "content">, PromptDef<"content" | "schema">];Danh sách toàn bộ prompt trong library — eval CI chạy qua tập này.
summarize
ts
const summarize: PromptDef<"max_points" | "content">;Tóm tắt văn bản/nghiệp vụ thành gạch đầu dòng.
tascoAssistant
ts
const tascoAssistant: PromptDef<"app_name">;Persona trợ lý mặc định cho CChat trong app sản phẩm Tasco.
Hàm
definePrompt()
ts
function definePrompt<V>(def): PromptDef<V>;Helper giữ literal type cho tên biến (autocomplete khi render).
Tham số kiểu
| Tham số kiểu |
|---|
V extends string |
Tham số
| Tham số | Kiểu |
|---|---|
def | PromptDef<V> |
Trả về
PromptDef<V>
listPlaceholders()
ts
function listPlaceholders(template): string[];Liệt kê tên placeholder xuất hiện trong template (không trùng lặp).
Tham số
| Tham số | Kiểu |
|---|---|
template | string |
Trả về
string[]
renderPrompt()
ts
function renderPrompt<V>(def, vars?): string;Render prompt với biến — ném lỗi khi thiếu biến khai báo hoặc template còn placeholder không được cấp giá trị (typo guard).
Tham số kiểu
| Tham số kiểu |
|---|
V extends string |
Tham số
| Tham số | Kiểu |
|---|---|
def | PromptDef<V> |
vars | Record<V, string> |
Trả về
string
Interface
PromptDef
Định nghĩa một prompt có version. V là union tên biến, tạo bằng definePrompt để giữ literal type.
Tham số kiểu
| Tham số kiểu | Default type |
|---|---|
V extends string | string |