import { post, get, del, download } from '@/request/writingHttp' import { fetchWithAbort } from '@/request/fetchWithAbort'; import useStore from '@/stores' const { docs } = useStore(); /** * 2.1 获取模版 * @returns * @param type 模版类型, 0 - 法定类, 1 - 事物类, 2 - 自定义 */ export const getTemplate: (type: number) => Promise = (type) => { return get(`/v1/template?official_document_type=${type}`, undefined) } /** * 2.2 获取模版字段数据 * @returns * @param template_id */ export const getTemplateById: (template_id: number) => Promise = (template_id) => { return get(`/v1/template/${template_id}`, undefined) } interface CreateDocumentData { template_type: number template_id: string } /** * 2.3 创建新文档 * @returns * @param data */ export const createDocument: (data: { template_type: 0 | 1 template_id: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 }) => Promise = (data) => { return post(`/v1/document`, data) } /** * 2.4 获取文档基本信息 * @returns */ export const getBasicInfo: () => Promise = () => { return get(`/v1/document/${docs.document_id}/basic_info`) } /** * 2.5 提交基本信息字段数据 * @returns * @param data */ export const saveBasicInfo: (data: any) => Promise = (data) => { return post(`/v1/document/${docs.document_id}/basic_info`, data) } /** * 2.6 获取大纲 * @returns */ export const getOutline: () => Promise = () => { return get(`/v1/document/${docs.document_id}/outline`) } /** * 2.7 编辑大纲 * @returns * @param data */ export const saveOutline: ( data: any) => Promise = (data) => { return post(`/v1/document/${docs.document_id}/outline/${docs.outlineId}`, data) } interface SaveReferenceData { file: File, file_name: string file_type: 0 | 1 // 0 参考素材 1 数据参考 } /** * 2.8 提交参考文献 * @returns * @param data */ export const saveReference: (formData: FormData) => Promise = (data) => { return post(`/v1/document/${docs.document_id}/reference`, data) } /** * 2.9 查看参考文献 * @returns * @param reference_id */ export const delReference: (reference_id: string) => Promise = (reference_id) => { return del(`/v1/document/reference/${reference_id}`) } interface actionDocumentData { // 0 - start 开始生成, 1- rewrite,重写, 2 - delete 删除, 3- approve 采纳 action: 0 | 1 | 2 | 3, } /** * 2.10 文档操作 * 生成公文正文, SSE * @returns * @param data */ export const actionDocument: (data: actionDocumentData) => Promise = (data) => { return fetchWithAbort(`/ai-doc/api/v1/document/${docs.document_id}/content`, { ...data, model_id: docs.modelId }) } /** * 2.11 获取文档列表 * @returns * @param params */ export const getDocumentList: (params: any) => Promise = (params) => { return get(`/v1/document`, params) } /** * 2.12 删除文档 * @returns * @param document_ids */ export const deleteDocuments: (document_ids: any) => Promise = (document_ids) => { return del(`/v1/document`, undefined, { document_ids }) } /** * 2.13 获取文档 * @returns * @param document_id */ export const getDocumentItem: (document_id: string) => Promise = (document_id) => { return get(`/v1/document/${document_id}`, undefined) } /** * 2.14 编辑文档 * @returns * @param data */ export const saveDocumentItem: (data: any) => Promise = (data) => { return post(`/v1/document/${docs.document_id}`, data) } interface CreatePolishData { content: string action: 0 | 1 | 2 | 3// int, 0 - polish 润色,1 - extend 扩写 preferences?: { } } /** * 2.15 ai润色 * @returns * @param data */ export const createPolish: (data: CreatePolishData) => Promise = (data) => { return fetchWithAbort(`/ai-doc/api/v1/document/polish`, { ...data, model_id: docs.modelId }) } /** * 2.15 ai润色 * @returns */ export const downloadDocument: () => Promise = () => { return download(`/v1/document/${docs.document_id}/download`, 'get') } /** * * AI助手对话, SSE * @returns * @param data */ export const aiChat: (data: any) => Promise = (data) => { return fetchWithAbort(`/ai-doc/api/v1/chat`, { ...data, model_id: docs.modelId }) } /** * * 获取所有模型列表 * @returns */ export const getAllModel: () => Promise = () => { return get(`/v1/llm`) } /** * * 根据UUID获取特定LLM模型的配置详情 * @returns */ export const getModel: (llm_uuid: string) => Promise = (llm_uuid) => { return get(`/v1/llm/${llm_uuid}`) } /** * * 设置ai相关调用llm信息 * @returns */ export const setModel: (id: string) => Promise = (id) => { return post(`/v1/llm`, { id }) }