247_intelligent_tests.sql 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. -- Additive only: durable account capability tests; existing account/user rows stay intact.
  2. CREATE TABLE IF NOT EXISTS test_settings (
  3. test_type VARCHAR(64) PRIMARY KEY,
  4. enabled BOOLEAN NOT NULL DEFAULT true,
  5. user_visible BOOLEAN NOT NULL DEFAULT false,
  6. config JSONB NOT NULL,
  7. updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
  8. );
  9. INSERT INTO test_settings(test_type, config) VALUES
  10. ('pelican', '{"prompt":"请只输出一个独立、有效的 SVG,绘制一只骑自行车的鹈鹕。画面包含两个车轮、车架、鹈鹕身体、长喙和脚踏关系。使用 viewBox 和静态图形属性(fill、stroke、transform 等),不要使用 style、class、脚本、外部资源、foreignObject 或图片嵌入。","model":"","evaluator":"svg_structure","expected_answer":"","timeout_seconds":300}'),
  11. ('candy', '{"prompt":"盒子里有 24 颗糖。小明取走总数的四分之一,小红随后取走剩余糖的一半,最后小明放回 3 颗。盒子里现在有多少颗糖?请给出简短推导,并在最后单独一行输出 ANSWER: 数字。","model":"","evaluator":"exact_answer","expected_answer":"12","timeout_seconds":180}')
  12. ON CONFLICT(test_type) DO NOTHING;
  13. CREATE TABLE IF NOT EXISTS account_tests (
  14. id BIGSERIAL PRIMARY KEY,
  15. account_id BIGINT NOT NULL REFERENCES accounts(id) ON DELETE RESTRICT,
  16. test_type VARCHAR(64) NOT NULL REFERENCES test_settings(test_type) ON DELETE RESTRICT,
  17. status VARCHAR(32) NOT NULL DEFAULT 'queued'
  18. CHECK(status IN ('queued','running','success','failed','rate_limited','account_error','model_error','suspected_degradation')),
  19. score DOUBLE PRECISION CHECK(score IS NULL OR (score >= 0 AND score <= 100)),
  20. result TEXT NOT NULL DEFAULT '',
  21. result_image TEXT NOT NULL DEFAULT '',
  22. input TEXT NOT NULL,
  23. raw_response TEXT NOT NULL DEFAULT '',
  24. raw_truncated BOOLEAN NOT NULL DEFAULT false,
  25. error_message TEXT NOT NULL DEFAULT '',
  26. duration_ms BIGINT NOT NULL DEFAULT 0,
  27. model VARCHAR(200) NOT NULL DEFAULT '',
  28. anti_degradation BOOLEAN NOT NULL,
  29. config_snapshot JSONB NOT NULL,
  30. evaluation JSONB NOT NULL DEFAULT '{}',
  31. requested_by BIGINT NOT NULL,
  32. lease_token VARCHAR(64),
  33. lease_until TIMESTAMPTZ,
  34. started_at TIMESTAMPTZ,
  35. finished_at TIMESTAMPTZ,
  36. created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
  37. );
  38. CREATE INDEX IF NOT EXISTS idx_account_tests_account_history ON account_tests(account_id, test_type, id DESC);
  39. CREATE INDEX IF NOT EXISTS idx_account_tests_created ON account_tests(created_at DESC, id DESC);
  40. CREATE INDEX IF NOT EXISTS idx_account_tests_queue ON account_tests(status, id) WHERE status IN ('queued','running');
  41. CREATE UNIQUE INDEX IF NOT EXISTS idx_account_tests_active ON account_tests(account_id, test_type) WHERE status IN ('queued','running');
  42. CREATE TABLE IF NOT EXISTS intelligent_test_requests (
  43. actor_id BIGINT NOT NULL,
  44. request_key VARCHAR(100) NOT NULL,
  45. fingerprint VARCHAR(64) NOT NULL,
  46. record_ids BIGINT[] NOT NULL,
  47. created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  48. PRIMARY KEY(actor_id, request_key)
  49. );