ติดตามและตรวจสอบการเรียกใช้ LLM
เก็บโทเค็น เวลาแฝง และต้นทุนต่อคำขอ
ติดตามและตรวจสอบการเรียกใช้ LLM เป็นบทเรียน MLOps Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน MLOps Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส MLOps Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
You Cannot Fix What You Cannot See
An LLM app feels like a black box until you log what it does. Tracing records each call so you can debug, cost, and improve it later. 🔍
Capture the Request
For every call, log the final prompt, the model name, and key parameters. This request record lets you reproduce any answer exactly.
log.info({"model": "gpt-4o", "prompt": prompt, "temperature": 0.2})Capture the Response
Save the generated text alongside the request. Together the input and output form one trace you can replay, score, or share with a teammate.
Record Token Usage
Each response reports tokens in and out. Logging tokens per call is how you attribute cost and spot prompts that quietly grew too large.
usage = response.usage
log.info({"in": usage.input_tokens, "out": usage.output_tokens})Turn Tokens Into Cost
Multiply token counts by the price per token to get spend. Tracking cost per request keeps a runaway feature from surprising you on the bill.
cost = inp / 1e6 * 2.50 + out / 1e6 * 10.00Measure Latency
Time each call from send to final token. Watching latency per request reveals slow prompts and tells you when streaming would help users.
start = time.perf_counter()
response = client.responses.create(...)
latency = time.perf_counter() - startSpans Build a Trace
A real request may chain retrieval, the LLM, and a tool. Each step is a span, and nesting them into one trace shows where time and tokens go.
Tools Built for LLMs
Platforms like LangSmith, Langfuse, and Phoenix capture traces with one wrapper. A purpose-built observability tool beats parsing raw logs by hand.
from langfuse.openai import openai
response = openai.responses.create(model="gpt-4o", input=prompt)Tag Traces With Metadata
Attach a user id, prompt version, and feature name to each trace. This metadata lets you slice metrics and find which segment is misbehaving.
Sample What You Cannot Store
At high volume, logging every full payload is costly. Sampling a fraction of traces keeps insight while controlling storage and privacy.
Dashboards and Alerts
Roll traces into dashboards for cost, latency, and error rate, then alert on spikes. Now production problems reach you before users complain.
Quick Check
Your monthly LLM bill jumped with no traffic change. Which logged value explains it fastest?
Recap
You can now trace LLM calls end to end: request, response, tokens, cost, latency, and spans, then watch them on dashboards. Eyes wide open! 🎉
คำถามที่พบบ่อย
บทเรียน “ติดตามและตรวจสอบการเรียกใช้ LLM” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ติดตามและตรวจสอบการเรียกใช้ LLM” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส MLOps Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส MLOps Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ติดตามและตรวจสอบการเรียกใช้ LLM”
เก็บโทเค็น เวลาแฝง และต้นทุนต่อคำขอ คุณปฏิบัติ MLOps Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน MLOps Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน MLOps Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “ติดตามและตรวจสอบการเรียกใช้ LLM” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน MLOps Academy นี้ได้ไหม
ได้ บทเรียน MLOps Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- LLMOps แตกต่างจาก MLOps แบบดั้งเดิมอย่างไร
- จัดเวอร์ชันพรอมต์และประเมินเอาต์พุต
- ติดตามและตรวจสอบการเรียกใช้ LLM
- เกราะป้องกันและการประเมิน RAG