إنتقل إلى المحتوى الرئيسي

الفصل 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