|
1 | | -import { get } from '../../core/request' |
| 1 | +import { del, get, post, put } from '../../core/request' |
2 | 2 | import type { ParamsPage, ResponsePage } from '../../core/types' |
3 | | -import type { ParagraphProblem } from '@/api/types' |
| 3 | +import type { ParagraphProblem, ProblemBatchAssociationPayload, ProblemParagraph } from '@/api/types' |
4 | 4 | import { getWorkspaceId } from '@/utils/resource-context' |
5 | 5 |
|
| 6 | +const getPrefix = (knowledgeId: string) => `/workspace/${getWorkspaceId()}/knowledge/${knowledgeId}/problem` |
| 7 | + |
| 8 | +/** 批量创建知识库问题。 */ |
| 9 | +const postProblems = (knowledgeId: string, contents: string[]) => post<string[], void>(getPrefix(knowledgeId), contents) |
| 10 | + |
6 | 11 | /** 分页搜索知识库问题,供分段选择已有问题进行关联。 */ |
7 | 12 | const getProblemsPage = (knowledgeId: string, page: ParamsPage, query?: { content?: string }) => |
8 | | - get<ResponsePage<ParagraphProblem>>(`/workspace/${getWorkspaceId()}/knowledge/${knowledgeId}/problem/${page.currentPage}/${page.pageSize}`, query) |
| 13 | + get<ResponsePage<ParagraphProblem>>(`${getPrefix(knowledgeId)}/${page.currentPage}/${page.pageSize}`, query) |
| 14 | + |
| 15 | +/** 编辑单个知识库问题的内容。 */ |
| 16 | +const putProblem = (knowledgeId: string, problemId: string, content: string) => |
| 17 | + put<{ content: string }, void>(`${getPrefix(knowledgeId)}/${problemId}`, { content }) |
| 18 | + |
| 19 | +/** 删除单个知识库问题。 */ |
| 20 | +const deleteProblem = (knowledgeId: string, problemId: string) => del<undefined, boolean>(`${getPrefix(knowledgeId)}/${problemId}`) |
| 21 | + |
| 22 | +/** 获取问题当前关联的文档分段。 */ |
| 23 | +const getProblemParagraphs = (knowledgeId: string, problemId: string) => get<ProblemParagraph[]>(`${getPrefix(knowledgeId)}/${problemId}/paragraph`) |
| 24 | + |
| 25 | +/** 批量将问题关联到指定文档分段。 */ |
| 26 | +const putBatchAssociateProblems = (knowledgeId: string, payload: ProblemBatchAssociationPayload) => |
| 27 | + put<ProblemBatchAssociationPayload, boolean>(`${getPrefix(knowledgeId)}/batch_association`, payload) |
| 28 | + |
| 29 | +/** 批量删除知识库问题。 */ |
| 30 | +const putBatchDeleteProblems = (knowledgeId: string, problemIds: string[]) => |
| 31 | + put<string[], boolean>(`${getPrefix(knowledgeId)}/batch_delete`, problemIds) |
9 | 32 |
|
10 | | -export default { getProblemsPage } |
| 33 | +export default { |
| 34 | + postProblems, |
| 35 | + getProblemsPage, |
| 36 | + putProblem, |
| 37 | + deleteProblem, |
| 38 | + getProblemParagraphs, |
| 39 | + putBatchAssociateProblems, |
| 40 | + putBatchDeleteProblems, |
| 41 | +} |
0 commit comments