2025-10-21 11:40:47 +08:00
|
|
|
import { useUserData } from "./useUserData";
|
2025-10-21 16:41:22 +08:00
|
|
|
import { useEffect, useState } from "react";
|
2025-10-21 11:40:47 +08:00
|
|
|
import logger from "@/utils/logger";
|
|
|
|
|
import type { IUserInfo } from "@/interfaces/database/user-setting";
|
|
|
|
|
import userService from "@/services/user_service";
|
|
|
|
|
import { rsaPsw } from "../utils/encryption";
|
2025-10-21 16:41:22 +08:00
|
|
|
import type { IFactory, IMyLlmModel } from "@/interfaces/database/llm";
|
|
|
|
|
import type { LLMFactory } from "@/constants/llm";
|
2025-10-21 11:40:47 +08:00
|
|
|
|
2025-10-21 16:41:22 +08:00
|
|
|
/**
|
|
|
|
|
* 个人中心设置
|
|
|
|
|
*/
|
2025-10-21 11:40:47 +08:00
|
|
|
export function useProfileSetting() {
|
2025-10-22 15:27:31 +08:00
|
|
|
const { fetchUserInfo, userInfo } = useUserData();
|
2025-10-21 11:40:47 +08:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchUserInfo();
|
|
|
|
|
}, [fetchUserInfo]);
|
|
|
|
|
|
|
|
|
|
const updateUserInfo = async (newUserInfo: Partial<IUserInfo>) => {
|
|
|
|
|
try {
|
|
|
|
|
await userService.updateSetting(newUserInfo);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.error('更新用户信息失败:', error);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const changeUserPassword = async (data: { password: string; new_password: string }) => {
|
|
|
|
|
try {
|
|
|
|
|
const newPassword = rsaPsw(data.new_password);
|
|
|
|
|
const oldPassword = rsaPsw(data.password);
|
|
|
|
|
const res = await userService.updatePassword({
|
|
|
|
|
password: oldPassword,
|
|
|
|
|
new_password: newPassword,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
userInfo,
|
|
|
|
|
updateUserInfo,
|
|
|
|
|
changeUserPassword,
|
|
|
|
|
};
|
2025-10-21 16:41:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* LLM 模型设置
|
|
|
|
|
*/
|
|
|
|
|
export function useLlmModelSetting() {
|
|
|
|
|
const [llmFactory, setLlmFactory] = useState<IFactory[]>([]);
|
|
|
|
|
const [myLlm, setMyLlm] = useState<Record<LLMFactory, IMyLlmModel>>();
|
|
|
|
|
|
2025-10-22 15:27:31 +08:00
|
|
|
const fetchLlmFactory = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await userService.llm_factories_list();
|
|
|
|
|
const arr = res.data.data || [];
|
|
|
|
|
setLlmFactory(arr);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.error('获取模型工厂失败:', error);
|
|
|
|
|
throw error;
|
2025-10-21 16:41:22 +08:00
|
|
|
}
|
2025-10-22 15:27:31 +08:00
|
|
|
}
|
2025-10-21 16:41:22 +08:00
|
|
|
|
2025-10-22 15:27:31 +08:00
|
|
|
const fetchMyLlm = async () => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await userService.my_llm();
|
|
|
|
|
const llm_dic = res.data.data || {};
|
|
|
|
|
setMyLlm(llm_dic);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.error('获取我的模型失败:', error);
|
|
|
|
|
throw error;
|
2025-10-21 16:41:22 +08:00
|
|
|
}
|
2025-10-22 15:27:31 +08:00
|
|
|
}
|
|
|
|
|
useEffect(() => {
|
2025-10-21 16:41:22 +08:00
|
|
|
fetchLlmFactory();
|
|
|
|
|
fetchMyLlm();
|
2025-10-22 15:27:31 +08:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const refreshLlmModel = async () => {
|
|
|
|
|
await fetchMyLlm();
|
|
|
|
|
// await fetchLlmFactory();
|
|
|
|
|
logger.info('刷新我的模型成功');
|
|
|
|
|
}
|
2025-10-21 16:41:22 +08:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
llmFactory,
|
|
|
|
|
myLlm,
|
2025-10-22 15:27:31 +08:00
|
|
|
refreshLlmModel,
|
2025-10-21 16:41:22 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|