import { OperateCard, useProviderContext, Markdown } from '@agentscope-ai/chat'; import { Empty, IconButton, Tag } from '@agentscope-ai/design'; import { SparkBookLine, SparkDownLine, SparkUpLine, SparkWarningCircleFill } from '@agentscope-ai/icons'; import { ConfigProvider, Flex, Image } from 'antd'; import { Locale } from "antd/es/locale"; import React from 'react'; import { ReactNode, useState } from 'react'; export interface IRagProps { /** * @description 标题 * @descriptionEn Title * @default '知识库检索' */ title?: string; /** * @description 副标题 * @descriptionEn Subtitle * @default '' */ subTitle?: string; /** * @description 召回知识列表 * @descriptionEn RAG List * @default [] */ list: { score?: number | string | ReactNode; title: string; content: string; footer: string; images?: string[]; link?: string; }[] /** * @description 默认展开 * @descriptionEn Default Open * @default true */ defaultOpen?: boolean; /** * @description 空状态占位内容 * @descriptionEn Empty Placeholder * @default '暂无数据' */ placeholder?: string; query: string; /** * @description 检索图片列表 * @descriptionEn Query Images * @default [] */ images?: string[]; filters?: string; } // 兼容上游传入的 images 类型不规范(如单个字符串、null 等),统一归一化为字符串数组 function normalizeImages(images?: string[] | string | null): string[] { if (Array.isArray(images)) { return images.filter((image): image is string => typeof image === 'string' && !!image); } if (typeof images === 'string' && images) { return [images]; } return []; } function Images({ images }: { images?: string[] | string | null }) { const { getPrefixCls } = useProviderContext(); const prefixCls = getPrefixCls('operate-card'); const imageList = normalizeImages(images); if (!imageList.length) { return null; } return {imageList.map((image, index) => )} } function Item({ item }) { const [open, setOpen] = useState(false); const { getPrefixCls } = useProviderContext(); const prefixCls = getPrefixCls('operate-card'); return
{ setOpen(!open); }}> {item.title} { item.score ? 得分 {item.score} : null } : } />
{ open &&
{item.content}
{ normalizeImages(item.images).length ?
: null } { item.link ? { window.open(item.link, '_blank'); }} className={`${prefixCls}-rag-item-footer`} href={item.link} target="_blank">{item.footer} :
{item.footer}
}
}
} export default function (props: IRagProps) { const { title = '知识库检索', subTitle, defaultOpen = true, placeholder = '未查询到与提问相关知识库', images, query, filters } = props; const { getPrefixCls } = useProviderContext(); const prefixCls = getPrefixCls('operate-card'); const children =
检索 Query
{query}
{ normalizeImages(images).length ?
检索图片
: null } { filters ?
过滤条件
{filters}
: null } {props.list.length ?
Output
{ props.list.map((item, index) => { return }) }
: <>
Output
{placeholder} }
; return , title: title, description: subTitle, }} body={{ defaultOpen, children:
{children}
}} /> }