Better names for cloned chats and profiles
This commit is contained in:
parent
b8f6e9f4ec
commit
67044b362c
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { applyProfile, getDefaultProfileKey, getProfile, getProfileSelect, setSystemPrompt } from './Profiles.svelte'
|
import { applyProfile, getDefaultProfileKey, getProfile, getProfileSelect, newNameForProfile, setSystemPrompt } from './Profiles.svelte'
|
||||||
import { getChatDefaults, getChatSettingList, getChatSettingObjectByKey, getExcludeFromProfile } from './Settings.svelte'
|
import { getChatDefaults, getChatSettingList, getChatSettingObjectByKey, getExcludeFromProfile } from './Settings.svelte'
|
||||||
import {
|
import {
|
||||||
saveChatStore,
|
saveChatStore,
|
||||||
|
@ -225,19 +225,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const newNameForProfile = (name:string):string => {
|
|
||||||
const profiles = getProfileSelect()
|
|
||||||
const nameMap = profiles.reduce((a, p) => { a[p.text] = p; return a }, {})
|
|
||||||
if (!nameMap[name]) return name
|
|
||||||
let i:number = 1
|
|
||||||
let cname = name + `-${i}`
|
|
||||||
while (nameMap[cname]) {
|
|
||||||
i++
|
|
||||||
cname = name + `-${i}`
|
|
||||||
}
|
|
||||||
return cname
|
|
||||||
}
|
|
||||||
|
|
||||||
const startNewChat = () => {
|
const startNewChat = () => {
|
||||||
const differentProfile = originalSettings.profile !== chatSettings.profile
|
const differentProfile = originalSettings.profile !== chatSettings.profile
|
||||||
// start new
|
// start new
|
||||||
|
|
|
@ -43,11 +43,12 @@
|
||||||
const chatId = newChatID()
|
const chatId = newChatID()
|
||||||
|
|
||||||
profile = JSON.parse(JSON.stringify(profile || getProfile(''))) as ChatSettings
|
profile = JSON.parse(JSON.stringify(profile || getProfile(''))) as ChatSettings
|
||||||
|
const nameMap = chats.reduce((a, chat) => { a[chat.name] = chat; return a }, {})
|
||||||
|
|
||||||
// Add a new chat
|
// Add a new chat
|
||||||
chats.push({
|
chats.push({
|
||||||
id: chatId,
|
id: chatId,
|
||||||
name: `Chat ${chatId}`,
|
name: newName(`Chat ${chatId}`, nameMap),
|
||||||
settings: profile,
|
settings: profile,
|
||||||
messages: [],
|
messages: [],
|
||||||
usage: {} as Record<Model, Usage>,
|
usage: {} as Record<Model, Usage>,
|
||||||
|
@ -387,12 +388,7 @@
|
||||||
const chats = get(chatsStorage)
|
const chats = get(chatsStorage)
|
||||||
const chat = chats.find((chat) => chat.id === chatId) as Chat
|
const chat = chats.find((chat) => chat.id === chatId) as Chat
|
||||||
const nameMap = chats.reduce((a, chat) => { a[chat.name] = chat; return a }, {})
|
const nameMap = chats.reduce((a, chat) => { a[chat.name] = chat; return a }, {})
|
||||||
let i:number = 1
|
const cname = newName(chat.name, nameMap)
|
||||||
let cname = chat.name + `-${i}`
|
|
||||||
while (nameMap[cname]) {
|
|
||||||
i++
|
|
||||||
cname = chat.name + `-${i}`
|
|
||||||
}
|
|
||||||
const chatCopy = JSON.parse(JSON.stringify(chat))
|
const chatCopy = JSON.parse(JSON.stringify(chat))
|
||||||
|
|
||||||
// Set the ID
|
// Set the ID
|
||||||
|
@ -557,11 +553,18 @@
|
||||||
|
|
||||||
export const newName = (name:string, nameMap:Record<string, any>):string => {
|
export const newName = (name:string, nameMap:Record<string, any>):string => {
|
||||||
if (!nameMap[name]) return name
|
if (!nameMap[name]) return name
|
||||||
|
const nm = name.match(/^(.*[^0-9]+)([- ])*([0-9]+)$/)
|
||||||
let i:number = 1
|
let i:number = 1
|
||||||
let cname = name + `-${i}`
|
let s = ' '
|
||||||
|
if (nm) {
|
||||||
|
name = nm[1]
|
||||||
|
s = nm[2] || ''
|
||||||
|
i = parseInt(nm[3])
|
||||||
|
}
|
||||||
|
let cname = `${name}${s}${i}`
|
||||||
while (nameMap[cname]) {
|
while (nameMap[cname]) {
|
||||||
i++
|
i++
|
||||||
cname = name + `-${i}`
|
cname = `${name}${s}${i}`
|
||||||
}
|
}
|
||||||
return cname
|
return cname
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue