AI改写群公告接口改写
This commit is contained in:
@@ -6,19 +6,24 @@ import { useUserStore } from "@/store/module/user";
|
||||
* @param {string} content - 提示词内容
|
||||
* @returns {Promise<string>} - AI生成的文本内容
|
||||
*/
|
||||
export async function generateAiText(content: string): Promise<string> {
|
||||
export async function generateAiText(
|
||||
content: string,
|
||||
params?: { wechatAccountId: number | string; groupId: number | string },
|
||||
): Promise<string> {
|
||||
try {
|
||||
// 获取用户token
|
||||
const { token } = useUserStore.getState();
|
||||
|
||||
// 获取AI接口基础URL
|
||||
const apiBaseUrl = (import.meta as any).env?.VITE_API_BASE_URL || "/api";
|
||||
const fullUrl = `${apiBaseUrl}/v1/ai/doubao/text`;
|
||||
const fullUrl = `${apiBaseUrl}/v1/kefu/wechatChatroom/aiAnnouncement`;
|
||||
|
||||
// 发送POST请求
|
||||
const response = await axios.post(
|
||||
fullUrl,
|
||||
{
|
||||
wechatAccountId: params?.wechatAccountId,
|
||||
groupId: params?.groupId,
|
||||
content,
|
||||
},
|
||||
{
|
||||
@@ -30,12 +35,14 @@ export async function generateAiText(content: string): Promise<string> {
|
||||
}
|
||||
);
|
||||
|
||||
// 返回生成的文本内容
|
||||
// 根据接口返回格式:data.choices[0].message.content
|
||||
return response?.data?.data?.choices?.[0]?.message?.content || "";
|
||||
// 新接口返回:{ code: 200, msg: 'success', data: '...公告内容...' }
|
||||
if (response?.data?.code === 200) {
|
||||
return response?.data?.data || "";
|
||||
}
|
||||
return "";
|
||||
} catch (error: any) {
|
||||
const errorMessage =
|
||||
error.response?.data?.message || error.message || "AI生成失败";
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,8 +362,11 @@ const Person: React.FC<PersonProps> = ({
|
||||
setAiGenerating(true);
|
||||
try {
|
||||
// 调用AI接口生成群公告
|
||||
const aiResponse = await generateAiText(aiPrompt);
|
||||
|
||||
const aiResponse = await generateAiText(aiPrompt, {
|
||||
wechatAccountId: contract.wechatAccountId,
|
||||
groupId: contract.id,
|
||||
});
|
||||
|
||||
setAiGeneratedContent(aiResponse);
|
||||
messageApi.success("AI生成群公告成功!");
|
||||
} catch (error: any) {
|
||||
@@ -1197,11 +1200,11 @@ const Person: React.FC<PersonProps> = ({
|
||||
].filter(Boolean)}
|
||||
>
|
||||
{!hasGroupManagePermission() && (
|
||||
<div style={{
|
||||
marginBottom: "16px",
|
||||
padding: "12px",
|
||||
backgroundColor: "#fff7e6",
|
||||
border: "1px solid #ffd591",
|
||||
<div style={{
|
||||
marginBottom: "16px",
|
||||
padding: "12px",
|
||||
backgroundColor: "#fff7e6",
|
||||
border: "1px solid #ffd591",
|
||||
borderRadius: "6px",
|
||||
color: "#d46b08"
|
||||
}}>
|
||||
@@ -1214,7 +1217,7 @@ const Person: React.FC<PersonProps> = ({
|
||||
onChange={e => setGroupNoticeValue(e.target.value)}
|
||||
placeholder={hasGroupManagePermission() ? "请输入群公告内容,或点击AI编写按钮自动生成" : "仅群主可以修改群公告"}
|
||||
rows={8}
|
||||
style={{
|
||||
style={{
|
||||
resize: "none",
|
||||
whiteSpace: "pre-wrap",
|
||||
wordBreak: "break-word",
|
||||
|
||||
Reference in New Issue
Block a user