diff --git a/src/hooks/useAIPPT.ts b/src/hooks/useAIPPT.ts index 8f1a486c..b499604c 100644 --- a/src/hooks/useAIPPT.ts +++ b/src/hooks/useAIPPT.ts @@ -217,6 +217,13 @@ export default () => { if (match) return match[1].trim() return content.replace('```markdown', '').replace('```', '') } + + const getJSONContent = (content: string) => { + const regex = /```json([^```]*)```/ + const match = content.match(regex) + if (match) return match[1].trim() + return content.replace('```json', '').replace('```', '') + } const AIPPT = (templateSlides: Slide[], _AISlides: AIPPTSlide[], imgs?: PexelsImage[]) => { if (imgs) imgPool.value = imgs @@ -480,5 +487,6 @@ export default () => { return { AIPPT, getMdContent, + getJSONContent, } } \ No newline at end of file diff --git a/src/services/index.ts b/src/services/index.ts index 541585af..f0061a5b 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -12,7 +12,11 @@ export default { return axios.get(`${ASSET_URL}/data/${filename}.json`) }, - AIPPT_Outline(content: string, language: string): Promise { + AIPPT_Outline( + content: string, + language: string, + model = 'doubao-1.5-pro-32k' + ): Promise { return fetch(`${SERVER_URL}/tools/aippt_outline`, { method: 'POST', headers: { @@ -21,12 +25,21 @@ export default { body: JSON.stringify({ content, language, + model, stream: true, }), }) }, - AIPPT(content: string, language: string) { - return axios.post(`${SERVER_URL}/tools/aippt`, { content, language }) + AIPPT( + content: string, + language: string, + model = 'doubao-1.5-pro-32k' + ) { + return axios.post(`${SERVER_URL}/tools/aippt`, { + content, + language, + model, + }) }, } \ No newline at end of file diff --git a/src/views/Editor/AIPPTDialog.vue b/src/views/Editor/AIPPTDialog.vue index 74f9f3ee..5a562d0f 100644 --- a/src/views/Editor/AIPPTDialog.vue +++ b/src/views/Editor/AIPPTDialog.vue @@ -68,7 +68,7 @@ import FullscreenSpin from '@/components/FullscreenSpin.vue' const mainStore = useMainStore() const { templates } = storeToRefs(useSlidesStore()) -const { AIPPT } = useAIPPT() +const { AIPPT, getJSONContent } = useAIPPT() const language = ref<'zh' | 'en'>('zh') const keyword = ref('') @@ -137,7 +137,7 @@ const createPPT = async () => { // const AISlides: AIPPTSlide[] = await api.getMockData('AIPPT') const AISlides: AIPPTSlide[] = await api.AIPPT(outline.value, language.value).then(ret => { - const obj = JSON.parse(ret.data[0].content) + const obj = JSON.parse(getJSONContent(ret.data[0].content)) return obj.data }) const templateSlides: Slide[] = await api.getFileData(selectedTemplate.value).then(ret => ret.slides)