快速入门
本指南将帮助您在 5 分钟内开始使用 SOVR SDK。
前置条件
- Python 3.8+ 或 Node.js 18+
- SOVR API Key(从 控制台 获取)
安装
bash
pip install sovr-sdkbash
npm install @sovr/sdk
# 或
pnpm add @sovr/sdk初始化客户端
python
from sovr_sdk import SOVRClient
client = SOVRClient(
base_url="https://api.sovr.ai",
api_key="your-api-key",
timeout=30 # 可选,默认 30 秒
)typescript
import { SOVRClient } from '@sovr/sdk';
const client = new SOVRClient({
baseUrl: 'https://api.sovr.ai',
apiKey: 'your-api-key',
timeout: 30000 // 可选,默认 30 秒
});创建第一个决策
决策(Decision)是 SOVR 的核心概念,代表 AI 执行的一个可追溯操作。
python
# 创建决策
decision = client.create_decision(
action="send_notification",
context={
"recipient": "user@example.com",
"message": "Your order has been shipped"
},
risk_level="low",
requires_approval=False
)
print(f"Decision created: {decision.id}")
print(f"Status: {decision.status}")typescript
// 创建决策
const decision = await client.createDecision({
action: 'send_notification',
context: {
recipient: 'user@example.com',
message: 'Your order has been shipped'
},
riskLevel: 'low',
requiresApproval: false
});
console.log(`Decision created: ${decision.id}`);
console.log(`Status: ${decision.status}`);创建信任包
信任包(Trust Bundle)用于收集和管理决策相关的证据。
python
# 创建信任包
bundle = client.create_trust_bundle(
name="Order Processing Bundle",
bundle_type="transaction",
description="信任包用于订单处理流程"
)
# 添加证据
client.add_evidence(
bundle_id=bundle.id,
evidence_type="audit_trail",
content={"action": "order_created", "order_id": "12345"},
source="order_service"
)
# 评估充分性
evaluation = client.evaluate_sufficiency(bundle.id)
print(f"Sufficiency Score: {evaluation.score}")
print(f"Status: {evaluation.status}")typescript
// 创建信任包
const bundle = await client.createTrustBundle({
name: 'Order Processing Bundle',
bundleType: 'transaction',
description: '信任包用于订单处理流程'
});
// 添加证据
await client.addEvidence({
bundleId: bundle.id,
evidenceType: 'audit_trail',
content: { action: 'order_created', orderId: '12345' },
source: 'order_service'
});
// 评估充分性
const evaluation = await client.evaluateSufficiency(bundle.id);
console.log(`Sufficiency Score: ${evaluation.score}`);
console.log(`Status: ${evaluation.status}`);查询审计日志
python
# 查询最近的审计日志
logs = client.query_audit_logs(
entity_type="decision",
limit=10
)
for log in logs:
print(f"[{log.created_at}] {log.event_type}: {log.action}")typescript
// 查询最近的审计日志
const logs = await client.queryAuditLogs({
entityType: 'decision',
limit: 10
});
for (const log of logs) {
console.log(`[${log.createdAt}] ${log.eventType}: ${log.action}`);
}