Skip to content

FR: server: Pre-fill textarea and auto-generate based on query parameters #11150

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
Binary file modified examples/server/public/index.html.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/server/webui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ <h2 class="font-bold ml-4">Conversations</h2>
id="msg-input"
dir="auto"
></textarea>
<button v-if="!isGenerating" class="btn btn-primary ml-2" @click="sendMessage" :disabled="inputMsg.length === 0">Send</button>
<button v-if="!isGenerating" class="btn btn-primary ml-2" @click="sendMessage" :disabled="inputMsg.length === 0" id="msg-send">Send</button>
<button v-else class="btn btn-neutral ml-2" @click="stopGeneration">Stop</button>
</div>
</div>
Expand Down
16 changes: 13 additions & 3 deletions examples/server/webui/src/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './styles.scss';
import { createApp, defineComponent, shallowRef, computed, h } from 'vue/dist/vue.esm-bundler.js';
import { createApp, defineComponent, shallowRef, computed, h, nextTick } from 'vue/dist/vue.esm-bundler.js';
import MarkdownIt from 'markdown-it';
import TextLineStream from 'textlinestream';

Expand Down Expand Up @@ -373,6 +373,10 @@ async function* sendSSEPostRequest(url, fetchOptions) {
}
};

const usp = new URLSearchParams (window.location.search);
const initial_query = usp.get ('q');
const initial_msg = initial_query || usp.get ('m') || '';

const mainApp = createApp({
components: {
VueMarkdown,
Expand All @@ -385,7 +389,7 @@ const mainApp = createApp({
/** @type {Array<Message>} */
messages: [],
viewingConvId: StorageUtils.getNewConvId(),
inputMsg: '',
inputMsg: initial_msg,
isGenerating: false,
/** @type {Array<Message> | null} */
pendingMsg: null, // the on-going message from assistant
Expand Down Expand Up @@ -660,7 +664,13 @@ const mainApp = createApp({
});
mainApp.config.errorHandler = alert;
try {
mainApp.mount('#app');
const appInstance = mainApp.mount('#app');
nextTick().then(() => {
if (initial_query)
appInstance.sendMessage();
else if (initial_msg)
setTimeout(() => document.getElementById('msg-input').focus(), 1);
});
} catch (err) {
console.error(err);
document.getElementById('app').innerHTML = `<div style="margin:2em auto">
Expand Down