add custom system prompt (#39)

This commit is contained in:
Mckay Wrigley
2023-03-21 01:39:32 -06:00
committed by GitHub
parent 6e19d44020
commit 0d6ff739a2
16 changed files with 310 additions and 206 deletions
+52
View File
@@ -0,0 +1,52 @@
import { Conversation, OpenAIModelID, OpenAIModels } from "@/types";
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)
let updatedConversation = conversation;
// check for model on each conversation
if (!updatedConversation.model) {
updatedConversation = {
...updatedConversation,
model: OpenAIModels[OpenAIModelID.GPT_3_5]
};
}
// check for system prompt on each conversation
if (!updatedConversation.prompt) {
updatedConversation = {
...updatedConversation,
prompt: DEFAULT_SYSTEM_PROMPT
};
}
return updatedConversation;
};
export const cleanConversationHistory = (history: Conversation[]) => {
// added model for each conversation (3/20/23)
// added system prompt for each conversation (3/21/23)
let updatedHistory = [...history];
// check for model on each conversation
if (!updatedHistory.every((conversation) => conversation.model)) {
updatedHistory = updatedHistory.map((conversation) => ({
...conversation,
model: OpenAIModels[OpenAIModelID.GPT_3_5]
}));
}
// check for system prompt on each conversation
if (!updatedHistory.every((conversation) => conversation.prompt)) {
updatedHistory = updatedHistory.map((conversation) => ({
...conversation,
systemPrompt: DEFAULT_SYSTEM_PROMPT
}));
}
return updatedHistory;
};
+1
View File
@@ -0,0 +1 @@
export const DEFAULT_SYSTEM_PROMPT = "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown.";
+27
View File
@@ -0,0 +1,27 @@
import { Conversation } from "@/types";
export const updateConversation = (updatedConversation: Conversation, allConversations: Conversation[]) => {
const updatedConversations = allConversations.map((c) => {
if (c.id === updatedConversation.id) {
return updatedConversation;
}
return c;
});
saveConversation(updatedConversation);
saveConversations(updatedConversations);
return {
single: updatedConversation,
all: updatedConversations
};
};
export const saveConversation = (conversation: Conversation) => {
localStorage.setItem("selectedConversation", JSON.stringify(conversation));
};
export const saveConversations = (conversations: Conversation[]) => {
localStorage.setItem("conversationHistory", JSON.stringify(conversations));
};
-33
View File
@@ -1,33 +0,0 @@
import { Conversation, OpenAIModelID, OpenAIModels } from "@/types";
export const cleanConversationHistory = (history: Conversation[]) => {
// added model for each conversation (3/20/23)
if (history.length === 0) {
return history;
} else {
return history.map((conversation) => {
if (conversation.model) {
return conversation;
} else {
return {
...conversation,
model: OpenAIModels[OpenAIModelID.GPT_3_5]
};
}
});
}
};
export const cleanSelectedConversation = (conversation: Conversation) => {
// added model for each conversation (3/20/23)
if (conversation.model) {
return conversation;
} else {
return {
...conversation,
model: OpenAIModels[OpenAIModelID.GPT_3_5]
};
}
};