提交 97f423c0 authored 作者: 王鹏飞's avatar 王鹏飞

chore: update

上级 a1f837ea
......@@ -12,7 +12,7 @@ import { Boot } from '@wangeditor/editor'
import { SlateEditor, DomEditor, SlateElement, SlateTransforms } from '@wangeditor/editor'
import { Editor, Toolbar } from '@wangeditor/editor-for-react'
import { fontFamilyList, fontSizeList, lineHeightList } from './utils/setting'
import { fontFamilyList, lineHeightList } from './utils/setting'
import '@wangeditor/editor/dist/css/style.css' // 引入 css
import timesave from '@/assets/images/timesave.png'
......@@ -415,7 +415,26 @@ const WangEditorCustomer = (props, ref) => {
}
},
MENU_CONF: {
fontSize: { fontSizeList },
fontSize: {
fontSizeList: [
{ name: '初号', value: '56px' },
{ name: '小初', value: '48px' },
{ name: '一号', value: '34px' },
{ name: '小一', value: '32px' },
{ name: '二号', value: '29px' },
{ name: '小二', value: '24px' },
{ name: '三号', value: '21px' },
{ name: '小三', value: '20px' },
{ name: '四号', value: '18px' },
{ name: '小四', value: '16px' },
{ name: '五号', value: '14px' },
{ name: '小五', value: '12px' },
{ name: '六号', value: '10px' },
{ name: '小六', value: '8px' },
{ name: '七号', value: '7px' },
{ name: '八号', value: '6px' }
]
},
fontFamily: { fontFamilyList },
lineHeight: { lineHeightList }
}
......
import { useEffect, useState } from 'react'
import { Modal, Input, Button, Flex, Spin } from 'antd'
import { useAIEdit } from '@/hooks/useBaiduAI'
import { SlateTransforms } from '@wangeditor/editor'
const { TextArea } = Input
import { SlateEditor, SlateElement, SlateTransforms } from '@wangeditor/editor'
const actionMap = {
rewrite: { name: '改写', prompt: '帮我改写以下文字内容:' },
expand: { name: '扩写', prompt: '帮我在以下文字内容基础上进行扩写:' },
abbreviate: { name: '润色', prompt: '帮我润色以下文字内容:' },
summary: { name: '总结', prompt: '帮我总结以下文字内容:' },
punctuation: { name: '标点校对', prompt: '帮我校对以下文字内容中的标点符号' },
contentInspect: { name: '内容检查', prompt: '帮我检查以下文字内容中的敏感词和错别字' }
punctuation: {
name: '标点校对',
prompt: `帮我校对标点符号,要求如下:
1、如果标点符号没有问题,则告诉我“该内容标点符号正常”。
2、如果标点符号存在问题,则按照如下规则进行返回:
(1)带有错误标点符号的句子:
(2)纠正标点符号之后正确的句子:
(3)更新符号之后的完整内容:
具体要校对的内容如下:`
},
contentInspect: {
name: '内容检查',
prompt: `帮我检查敏感词和错别字,要求如下:
1、如果没有敏感词或者错别字,则告诉我“该内容正常,无敏感词和错别字”。
2、如果存在敏感词或错别字问题,则按照如下规则进行返回:
(1)带有敏感词或错别字的句子:
(2)纠正敏感词或错别字之后正确的句子:
(3)更新之后的完整内容:
具体要校对的内容如下:`
}
}
export default function AIModal({ editor, docAction }) {
......@@ -38,14 +56,37 @@ export default function AIModal({ editor, docAction }) {
}
const handlePrimary = () => {
let result = content.trim()
// 标点校对结果判断
if (docAction === 'punctuation') {
if (result.includes('该内容标点符号正常')) {
setIsModalOpen(false)
return
}
const match = result.match(/更新符号之后的完整内容[::]?\s?([\s\S]*)/)
if (match) {
result = match[1].trim()
}
}
// 内容检查结果判断
if (docAction === 'contentInspect') {
if (result.includes('该内容正常,无敏感词和错别字')) {
setIsModalOpen(false)
return
}
const match = result.match(/更新之后的完整内容[::]?\s?([\s\S]*)/)
if (match) {
result = match[1].trim()
}
}
console.log(result)
editor.restoreSelection()
// 删除当前选中的节点
SlateTransforms.removeNodes(editor)
const contentArr = content.split('\n').filter(item => item)
const nodeList = contentArr.map(item => {
const resultArr = result.split('\n').filter(item => item)
const nodeList = resultArr.map(item => {
return { type: 'paragraph', indent: '2em', children: [{ text: item }] }
})
console.log(nodeList, editor.children)
// 插入节点
SlateTransforms.insertNodes(editor, nodeList)
setIsModalOpen(false)
......
......@@ -10,7 +10,7 @@ export function useAIEdit() {
const fetch = useCallback(async params => {
setIsLoading(true)
try {
const defaultParams = { ernie_name: 'ERNIE-Lite-8K-0922', stream: false }
const defaultParams = { ernie_name: 'ERNIE-4.0-8K-Preview', stream: false }
const res = await baiduAIChat({ ...defaultParams, params })
const message = { role: 'assistant', content: res.data.result }
setMessages(prevMessages => [...prevMessages, message])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论