forked from Niek/chatgpt-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow using URL Params to jumpstart NewChat with a given message.
For example, ``` https://localhost:5173/#/chat/new?message=hello ``` This will start a new chat and then send the message out to kickoff the session. Issue: Niek#418
- Loading branch information
Showing
1 changed file
with
25 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |