Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ build/
*.swp
.DS_Store
Thumbs.db

# ===== 冒烟测试产物(不入库)=====
smoke_menu.jpg
10 changes: 10 additions & 0 deletions COMMUNICATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@

## 1. 协作会话记录

### S-8 | 2026-09-07 | 执行 B07/B08:可恢复任务与真实模型接入
- **参与方**:Product Owner(乔瑞雪)× ZCode(AI)
- **决策**:D-016 模型供应商选定阶跃星辰(StepFun),supersedes D-007;API key 由 PO 配置于 services/ai/.env(gitignored,不入库)。
- **结果**:
- B07(PR #12):audit_runs/jobs/findings 迁移、SKIP LOCKED 并发领取、租约+attempt token、重试耗尽与取消语义、原子落库(集成测试实测并修复『取消晚到 success 仍提交 findings』的落库顺序缺陷);Python /internal/assess 契约端点。
- B08(PR #13/#14):StepFun 视觉适配器(共享请求预算、auth/quota 不可重试、JSON repair)、assessment/v1 + extraction/v1 版本化 Prompt、content_url 预签名读图(契约修订)、5 类离线 eval fixture + runner 进 CI。
- 易用性(PR #15):模型凭据支持 services/ai/.env 文件配置(PO 反馈原配置找不到入口),.env.template 模板入库。
- **首次真实调用冒烟(2026-09-07)**:自制菜单图 fixture(明确标注非真实门店)→ step-1o-turbo-vision → 合法 assessment JSON;2 次 provider 请求(models 列表 + 1 次 chat,预算 6)、1,175 tokens、7.9s、cost=unknown 如实记录。判定合理:D2 语言可达 PASS、D5 支付 WARN(无国际卡标识)。
- **遗留问题**:D-006/D-009 与 D-011/D-012 仍待 PO;ADR-0002 评分语义待审定(B10 前置);T-006 真实素材未开始(B15 前置);本机 Docker 引擎未修复(T-003 compose 探活);下一批 B09(前端证据工作流)。

### S-7 | 2026-09-07 | 执行 B05/B06:认证租户与证据闭环
- **参与方**:Product Owner(乔瑞雪)× ZCode(AI)
- **结果**:
Expand Down
6 changes: 4 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
- DoD:Go 与 Python 两端都能从契约生成或校验类型;契约 lint 进 CI(哪怕 CI 只有这一步);
- Owner:AI Tech Lead + Application Lead。

- [ ] **T-008 模型 Provider Adapter + Prompt v1**
- [~] **T-008 模型 Provider Adapter + Prompt v1**
- 当前进展(B08,2026-09-07):StepFun 适配器(D-016 supersedes D-007)+ assessment/v1、extraction/v1 版本化 Prompt + 离线 eval runner(5 类 fixture,进 CI)已交付;**首次真实调用冒烟通过**——自制菜单图 → 合法 assessment JSON(step-1o-turbo-vision,2 次请求 / 1,175 tokens / 7.9s,cost=unknown 如实记录)。**未完成**:真实门店菜单图验证(随 T-006 素材)、备用 provider 与 fallback(未接通不声称已验证)。
- 原产出与 DoD:
- 产出:`StructuredModel` Protocol + 首个供应商 adapter(含 retry / fallback)+ `ai/prompts/extraction/v1.md`、`ai/prompts/assessment/v1.md`(版本化文件,不写死在代码里);
- DoD:业务层无供应商 SDK import;「一张菜单图 → 合法 assessment JSON」跑通;schema 校验失败走安全失败路径(TECH_SPEC §28);请求元数据(prompt_version / token / cost)有记录;
- Owner:AI Tech Lead。**依赖:D-007 供应商已暂定(豆包主 + Qwen-VL 备,待 PO 复核);若改选其他家,只影响 adapter,不影响本任务结构。**
Expand All @@ -86,7 +88,7 @@
| 任务 | 阻塞点 | 需要谁解除 |
|---|---|---|
| T-001 | 时间线 / 供应商 / 团队 / 验证顺序 四项决策讨论中 | Product Owner |
| T-008 | 依赖 D-007(模型供应商) | Product Owner |
| T-008 | ~~依赖 D-007~~ 已由 D-016 解除(StepFun) | Product Owner |

## Archive

Expand Down
25 changes: 12 additions & 13 deletions services/ai/.env.template
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# ===== Arrival Ready AI Service | 模型凭据配置 =====
# 复制本文件为 .env 并填入真实值: copy .env.template .env
# .env 已被 .gitignore 覆盖,绝不入库(docs/03 §4.3)。

# 阶跃星辰开放平台 API Key(platform.stepfun.com → API 管理 → 新建)
MODEL_API_KEY=

# 开放平台接口地址(一般不用改)
MODEL_BASE_URL=https://api.stepfun.com/v1

# 视觉模型 id(有额度的 vision 模型,如 step-1v-8k;不确定可留空,
# 首次冒烟时会先查询 /models 列出可用模型再选定)
MODEL_ID=
# ===== Arrival Ready AI Service | 模型凭据配置 =====
# 复制本文件为 .env 并填入真实值: copy .env.template .env
# .env 已被 .gitignore 覆盖,绝不入库(docs/03 §4.3)。

# 阶跃星辰开放平台 API Key(platform.stepfun.com → API 管理 → 新建)
MODEL_API_KEY=

# 开放平台接口地址(一般不用改)
MODEL_BASE_URL=https://api.stepfun.com/v1

# 视觉模型 id(2026-09-07 冒烟验证可用:step-1o-turbo-vision)
MODEL_ID=step-1o-turbo-vision
106 changes: 106 additions & 0 deletions services/ai/smoke_stepfun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env python
"""First real-provider smoke test (execution plan B08 verify, D-016 StepFun).

Budget discipline (execution plan §6): this script spends at most
1 GET /models (read-only listing) + 1 chat completion (+1 repair)
against the provider. Auth/quota errors stop immediately.

The input image is a SELF-MADE fixture (engineering-slice allowance, plan §1),
clearly labelled "not a real shop" — this smoke proves the API path, request
shape and structured-output parsing, NOT assessment quality or business value.

Usage: uv run python evals/runners/../scripts? -> services/ai/smoke_stepfun.py
(run from services/ai: uv run python smoke_stepfun.py <image.jpg>)
"""

from __future__ import annotations

import asyncio
import base64
import json
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent))

import httpx # noqa: E402

from app.config import get_settings # noqa: E402
from providers.base import StepFunVisionModel, rules_block # noqa: E402


async def main(image_path: str) -> int:
settings = get_settings()
if not settings.model_configured:
print("MODEL_API_KEY / MODEL_BASE_URL not configured")
return 2
model_id = settings.model_id or "step-1v-8k"
raw = Path(image_path).read_bytes()
b64 = base64.b64encode(raw).decode()
data_url = f"data:image/jpeg;base64,{b64}"

payload = {
"job_id": "smoke-job", "run_id": "smoke-run", "attempt_token": "smoke-token",
"prompt_version": "assessment/v1",
"project": {"project_id": "smoke", "entity_type": "restaurant", "target_locale": "en-US"},
"evidence": [{"evidence_id": "ev-smoke-1", "type": "image",
"journey_stage": "understand", "content_url": data_url}],
"applicable_rules": [
{"code": "IRRS-D2-001", "dimension": "D2",
"description": "菜单对目标访客语言可达(目标语言版本或可理解翻译路径)",
"review_required": False},
{"code": "IRRS-D5-001", "dimension": "D5",
"description": "支付方式以标识明示(国际卡/移动支付/现金)",
"review_required": True},
],
"budget": {"max_provider_requests": 6, "timeout_ms": 120000},
}

headers = {"Authorization": f"Bearer {settings.model_api_key}"}
async with httpx.AsyncClient(timeout=120) as client:
# Step 0 (read-only): confirm the chosen model id is available.
listing = await client.get(f"{settings.model_base_url}/models", headers=headers)
if listing.status_code != 200:
print(f"models list failed: HTTP {listing.status_code}: {listing.text[:200]}")
return 3
available = [m["id"] for m in listing.json().get("data", [])]
if model_id not in available:
print(f"model {model_id} not in account's model list; pick one from: {available}")
return 3
print(f"[0/1] models list OK; using {model_id}")

# Step 1 (the one real generation call): reuse the production adapter,
# but hand it an httpx client bound to this script so we can print
# usage. The adapter enforces the shared budget internally.
adapter = StepFunVisionModel(
api_key=settings.model_api_key,
base_url=settings.model_base_url,
model_id=model_id,
max_requests=2, # initial + at most one repair
)
response = await adapter.assess(payload)

print("=== ProviderResponse ===")
print(json.dumps(
{"outcome": response.get("outcome"),
"provider": response.get("metadata", {}).get("provider"),
"model": response.get("metadata", {}).get("model"),
"error": response.get("error")},
ensure_ascii=False))
if response.get("outcome") == "success":
for a in response.get("assessments", []):
print(f"- {a.get('rule_id')}: {a.get('status')} severity={a.get('severity')} "
f"confidence={a.get('confidence')} refs={[r.get('evidence_id') for r in a.get('evidence_refs', [])]}")
print(f" observation: {a.get('observation', '')[:120]}")
attempts = response.get("attempts", [])
if attempts:
print(f"usage: {attempts[0].get('usage')} | latency_ms: {attempts[0].get('latency_ms')} | "
f"cost: {attempts[0].get('cost')}")
return 0
print(json.dumps(response.get("error", {}), ensure_ascii=False))
return 1


if __name__ == "__main__":
image = sys.argv[1] if len(sys.argv) > 1 else "smoke_menu.jpg"
sys.exit(asyncio.run(main(image)))
Loading