Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using URL Params to jumpstart NewChat with a given message. #419

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/lib/NewChat.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
<script lang="ts">
import { querystring } from 'svelte-spa-router'
import { addChat, setChatSettingValueByKey } from './Storage.svelte'
import {
addChat,
addMessage,
setChatSettingValueByKey,
submitExitingPromptsNow,
} from './Storage.svelte'
import { replace } from 'svelte-spa-router'
import { getProfile, restartProfile } from './Profiles.svelte'
import { getChatDefaults, hasChatSetting } from './Settings.svelte'
import { v4 as uuidv4 } from 'uuid'
import { type Message } from './Types.svelte'
// Create the new chat instance then redirect to it
const urlParams: URLSearchParams = new URLSearchParams($querystring)
const chatId = urlParams.has('p') ? addChat(getProfile(urlParams.get('p') || '')) : addChat()
Object.keys(getChatDefaults()).forEach(k => {
const chatId = urlParams.has("p")
? addChat(getProfile(urlParams.get("p") || ""))
: addChat()
Object.keys(getChatDefaults()).forEach((k) => {
if (urlParams.has(k) && hasChatSetting(k as any)) {
setChatSettingValueByKey(chatId, k as any, urlParams.get(k))
}
})
restartProfile(chatId)
const messageContent = urlParams.get("message")
if (messageContent !== null) {
const uuid = uuidv4()
const inputMessage: Message = {
role: "user",
content: messageContent,
uuid,
}
addMessage(chatId, inputMessage)
$submitExitingPromptsNow = true
}
replace(`/chat/${chatId}`)
</script>