Wire the prompt across from UI to worker to LLM.
Browse files- package.json +1 -1
- src/app/boot-app.js +1 -1
- src/app/enter-key.js +2 -2
- src/app/handle-prompt.js +14 -7
- src/app/worker-connection.js +2 -2
package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "localm",
|
| 3 |
-
"version": "1.0
|
| 4 |
"description": "",
|
| 5 |
"main": "chat-full.js",
|
| 6 |
"scripts": {
|
|
|
|
| 1 |
{
|
| 2 |
"name": "localm",
|
| 3 |
+
"version": "1.1.0",
|
| 4 |
"description": "",
|
| 5 |
"main": "chat-full.js",
|
| 6 |
"scripts": {
|
src/app/boot-app.js
CHANGED
|
@@ -26,7 +26,7 @@ export async function bootApp() {
|
|
| 26 |
const { chatLogEditor: chatLogEditorInstance, chatInputEditor: chatInputEditorInstance } = await initMilkdown({
|
| 27 |
chatLog,
|
| 28 |
chatInput,
|
| 29 |
-
inputPlugins: makeEnterPlugins()
|
| 30 |
});
|
| 31 |
chatLogEditor = chatLogEditorInstance;
|
| 32 |
chatInputEditor = chatInputEditorInstance;
|
|
|
|
| 26 |
const { chatLogEditor: chatLogEditorInstance, chatInputEditor: chatInputEditorInstance } = await initMilkdown({
|
| 27 |
chatLog,
|
| 28 |
chatInput,
|
| 29 |
+
inputPlugins: makeEnterPlugins({ workerConnection: worker })
|
| 30 |
});
|
| 31 |
chatLogEditor = chatLogEditorInstance;
|
| 32 |
chatInputEditor = chatInputEditorInstance;
|
src/app/enter-key.js
CHANGED
|
@@ -10,7 +10,7 @@ import { $command, $useKeymap } from '@milkdown/utils';
|
|
| 10 |
|
| 11 |
import { handlePrompt } from './handle-prompt';
|
| 12 |
|
| 13 |
-
export function makeEnterPlugins() {
|
| 14 |
// Create a command that sends the current input content to the chat log
|
| 15 |
const myEnterCommand = $command('MyEnterCommand', (ctx) => {
|
| 16 |
return () => (state, dispatch) => {
|
|
@@ -20,7 +20,7 @@ export function makeEnterPlugins() {
|
|
| 20 |
const markdown = (toMarkdown(view.state.doc) || '').trim();
|
| 21 |
|
| 22 |
if (markdown) {
|
| 23 |
-
handlePrompt(markdown);
|
| 24 |
}
|
| 25 |
|
| 26 |
// Clear input
|
|
|
|
| 10 |
|
| 11 |
import { handlePrompt } from './handle-prompt';
|
| 12 |
|
| 13 |
+
export function makeEnterPlugins({ workerConnection }) {
|
| 14 |
// Create a command that sends the current input content to the chat log
|
| 15 |
const myEnterCommand = $command('MyEnterCommand', (ctx) => {
|
| 16 |
return () => (state, dispatch) => {
|
|
|
|
| 20 |
const markdown = (toMarkdown(view.state.doc) || '').trim();
|
| 21 |
|
| 22 |
if (markdown) {
|
| 23 |
+
handlePrompt({ promptMarkdown: markdown, workerConnection });
|
| 24 |
}
|
| 25 |
|
| 26 |
// Clear input
|
src/app/handle-prompt.js
CHANGED
|
@@ -2,14 +2,21 @@
|
|
| 2 |
|
| 3 |
import { outputMessage } from './output-message';
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
outputMessage(formatted);
|
| 8 |
|
| 9 |
-
await new Promise(resolve => setTimeout(resolve, 100));
|
| 10 |
-
|
| 11 |
outputMessage('Processing your request...');
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
}
|
|
|
|
| 2 |
|
| 3 |
import { outputMessage } from './output-message';
|
| 4 |
|
| 5 |
+
/**
|
| 6 |
+
* @param {{
|
| 7 |
+
* promptMarkdown: string,
|
| 8 |
+
* workerConnection: ReturnType<import('./worker-connection').workerConnection>
|
| 9 |
+
* }} _
|
| 10 |
+
*/
|
| 11 |
+
export async function handlePrompt({ promptMarkdown, workerConnection }) {
|
| 12 |
+
const formatted = `**Question:**\n> ${promptMarkdown.replaceAll('\n', '\n> ')}`;
|
| 13 |
outputMessage(formatted);
|
| 14 |
|
|
|
|
|
|
|
| 15 |
outputMessage('Processing your request...');
|
| 16 |
+
try {
|
| 17 |
+
const promptOutput = await workerConnection.runPrompt(promptMarkdown);
|
| 18 |
+
outputMessage('**Reply:**\n' + promptOutput);
|
| 19 |
+
} catch (error) {
|
| 20 |
+
outputMessage('**Error:** ' + error.message);
|
| 21 |
+
}
|
| 22 |
}
|
src/app/worker-connection.js
CHANGED
|
@@ -84,7 +84,7 @@ export function workerConnection() {
|
|
| 84 |
*/
|
| 85 |
async function runPrompt(promptText, modelName) {
|
| 86 |
await workerLoaded;
|
| 87 |
-
|
| 88 |
-
|
| 89 |
}
|
| 90 |
}
|
|
|
|
| 84 |
*/
|
| 85 |
async function runPrompt(promptText, modelName) {
|
| 86 |
await workerLoaded;
|
| 87 |
+
const { send } = await workerLoaded;
|
| 88 |
+
return send({ type: 'runPrompt', prompt: promptText, modelName });
|
| 89 |
}
|
| 90 |
}
|