準備 AI 工程師面試:API 整合和 Fine-tuning 我踩過的坑
前情提要 在 RTL-AI-Lab 的第二個月,我花了兩週時間密集整理 AI 工程師面試會問到的東西。 不是因為我要換工作,而是因為我發現:我雖然用了很多 Claude API,但很多底層的東西我說不清楚。Rate limit 怎麼處理?Streaming 為什麼存在?Fine-tuning 和 RAG 到底什麼時候選哪個? 這篇文章是我實際寫過程式、踩過坑之後整理出來的,不是翻教科書。 一、API 整合:在正式環境裡用 AI 的四個關卡 關卡 1:Rate Limit 第一次遇到 HTTP 429 的時候我以為是我的程式壞了。後來才懂——Rate Limit 不是 bug,是設計。 正確處理方式是指數退避(Exponential Backoff):第一次失敗等 1 秒,第二次等 2 秒,第三次等 4 秒,以此類推,中間加一點隨機 jitter 避免所有 client 同時重試: from tenacity import retry, wait_exponential, stop_after_attempt, retry_if_exception_type import anthropic @retry( wait=wait_exponential(multiplier=1, min=1, max=60), stop=stop_after_attempt(5), retry=retry_if_exception_type(anthropic.RateLimitError) ) def call_claude(prompt: str) -> str: client = anthropic.Anthropic() message = client.messages.create( model="claude-opus-4-6", max_tokens=1024, messages=[{"role": "user", "content": prompt}] ) return message.content[0].text 手寫 retry loop 也可以,但用 tenacity 套件更乾淨,面試的時候說你用 tenacity 比手寫更加分。 ...