Skip to content

Commit a338a95

Browse files
committed
impl TextViewer for Tool Args/Output + SystemPrompt
1 parent 21e5583 commit a338a95

9 files changed

Lines changed: 268 additions & 182 deletions

File tree

llms/extensions/app/ui/threadStore.mjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,11 @@ async function startNewThread({ title, model, tools, redirect }) {
354354
async function queueChat(ctxRequest, options = {}) {
355355
if (!ctxRequest.request) return ctx.createErrorResult({ message: 'No request provided' })
356356
if (!ctxRequest.thread) return ctx.createErrorResult({ message: 'No thread provided' })
357-
if (!ctxRequest.request.metadata) {
358-
ctxRequest.request.metadata = {}
359-
}
357+
ctxRequest = ctx.createChatContext(ctxRequest)
360358
ctx.chatRequestFilters.forEach(f => f(ctxRequest))
361359
const { thread, request } = ctxRequest
360+
ctx.completeChatContext(ctxRequest)
361+
362362
const api = await ctx.postJson(`/ext/app/threads/${thread.id}/chat`, {
363363
...options,
364364
body: typeof request == 'string'
@@ -381,6 +381,12 @@ async function loadThreadDetails(id, opt = null) {
381381
return threadDetails.value[id]
382382
}
383383

384+
function getCurrentThreadSystemPrompt() {
385+
return currentThread.value?.systemPrompt
386+
?? currentThread.value?.messages?.find(m => m.role == 'system')?.content
387+
?? ''
388+
}
389+
384390
// Export the store
385391
export function useThreadStore() {
386392
return {
@@ -391,6 +397,7 @@ export function useThreadStore() {
391397
groupedThreads,
392398

393399
// Actions
400+
getCurrentThreadSystemPrompt,
394401
query,
395402
createThread,
396403
updateThread,

llms/extensions/system_prompts/ui/index.mjs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const SystemPromptEditor = {
163163
</div>
164164
</div>
165165
<div v-if="hasMessages" class="w-full rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 px-3 py-2 text-sm">
166-
{{$threads.currentThread.value?.systemPrompt || 'No System Prompt was used' }}
166+
<TextViewer prefsName="systemPrompt" :text="$threads.getCurrentThreadSystemPrompt() || 'No System Prompt was used'" />
167167
</div>
168168
<div v-else>
169169
<textarea
@@ -251,21 +251,17 @@ export default {
251251
}
252252
})
253253

254-
ctx.chatRequestFilters.push(({ request, thread }) => {
254+
ctx.chatRequestFilters.push(({ request, thread, context }) => {
255255

256-
const hasSystemPrompt = request.messages.find(x => x.role === 'system')
256+
const hasSystemPrompt = !!context.systemPrompt
257+
console.log('system_prompts chatRequestFilters', hasSystemPrompt)
257258
if (hasSystemPrompt) {
258259
console.log('Already has system prompt', hasSystemPrompt.content)
259260
return
260261
}
261262

262-
// Only add the selected system prompt for new requests
263-
if (ext.prefs.systemPrompt && request.messages.length <= 1) {
264-
// add message to start
265-
request.messages.unshift({
266-
role: 'system',
267-
content: ext.prefs.systemPrompt
268-
})
263+
if (ext.prefs.systemPrompt) {
264+
context.systemPrompt = ext.prefs.systemPrompt
269265
}
270266
})
271267

llms/extensions/tools/ui/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ export default {
656656
}
657657
})
658658

659-
ctx.chatRequestFilters.push(({ request, thread }) => {
659+
ctx.chatRequestFilters.push(({ request, thread, context }) => {
660660
// Tool Preferences
661661
const prefs = ctx.prefs
662662
if (prefs.onlyTools != null) {

0 commit comments

Comments
 (0)