2024-01-21 23:08:25 +08:00
|
|
|
|
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
2024-01-23 10:54:12 +08:00
|
|
|
|
import { Reference } from "@/utils/global";
|
2024-01-21 23:08:25 +08:00
|
|
|
|
export interface APIState {
|
|
|
|
|
apiKey: string;
|
2024-01-23 10:54:12 +08:00
|
|
|
|
referencesRedux: Reference[];
|
2024-01-23 12:10:03 +08:00
|
|
|
|
editorContent: string;
|
2024-01-27 23:25:07 +08:00
|
|
|
|
upsreamUrl: string;
|
2024-01-29 13:35:24 +08:00
|
|
|
|
systemPrompt: string;
|
2024-02-08 10:31:29 +08:00
|
|
|
|
showPaperManagement: boolean;
|
2024-01-21 23:08:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const initialState: APIState = {
|
2024-02-09 11:45:14 +08:00
|
|
|
|
apiKey: "sk-aiHrrRLYUUelHstX69E9484509254dBf92061d6744FfFaD1", //sk-ffe19ebe9fa44d00884330ff1c18cf82
|
2024-01-23 10:54:12 +08:00
|
|
|
|
referencesRedux: [],
|
2024-01-23 12:10:03 +08:00
|
|
|
|
editorContent: "",
|
2024-02-09 11:45:14 +08:00
|
|
|
|
upsreamUrl: "https://one.caifree.com", //https://api.openai.com https://one.caifree.com https://chatserver.3211000.xyz https://api.deepseek.com
|
2024-02-08 23:28:33 +08:00
|
|
|
|
systemPrompt: `作为论文写作助手,您的主要任务是根据用户提供的研究主题和上下文,以及相关的研究论文,来撰写和完善学术论文。在撰写过程中,请注意以下要点:
|
|
|
|
|
1.学术格式:请采用标准的学术论文格式进行写作,包括清晰的段落结构、逻辑严谨的论点展开,以及恰当的专业术语使用。
|
|
|
|
|
2.文献引用:只引用与主题紧密相关的论文。在引用文献时,文末应使用方括号内的数字来标注引用来源,如 [1]。。请确保每个引用在文章中都有其对应的编号,*无需在文章末尾提供参考文献列表*。*每个文献对应的序号只应该出现一次,比如说引用了第一篇文献文中就只能出现一次[1]*。
|
|
|
|
|
3.忽略无关文献:对于与主题无关的论文,请不要包含在您的写作中。只关注对理解和阐述主题有实质性帮助的资料。
|
|
|
|
|
4.来源明确:在文章中,清楚地指出每个引用的具体来源。引用的信息应准确无误,确保读者能够追溯到原始文献。
|
2024-02-09 11:45:14 +08:00
|
|
|
|
5.使用中文完成回答,不超过三百字
|
2024-02-08 23:28:33 +08:00
|
|
|
|
6.只能对给出的文献进行引用,坚决不能虚构文献。
|
|
|
|
|
返回格式举例:
|
|
|
|
|
在某个方面,某论文实现了以下突破...[1],在另一篇论文中,研究了...[2]`,
|
2024-02-08 10:31:29 +08:00
|
|
|
|
showPaperManagement: false,
|
2024-01-21 23:08:25 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const authSlice = createSlice({
|
|
|
|
|
name: "auth",
|
|
|
|
|
initialState,
|
|
|
|
|
reducers: {
|
2024-02-08 10:31:29 +08:00
|
|
|
|
setShowPaperManagement: (state, action: PayloadAction<boolean>) => {
|
|
|
|
|
state.showPaperManagement = action.payload;
|
|
|
|
|
},
|
2024-01-21 23:08:25 +08:00
|
|
|
|
setApiKey: (state, action: PayloadAction<string>) => {
|
|
|
|
|
state.apiKey = action.payload;
|
|
|
|
|
},
|
2024-01-27 23:25:07 +08:00
|
|
|
|
setUpsreamUrl: (state, action: PayloadAction<string>) => {
|
|
|
|
|
state.upsreamUrl = action.payload;
|
|
|
|
|
},
|
2024-01-29 13:35:24 +08:00
|
|
|
|
setSystemPrompt: (state, action: PayloadAction<string>) => {
|
|
|
|
|
state.systemPrompt = action.payload;
|
|
|
|
|
},
|
2024-01-29 15:01:43 +08:00
|
|
|
|
setEditorContent: (state, action: PayloadAction<string>) => {
|
|
|
|
|
state.editorContent = action.payload;
|
|
|
|
|
},
|
2024-01-23 10:54:12 +08:00
|
|
|
|
addReferenceRedux: (state, action: PayloadAction<Reference>) => {
|
|
|
|
|
state.referencesRedux.push(action.payload);
|
|
|
|
|
},
|
2024-01-30 09:00:16 +08:00
|
|
|
|
addReferencesRedux: (
|
|
|
|
|
state,
|
|
|
|
|
action: PayloadAction<{ references: Reference[]; position?: number }>
|
|
|
|
|
) => {
|
|
|
|
|
const { references, position } = action.payload;
|
|
|
|
|
const insertPosition =
|
|
|
|
|
position !== undefined ? position : state.referencesRedux.length;
|
|
|
|
|
state.referencesRedux.splice(insertPosition, 0, ...references);
|
2024-01-23 10:54:12 +08:00
|
|
|
|
},
|
|
|
|
|
removeReferenceRedux: (state, action: PayloadAction<number>) => {
|
|
|
|
|
state.referencesRedux = state.referencesRedux.filter(
|
|
|
|
|
(_, i) => i !== action.payload
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
clearReferencesRedux: (state) => {
|
|
|
|
|
state.referencesRedux = [];
|
|
|
|
|
},
|
2024-02-08 10:31:29 +08:00
|
|
|
|
setReferencesRedux: (state, action: PayloadAction<Reference[]>) => {
|
|
|
|
|
state.referencesRedux = action.payload;
|
|
|
|
|
},
|
2024-01-29 15:01:43 +08:00
|
|
|
|
swapReferencesRedux: (
|
|
|
|
|
state,
|
|
|
|
|
action: PayloadAction<{ indexA: number; indexB: number }>
|
|
|
|
|
) => {
|
|
|
|
|
console.log("moveReference", state.referencesRedux); // 调试输出
|
|
|
|
|
|
|
|
|
|
const { indexA, indexB } = action.payload;
|
|
|
|
|
if (
|
|
|
|
|
indexA >= 0 &&
|
|
|
|
|
indexA < state.referencesRedux.length &&
|
|
|
|
|
indexB >= 0 &&
|
|
|
|
|
indexB < state.referencesRedux.length
|
|
|
|
|
) {
|
|
|
|
|
const newReferences = [...state.referencesRedux];
|
|
|
|
|
const temp = newReferences[indexA];
|
|
|
|
|
newReferences[indexA] = newReferences[indexB];
|
|
|
|
|
newReferences[indexB] = temp;
|
|
|
|
|
state.referencesRedux = newReferences;
|
|
|
|
|
}
|
2024-01-23 12:10:03 +08:00
|
|
|
|
},
|
2024-01-21 23:08:25 +08:00
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Action creators are generated for each case reducer function
|
2024-01-23 10:54:12 +08:00
|
|
|
|
export const {
|
2024-02-08 10:31:29 +08:00
|
|
|
|
setShowPaperManagement,
|
2024-01-23 10:54:12 +08:00
|
|
|
|
setApiKey,
|
2024-01-27 23:25:07 +08:00
|
|
|
|
setUpsreamUrl,
|
2024-01-23 10:54:12 +08:00
|
|
|
|
addReferenceRedux,
|
|
|
|
|
addReferencesRedux,
|
|
|
|
|
removeReferenceRedux,
|
|
|
|
|
clearReferencesRedux,
|
2024-01-23 12:10:03 +08:00
|
|
|
|
setEditorContent,
|
2024-02-08 10:31:29 +08:00
|
|
|
|
setReferencesRedux,
|
2024-01-29 13:35:24 +08:00
|
|
|
|
setSystemPrompt,
|
2024-01-29 15:01:43 +08:00
|
|
|
|
swapReferencesRedux,
|
2024-01-23 10:54:12 +08:00
|
|
|
|
} = authSlice.actions;
|
2024-01-21 23:08:25 +08:00
|
|
|
|
|
|
|
|
|
export const authReducer = authSlice.reducer;
|