提交 95ea0e5a authored 作者: 王鹏飞's avatar 王鹏飞

feat: 更新 useAIEdit 函数,使用 axios 发送请求并处理 AI 返回数据;调整章节管理菜单项

上级 0daa50b1
import { useState, useCallback } from 'react'
import { baiduAIChat } from '@/components/editor/api/ai'
import { useUserStore } from '@/stores/userStore'
import axios from 'axios'
export function useAIEdit() {
const [messages, setMessages] = useState([])
......@@ -10,9 +11,25 @@ export function useAIEdit() {
const fetch = useCallback(async (params) => {
setIsLoading(true)
try {
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 }
const defaultParams = { model: 'deepseek-v4-1-flash', stream: false }
const { userInfo } = useUserStore.getState()
const res = await axios.post(
'https://node-server.ezijing.com/ai/chat/completions',
{ ...defaultParams, ...params },
{
headers: {
Authorization: 'Bearer sk-ezj-HbVJBbbzGoCZUVaMXWH-Hyt2rHhdn9K4',
'X-User-Id': String(userInfo.id ?? ''),
'X-User-Name': encodeURIComponent(String(userInfo.real_name ?? '')),
},
},
)
const data = res.data
const content = data?.choices?.[0]?.message?.content ?? data?.result
if (typeof content !== 'string') {
throw new Error('AI 返回数据中缺少文本内容')
}
const message = { role: 'assistant', content }
setMessages((prevMessages) => [...prevMessages, message])
} catch (error) {
console.error('Error fetching data:', error)
......
......@@ -343,7 +343,7 @@ const Examine = () => {
let chapterMenuItems = [
{ key: '1', label: '展开全部' },
{ key: '2', label: '添加子节' },
{ key: '7', label: '关联知识图谱' },
// { key: '7', label: '关联知识图谱' },
{ key: '5', label: '设置编者' },
// {
// key: "6",
......
import axios, {
type AxiosRequestConfig,
type AxiosResponse,
type InternalAxiosRequestConfig,
} from 'axios'
import axios, { type AxiosRequestConfig, type AxiosResponse, type InternalAxiosRequestConfig } from 'axios'
import md5 from 'js-md5'
import { message, Modal, notification } from 'antd'
......@@ -66,10 +62,7 @@ function getSignData(data: unknown): Record<string, unknown> {
data.forEach((value, key) => {
if (value instanceof File) return
const previous = values[key]
values[key] =
previous === undefined
? value
: [...(Array.isArray(previous) ? previous : [previous]), value]
values[key] = previous === undefined ? value : [...(Array.isArray(previous) ? previous : [previous]), value]
})
return values
}
......@@ -125,7 +118,7 @@ httpRequest.interceptors.response.use(
if (location.pathname !== ADMIN_LOGIN_PATH) showLoginModal()
return Promise.reject(data)
}
if (data.code !== 200) {
if (data.code !== 200 && data.code !== 0) {
if (response.config.resolveBusinessError) return data
if (response.config.silentBusinessError) return Promise.reject(data)
notification.error({ message: data.message || '请求错误' })
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论