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

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 @@ -157,7 +157,7 @@ <h2 class="font-bold ml-4">Conversations</h2>
:disabled="isGenerating"
id="msg-input"
></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>
tim-janik marked this conversation as resolved.
Show resolved Hide resolved
<button v-else class="btn btn-neutral ml-2" @click="stopGeneration">Stop</button>
</div>
</div>
Expand Down
15 changes: 12 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 @@ -313,6 +313,9 @@ async function* sendSSEPostRequest(url, fetchOptions) {
}
};

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pay attention to the coding style too

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly is the issue here?
I.e. what change would you like?


const mainApp = createApp({
components: {
VueMarkdown,
Expand All @@ -324,7 +327,7 @@ const mainApp = createApp({
conversations: StorageUtils.getAllConversations(),
messages: [], // { id: number, role: 'user' | 'assistant', content: string }
viewingConvId: StorageUtils.getNewConvId(),
inputMsg: '',
inputMsg: initial_msg,
isGenerating: false,
pendingMsg: null, // the on-going message from assistant
stopGeneration: () => {},
Expand Down Expand Up @@ -589,7 +592,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
Loading