Prompts (#229)
This commit is contained in:
+6
-3
@@ -1,10 +1,12 @@
|
||||
import { Conversation, OpenAIModelID, OpenAIModels } from '@/types';
|
||||
import { Conversation } from '@/types/chat';
|
||||
import { OpenAIModelID, OpenAIModels } from '@/types/openai';
|
||||
import { DEFAULT_SYSTEM_PROMPT } from './const';
|
||||
|
||||
export const cleanSelectedConversation = (conversation: Conversation) => {
|
||||
// added model for each conversation (3/20/23)
|
||||
// added system prompt for each conversation (3/21/23)
|
||||
// added folders (3/23/23)
|
||||
// added prompts (3/26/23)
|
||||
|
||||
let updatedConversation = conversation;
|
||||
|
||||
@@ -27,7 +29,7 @@ export const cleanSelectedConversation = (conversation: Conversation) => {
|
||||
if (!updatedConversation.folderId) {
|
||||
updatedConversation = {
|
||||
...updatedConversation,
|
||||
folderId: updatedConversation.folderId || 0,
|
||||
folderId: updatedConversation.folderId || null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -38,6 +40,7 @@ export const cleanConversationHistory = (history: Conversation[]) => {
|
||||
// added model for each conversation (3/20/23)
|
||||
// added system prompt for each conversation (3/21/23)
|
||||
// added folders (3/23/23)
|
||||
// added prompts (3/26/23)
|
||||
|
||||
return history.reduce((acc: Conversation[], conversation) => {
|
||||
try {
|
||||
@@ -50,7 +53,7 @@ export const cleanConversationHistory = (history: Conversation[]) => {
|
||||
}
|
||||
|
||||
if (!conversation.folderId) {
|
||||
conversation.folderId = 0;
|
||||
conversation.folderId = null;
|
||||
}
|
||||
|
||||
acc.push(conversation);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Conversation } from '@/types';
|
||||
import { Conversation } from '@/types/chat';
|
||||
|
||||
export const updateConversation = (
|
||||
updatedConversation: Conversation,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ChatFolder } from '@/types';
|
||||
import { Folder } from '@/types/folder';
|
||||
|
||||
export const saveFolders = (folders: ChatFolder[]) => {
|
||||
export const saveFolders = (folders: Folder[]) => {
|
||||
localStorage.setItem('folders', JSON.stringify(folders));
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ChatFolder, Conversation } from '@/types';
|
||||
import { Conversation } from '@/types/chat';
|
||||
import { Folder } from '@/types/folder';
|
||||
|
||||
function currentDate() {
|
||||
const date = new Date();
|
||||
@@ -40,7 +41,7 @@ export const exportData = () => {
|
||||
|
||||
export const importData = (
|
||||
conversations: Conversation[],
|
||||
folders: ChatFolder[],
|
||||
folders: Folder[],
|
||||
) => {
|
||||
localStorage.setItem('conversationHistory', JSON.stringify(conversations));
|
||||
localStorage.setItem(
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Prompt } from '@/types/prompt';
|
||||
|
||||
export const updatePrompt = (updatedPrompt: Prompt, allPrompts: Prompt[]) => {
|
||||
const updatedPrompts = allPrompts.map((c) => {
|
||||
if (c.id === updatedPrompt.id) {
|
||||
return updatedPrompt;
|
||||
}
|
||||
|
||||
return c;
|
||||
});
|
||||
|
||||
savePrompts(updatedPrompts);
|
||||
|
||||
return {
|
||||
single: updatedPrompt,
|
||||
all: updatedPrompts,
|
||||
};
|
||||
};
|
||||
|
||||
export const savePrompts = (prompts: Prompt[]) => {
|
||||
localStorage.setItem('prompts', JSON.stringify(prompts));
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Message, OpenAIModel } from '@/types';
|
||||
import { Message } from '@/types/chat';
|
||||
import { OpenAIModel } from '@/types/openai';
|
||||
import {
|
||||
createParser,
|
||||
ParsedEvent,
|
||||
|
||||
Reference in New Issue
Block a user