Skip to content

محاكي المستخدمين

حاكِ عدة مُعلّقين متزامنين في Potato لاختبار التكامل — اضبط استراتيجيات التعليق والسرعة ومستويات الاتفاق لاختبارات حِمل واقعية.

يتيح محاكي المستخدمين اختبارًا آليًّا لمهام التعليق في Potato عبر محاكاة عدة مستخدمين بسلوكيات ومستويات كفاءة قابلة للضبط.

نظرة عامة

المحاكي مفيد في:

  • اختبار ضبط الجودة: اختبر فحوص الانتباه والمعايير الذهبية وسلوك الحظر
  • اختبار لوحة التحكم: ولّد بيانات تعليق واقعية للوحة تحكم المشرف
  • اختبار القابلية للتوسّع: أخضع الخادم لضغط بعدد كبير من المستخدمين المتزامنين
  • تقييم مساعدة الذكاء الاصطناعي: قارن دقة النموذج اللغوي بسلوكيات شبيهة بالبشر
  • اختبار التعلّم النشط: حاكِ سير عمل تعليق تكراري

البداية السريعة

bash
# Basic random simulation with 10 users
python -m potato.simulator --server http://localhost:8000 --users 10
 
# With configuration file
python -m potato.simulator --config simulator-config.yaml --server http://localhost:8000
 
# Fast scalability test (no waiting between annotations)
python -m potato.simulator --server http://localhost:8000 --users 50 --parallel 10 --fast-mode

الإعداد

ملف إعدادات YAML

أنشئ ملف YAML يحمل إعدادات المحاكي:

yaml
simulator:
  # User configuration
  users:
    count: 20
    competence_distribution:
      good: 0.5      # 50% will be "good" annotators (80-90% accuracy)
      average: 0.3   # 30% "average" (60-70% accuracy)
      poor: 0.2      # 20% "poor" (40-50% accuracy)
 
  # Annotation strategy
  strategy: random  # random, biased, llm, pattern
 
  # Timing configuration
  timing:
    annotation_time:
      min: 2.0
      max: 45.0
      mean: 12.0
      std: 6.0
      distribution: normal  # uniform, normal, exponential
 
  # Execution
  execution:
    parallel_users: 5
    delay_between_users: 0.5
    max_annotations_per_user: 50
 
server:
  url: http://localhost:8000

مستويات الكفاءة

المستوىالدقةالوصف
perfect100%يطابق المعيار الذهبي دائمًا
good80-90%مُعلّق عالي الجودة
average60-70%عامل تعهيد جماعي نموذجي
poor40-50%مُعلّق منخفض الجودة
random~1/Nاختيار عشوائي من التصنيفات
adversarial0%خاطئ عمدًا (لاختبار ضبط الجودة)

استراتيجيات التعليق

الاستراتيجية العشوائية (الافتراضية)

تختار التصنيفات عشوائيًّا بتوزيع منتظم:

yaml
strategy: random

الاستراتيجية المنحازة

اختيار مرجَّح بناءً على تفضيلات التصنيفات:

yaml
strategy: biased
biased_config:
  label_weights:
    positive: 0.6
    negative: 0.3
    neutral: 0.1

استراتيجية النموذج اللغوي

تستخدم نموذجًا لغويًّا لتوليد التعليقات بناءً على محتوى النص:

yaml
strategy: llm
llm_config:
  endpoint_type: openai
  model: gpt-4o-mini
  api_key: ${OPENAI_API_KEY}
  temperature: 0.1
  add_noise: true
  noise_rate: 0.05

للنماذج اللغوية المحلية عبر Ollama:

yaml
strategy: llm
llm_config:
  endpoint_type: ollama
  model: llama3.2
  base_url: http://localhost:11434

خيارات سطر الأوامر

text
Usage: python -m potato.simulator [OPTIONS]

Required:
  --server, -s URL        Potato server URL

User Configuration:
  --users, -u NUM         Number of simulated users (default: 10)
  --competence DIST       Competence distribution

Strategy:
  --strategy TYPE         Strategy: random, biased, llm, pattern
  --llm-endpoint TYPE     LLM endpoint: openai, anthropic, ollama
  --llm-model NAME        LLM model name

Execution:
  --parallel, -p NUM      Max concurrent users (default: 5)
  --max-annotations, -m   Max annotations per user
  --fast-mode             Disable waiting between annotations

Output:
  --output-dir, -o DIR    Output directory (default: simulator_output)

اختبار ضبط الجودة

اختبر كشف فحوص الانتباه:

yaml
simulator:
  users:
    count: 10
    competence_distribution:
      adversarial: 1.0  # All users will fail
  quality_control:
    attention_check_fail_rate: 0.5
    respond_fast_rate: 0.3

ملفات المخرجات

بعد المحاكاة، تُصدَّر النتائج إلى مجلد المخرجات:

  • summary_{timestamp}.json - إحصاءات مجمّعة
  • user_results_{timestamp}.json - نتائج مفصّلة لكل مستخدم
  • annotations_{timestamp}.csv - كل التعليقات بصيغة مسطّحة

مثال الملخص

json
{
  "user_count": 20,
  "total_annotations": 400,
  "total_time_seconds": 125.3,
  "attention_checks": {
    "passed": 18,
    "failed": 2,
    "pass_rate": 0.9
  }
}

الاستخدام البرمجي

python
from potato.simulator import SimulatorManager, SimulatorConfig
 
# Create configuration
config = SimulatorConfig(
    user_count=10,
    strategy="random",
    competence_distribution={"good": 0.5, "average": 0.5}
)
 
# Create and run simulator
manager = SimulatorManager(config, "http://localhost:8000")
results = manager.run_parallel(max_annotations_per_user=20)
 
# Print summary and export
manager.print_summary()
manager.export_results()

التكامل مع الاختبارات

يمكن استخدام المحاكي في تجهيزات pytest:

python
import pytest
from potato.simulator import SimulatorManager, SimulatorConfig
 
@pytest.fixture
def simulated_annotations(flask_test_server):
    config = SimulatorConfig(user_count=5, strategy="random")
    manager = SimulatorManager(config, flask_test_server.base_url)
    return manager.run_parallel(max_annotations_per_user=10)
 
def test_dashboard_shows_annotations(simulated_annotations, flask_test_server):
    response = requests.get(f"{flask_test_server.base_url}/admin/api/overview")
    assert response.json()["total_annotations"] > 0

معالجة المشكلات

إخفاقات تسجيل الدخول

  • تأكد من أن الخادم يسمح بالتسجيل المجهول أو أن لديه require_password: false
  • راجع سجلات الخادم بحثًا عن أخطاء المصادقة

لا عناصر متاحة

  • تحقق من تحميل ملفات البيانات بشكل صحيح
  • راجع إعدادات استراتيجية التوزيع

استراتيجية النموذج اللغوي لا تعمل

  • تحقق من ضبط مفتاح الواجهة البرمجية
  • بالنسبة إلى Ollama، تأكد من أن الخادم يعمل
  • تحقق من صحة اسم النموذج

قراءات إضافية

للاطلاع على تفاصيل التنفيذ، انظر التوثيق المصدري.