ระดับกลาง
5 ธันวาคม 2569หาบั๊กให้เจอ: AI Engineering
โค้ดหนึ่งชิ้น หาบั๊กให้เจอ หรือพิสูจน์ว่าไม่มีบั๊ก
typescript
1import Anthropic from '@anthropic-ai/sdk';
2
3declare const MODEL: string;
4
5const client = new Anthropic();
6
7const LABELS = ['billing', 'bug', 'feature_request', 'other'] as const;
8type Label = (typeof LABELS)[number];
9
10export async function classifyTicket(ticket: string): Promise<Label> {
11 const response = await client.messages.create({
12 model: MODEL,
13 max_tokens: 2048,
14 system: `Classify the support ticket. Answer with exactly one of: ${LABELS.join(', ')}.`,
15 messages: [{ role: 'user', content: ticket }],
16 });
17
18 if (response.stop_reason !== 'end_turn') {
19 throw new Error(`Classification failed: ${response.stop_reason}`);
20 }
21 const answer = (response.content[0] as Anthropic.TextBlock).text.trim();
22 const label = LABELS.find((candidate) => candidate === answer);
23 if (label === undefined) {
24 throw new Error(`Unexpected label: ${answer}`);
25 }
26 return label;
27}คลิกบรรทัดที่เป็นต้นเหตุของปัญหา
คำตัดสินของคุณ
วันละหนึ่งครั้ง คำตอบจะแสดงทันทีหลังจากนั้น
รักษาสถิติต่อเนื่องของคุณ
สร้างบัญชีเพื่อเก็บสถิติต่อเนื่องและติดตามความคืบหน้า