支持待确认事项逐条采纳
This commit is contained in:
@@ -16,7 +16,6 @@ const listFields = [
|
||||
"core_claims",
|
||||
"forbidden_claims",
|
||||
"image_topics",
|
||||
"uncertain_items",
|
||||
] as const;
|
||||
|
||||
const fieldLabels: Record<(typeof listFields)[number], string> = {
|
||||
@@ -26,9 +25,24 @@ const fieldLabels: Record<(typeof listFields)[number], string> = {
|
||||
core_claims: "核心事实/主张",
|
||||
forbidden_claims: "禁止使用的主张",
|
||||
image_topics: "图片主题",
|
||||
uncertain_items: "待确认事项",
|
||||
};
|
||||
|
||||
type UncertainItemResolutionTarget =
|
||||
| "core_claims"
|
||||
| "forbidden_claims"
|
||||
| "image_topics"
|
||||
| "ignore";
|
||||
|
||||
const uncertainItemActions: {
|
||||
label: string;
|
||||
target: UncertainItemResolutionTarget;
|
||||
}[] = [
|
||||
{ label: "采纳为核心事实", target: "core_claims" },
|
||||
{ label: "标记为禁止主张", target: "forbidden_claims" },
|
||||
{ label: "采纳为图片主题", target: "image_topics" },
|
||||
{ label: "忽略", target: "ignore" },
|
||||
];
|
||||
|
||||
export function FactCardEditor({
|
||||
factCard,
|
||||
isSaving,
|
||||
@@ -60,11 +74,18 @@ export function FactCardEditor({
|
||||
});
|
||||
}
|
||||
|
||||
function resolveItem(
|
||||
itemIndex: number,
|
||||
target: UncertainItemResolutionTarget,
|
||||
) {
|
||||
onChange(resolveUncertainItem(currentFactCard, itemIndex, target));
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="panel stack">
|
||||
<div className="panel-heading">
|
||||
<span>事实卡</span>
|
||||
<button disabled={!canOptimize || isSaving} onClick={onConfirm}>
|
||||
<button disabled={!canOptimize || isSaving} onClick={onConfirm} type="button">
|
||||
{isSaving ? "保存中..." : "确认事实卡"}
|
||||
</button>
|
||||
</div>
|
||||
@@ -122,6 +143,32 @@ export function FactCardEditor({
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
<div className="field-group">
|
||||
<div className="field-label">待确认事项</div>
|
||||
{factCard.uncertain_items.length > 0 ? (
|
||||
<div className="uncertain-list">
|
||||
{factCard.uncertain_items.map((item, index) => (
|
||||
<div className="uncertain-row" key={`${item}-${index}`}>
|
||||
<p>{item}</p>
|
||||
<div className="uncertain-actions">
|
||||
{uncertainItemActions.map((action) => (
|
||||
<button
|
||||
className="secondary-button"
|
||||
key={action.target}
|
||||
onClick={() => resolveItem(index, action.target)}
|
||||
type="button"
|
||||
>
|
||||
{action.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="status-text pass">待确认事项已处理。</p>
|
||||
)}
|
||||
</div>
|
||||
{!canOptimize && (
|
||||
<p className="status-text fail">
|
||||
请先处理待确认事项,再开始优化。
|
||||
@@ -141,3 +188,32 @@ export function toConfirmedFactCard(
|
||||
confirmed_by_user: true,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveUncertainItem(
|
||||
factCard: CandidateFactCard,
|
||||
itemIndex: number,
|
||||
target: UncertainItemResolutionTarget,
|
||||
): CandidateFactCard {
|
||||
const item = factCard.uncertain_items[itemIndex]?.trim();
|
||||
if (!item) return factCard;
|
||||
|
||||
const uncertainItems = factCard.uncertain_items.filter(
|
||||
(_, index) => index !== itemIndex,
|
||||
);
|
||||
const nextFactCard = {
|
||||
...factCard,
|
||||
uncertain_items: uncertainItems,
|
||||
is_ready_for_optimization: uncertainItems.length === 0,
|
||||
};
|
||||
|
||||
if (target === "ignore") return nextFactCard;
|
||||
|
||||
return {
|
||||
...nextFactCard,
|
||||
[target]: appendUniqueLine(nextFactCard[target], item),
|
||||
};
|
||||
}
|
||||
|
||||
function appendUniqueLine(values: string[], value: string) {
|
||||
return values.includes(value) ? values : [...values, value];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user