Chuyên sâu ⏱️ 25:00 🔥 Nổi bật
Tích hợp LLM API, Structured Outputs & Function Calling
Cách đưa trí tuệ nhân tạo vào sản phẩm thật: gọi OpenAI / Claude API với Structured Outputs (Zod Schema) và cho AI gọi các hàm nội bộ (Tools / Function Calling).
Structured Output với Zod
// File: src/ai/extractor.ts
import { OpenAI } from 'openai'
import { z } from 'zod'
import { zodResponseFormat } from 'openai/helpers/zod'
const ResumeSchema = z.object({
candidateName: z.string(),
yearsOfExperience: z.number(),
skills: z.array(z.string()),
matchScore: z.number().min(0).max(100)
})
export async function analyzeResume(resumeText: string) {
const client = new OpenAI()
const response = await client.beta.chat.completions.parse({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: resumeText }],
response_format: zodResponseFormat(ResumeSchema, 'resume_analysis')
})
return response.choices[0].message.parsed
}