الفصل 3: بناء منصات LLM
بنية المنصة
تخصيص التكلفة
class CostAllocator:
def __init__(self, pricing: dict):
self.pricing = pricing
self.usage = {}
def track_usage(self, team_id: str, model: str, tokens: int):
"""Track usage by team."""
if team_id not in self.usage:
self.usage[team_id] = {}
if model not in self.usage[team_id]:
self.usage[team_id][model] = 0
self.usage[team_id][model] += tokens
def calculate_cost(self, team_id: str) -> dict:
"""Calculate cost for a team."""
team_usage = self.usage.get(team_id, {})
costs = {}
total = 0
for model, tokens in team_usage.items():
cost = (tokens / 1000) * self.pricing[model]
costs[model] = cost
total += cost
return {"breakdown": costs, "total": total}
def generate_report(self) -> dict:
"""Generate monthly cost report."""
report = {}
for team_id in self.usage:
report[team_id] = self.calculate_cost(team_id)
return report
إطار الحوكمة
| الجانب | السياسة | التنفيذ |
|---|---|---|
| التحكم في الوصول | الوصول المستند إلى الأدوار | IAM، مفاتيح API |
| حدود الاستخدام | حصص لكل فريق | تحديد المعدل، الميزانيات |
| الوصول إلى النماذج | النماذج المعتمدة فقط | قائمة السماح بالنماذج |
| معالجة البيانات | قيود PII | تصفية المدخلات/المخرجات |
| التدقيق | تسجيل جميع التفاعلات | تسجيل الأحداث المركزي |
التالي: اختبار الوحدة 14