+23
-16
@@ -4,6 +4,7 @@ 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)
|
||||
|
||||
let updatedConversation = conversation;
|
||||
|
||||
@@ -11,7 +12,7 @@ export const cleanSelectedConversation = (conversation: Conversation) => {
|
||||
if (!updatedConversation.model) {
|
||||
updatedConversation = {
|
||||
...updatedConversation,
|
||||
model: OpenAIModels[OpenAIModelID.GPT_3_5]
|
||||
model: updatedConversation.model || OpenAIModels[OpenAIModelID.GPT_3_5]
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,7 +20,14 @@ export const cleanSelectedConversation = (conversation: Conversation) => {
|
||||
if (!updatedConversation.prompt) {
|
||||
updatedConversation = {
|
||||
...updatedConversation,
|
||||
prompt: DEFAULT_SYSTEM_PROMPT
|
||||
prompt: updatedConversation.prompt || DEFAULT_SYSTEM_PROMPT
|
||||
};
|
||||
}
|
||||
|
||||
if (!updatedConversation.folderId) {
|
||||
updatedConversation = {
|
||||
...updatedConversation,
|
||||
folderId: updatedConversation.folderId || 0
|
||||
};
|
||||
}
|
||||
|
||||
@@ -29,24 +37,23 @@ export const cleanSelectedConversation = (conversation: Conversation) => {
|
||||
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)
|
||||
|
||||
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]
|
||||
}));
|
||||
}
|
||||
updatedHistory.forEach((conversation) => {
|
||||
if (!conversation.model) {
|
||||
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
|
||||
}));
|
||||
}
|
||||
if (!conversation.prompt) {
|
||||
conversation.prompt = DEFAULT_SYSTEM_PROMPT;
|
||||
}
|
||||
|
||||
if (!conversation.folderId) {
|
||||
conversation.folderId = 0;
|
||||
}
|
||||
});
|
||||
|
||||
return updatedHistory;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
interface languageMap {
|
||||
[key: string]: string | undefined;
|
||||
}
|
||||
|
||||
export const programmingLanguages: languageMap = {
|
||||
javascript: ".js",
|
||||
python: ".py",
|
||||
java: ".java",
|
||||
c: ".c",
|
||||
cpp: ".cpp",
|
||||
"c++": ".cpp",
|
||||
"c#": ".cs",
|
||||
ruby: ".rb",
|
||||
php: ".php",
|
||||
swift: ".swift",
|
||||
"objective-c": ".m",
|
||||
kotlin: ".kt",
|
||||
typescript: ".ts",
|
||||
go: ".go",
|
||||
perl: ".pl",
|
||||
rust: ".rs",
|
||||
scala: ".scala",
|
||||
haskell: ".hs",
|
||||
lua: ".lua",
|
||||
shell: ".sh",
|
||||
sql: ".sql",
|
||||
html: ".html",
|
||||
css: ".css"
|
||||
// add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
|
||||
};
|
||||
|
||||
export const generateRandomString = (length: Number, lowercase = false) => {
|
||||
const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789"; // excluding similar looking characters like Z, 2, I, 1, O, 0
|
||||
let result = "";
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||
}
|
||||
return lowercase ? result.toLowerCase() : result;
|
||||
};
|
||||
@@ -1,64 +0,0 @@
|
||||
import { Conversation } from "@/types";
|
||||
|
||||
export const exportConversations = () => {
|
||||
const history = localStorage.getItem("conversationHistory");
|
||||
|
||||
if (!history) return;
|
||||
|
||||
const blob = new Blob([history], { type: "application/json" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.download = "chatbot_ui_history.json";
|
||||
link.href = url;
|
||||
link.style.display = "none";
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
export const importConversations = (conversations: Conversation[]) => {
|
||||
localStorage.setItem("conversationHistory", JSON.stringify(conversations));
|
||||
localStorage.setItem("selectedConversation", JSON.stringify(conversations[conversations.length - 1]));
|
||||
};
|
||||
|
||||
interface languageMap {
|
||||
[key: string]: string | undefined
|
||||
}
|
||||
|
||||
export const programmingLanguages: languageMap = {
|
||||
'javascript': '.js',
|
||||
'python': '.py',
|
||||
'java': '.java',
|
||||
'c': '.c',
|
||||
'cpp': '.cpp',
|
||||
'c++': '.cpp',
|
||||
'c#': '.cs',
|
||||
'ruby': '.rb',
|
||||
'php': '.php',
|
||||
'swift': '.swift',
|
||||
'objective-c': '.m',
|
||||
'kotlin': '.kt',
|
||||
'typescript': '.ts',
|
||||
'go': '.go',
|
||||
'perl': '.pl',
|
||||
'rust': '.rs',
|
||||
'scala': '.scala',
|
||||
'haskell': '.hs',
|
||||
'lua': '.lua',
|
||||
'shell': '.sh',
|
||||
'sql': '.sql',
|
||||
'html': '.html',
|
||||
'css': '.css'
|
||||
// add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
|
||||
};
|
||||
|
||||
|
||||
export const generateRandomString = (length: Number, lowercase=false) => {
|
||||
const chars = "ABCDEFGHJKLMNPQRSTUVWXY3456789"; // excluding similar looking characters like Z, 2, I, 1, O, 0
|
||||
let result = "";
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||
}
|
||||
return lowercase ? result.toLowerCase() : result;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { ChatFolder } from "@/types";
|
||||
|
||||
export const saveFolders = (folders: ChatFolder[]) => {
|
||||
localStorage.setItem("folders", JSON.stringify(folders));
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Conversation } from "@/types";
|
||||
|
||||
export const exportConversations = () => {
|
||||
const history = localStorage.getItem("conversationHistory");
|
||||
|
||||
if (!history) return;
|
||||
|
||||
const blob = new Blob([history], { type: "application/json" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.download = "chatbot_ui_history.json";
|
||||
link.href = url;
|
||||
link.style.display = "none";
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
export const importConversations = (conversations: Conversation[]) => {
|
||||
localStorage.setItem("conversationHistory", JSON.stringify(conversations));
|
||||
localStorage.setItem("selectedConversation", JSON.stringify(conversations[conversations.length - 1]));
|
||||
};
|
||||
Reference in New Issue
Block a user