25 lines
1.9 KiB
TypeScript
25 lines
1.9 KiB
TypeScript
import { useState } from 'react';
|
||
import { modelIdentityLabel, type ModelIdentity } from '../shared/contracts/model-identity.mjs';
|
||
import { downloadArtifact } from './api';
|
||
import './ModelIdentityDetails.css';
|
||
|
||
export function ModelIdentityDetails({ identity, requestedModel }: { identity?: ModelIdentity; requestedModel: string }) {
|
||
const [busy, setBusy] = useState(false), [notice, setNotice] = useState('');
|
||
const source = identity?.responseSource;
|
||
return <details className="model-identity-details" data-status={identity?.status ?? 'historical'}>
|
||
<summary>{modelIdentityLabel(identity)}</summary>
|
||
<dl><dt>请求型号</dt><dd>{identity?.requestedModel ?? requestedModel}</dd>
|
||
<dt>上游报告型号</dt><dd>{identity?.reportedModels.length ? identity.reportedModels.join('、') : identity ? '未报告' : '历史记录未核对'}</dd>
|
||
<dt>处理方式</dt><dd>{identity?.policy === 'require-match' ? '不一致或无法核对时暂停' : '记录原结果和型号差异'}</dd>
|
||
{identity?.mapping && <><dt>映射依据</dt><dd>{identity.mapping.source}<br /><small>用户登记 · {identity.mapping.models.join('、')}</small></dd></>}
|
||
</dl><p>这里只核对接口报告的型号,不能据此认证底层模型。</p>
|
||
{source && <><p className="model-identity-hash">原响应 SHA-256 <code>{source.sha256}</code></p>
|
||
<button className="button secondary" type="button" disabled={busy} onClick={async () => {
|
||
setBusy(true); setNotice('');
|
||
try { await downloadArtifact(source.sessionId, source.artifactId, 'model-response-' + source.artifactId + (source.scope === 'sse-stream' ? '.sse' : '.json')); setNotice('已下载保存的响应。'); }
|
||
catch (error) { setNotice(error instanceof Error ? error.message : '下载失败,请核对原任务。'); } finally { setBusy(false); }
|
||
}}>{busy ? '正在读取原响应…' : '下载原响应'}</button></>}
|
||
{notice && <p role="status">{notice}</p>}
|
||
</details>;
|
||
}
|