Skip to content

Commit 194b7ac

Browse files
committed
maintain state per thread
1 parent b29bf9c commit 194b7ac

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

AiServer/wwwroot/mjs/components/PromptGenerator.mjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ActiveAiModels, QueryPrompts, OpenAiChatCompletion } from "dtos"
66
export default {
77
template:`
88
<div v-if="system">
9-
<button @click="prefs.show=!prefs.show" type="button" class="-ml-3 bg-white text-gray-600 hover:text-gray-900 group w-full flex items-center pr-2 py-2 text-left text-sm font-medium">
9+
<button @click="toggleShow()" type="button" class="-ml-3 bg-white text-gray-600 hover:text-gray-900 group w-full flex items-center pr-2 py-2 text-left text-sm font-medium">
1010
<svg v-if="prefs.show" class="text-gray-400 rotate-90 mr-0.5 flex-shrink-0 h-5 w-5 transform group-hover:text-gray-400 transition-colors ease-in-out duration-150" viewBox="0 0 20 20" aria-hidden="true"><path d="M6 6L14 10L6 14V6Z" fill="currentColor"></path></svg>
1111
<svg v-else class="text-gray-300 mr-0.5 flex-shrink-0 h-5 w-5 transform group-hover:text-gray-400 transition-colors ease-in-out duration-150" viewBox="0 0 20 20" aria-hidden="true"><path d="M6 6L14 10L6 14V6Z" fill="currentColor"></path></svg>
1212
AI Prompt Generator
@@ -71,9 +71,13 @@ export default {
7171

7272
watch(() => props.thread, () => {
7373
Object.assign(prefs.value, defaults, props.thread?.generator)
74-
console.log('watch', prefs.value)
7574
})
7675

76+
function toggleShow() {
77+
prefs.value.show = !prefs.value.show
78+
savePrefs()
79+
}
80+
7781
function savePrefs() {
7882
if (props.thread) props.thread.generator = prefs
7983
emit('save', prefs)
@@ -140,6 +144,6 @@ export default {
140144
}
141145
}
142146

143-
return { client, system, request, prefs, models, error, validPrompt, send }
147+
return { client, system, request, prefs, models, error, validPrompt, toggleShow, send }
144148
}
145149
}

AiServer/wwwroot/mjs/components/TextToImage.mjs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,13 @@ export default {
133133
const waitingOnResponse = ref(false)
134134
const storage = new ThreadStorage(`img2txt`, {
135135
model: 'jib-mix-realistic',
136+
positivePrompt: "",
136137
negativePrompt: '(nsfw),(explicit),(gore),(violence),(blood)',
137138
width: 1024,
138139
height: 1024,
139140
batchSize: 1,
141+
seed: '',
142+
tag: '',
140143
})
141144
const error = ref()
142145

@@ -165,6 +168,7 @@ export default {
165168
storage.saveHistory(history.value)
166169
}
167170
function saveThread() {
171+
console.log('saveThread', thread.value)
168172
if (thread.value) {
169173
storage.saveThread(thread.value)
170174
}
@@ -279,15 +283,14 @@ export default {
279283
const id = parseInt(routes.id)
280284
thread.value = storage.getThread(storage.getThreadId(id))
281285
threadRef.value = history.value.find(x => x.id === parseInt(routes.id))
282-
// console.log('thread', id, thread.value)
283-
// console.log('threadRef', threadRef.value)
286+
Object.keys(storage.defaults).forEach(field =>
287+
request.value[field] = thread.value[field] ?? storage.defaults[field])
284288
} else {
285289
thread.value = null
286290
}
287291
}
288292

289293
function updated() {
290-
// console.debug('updated', routes.admin, routes.id)
291294
onRouteChange()
292295
}
293296

@@ -313,6 +316,20 @@ export default {
313316
}
314317

315318
watch(() => routes.id, updated)
319+
watch(() => [
320+
request.value.model,
321+
request.value.positivePrompt,
322+
request.value.negativePrompt,
323+
request.value.width,
324+
request.value.height,
325+
request.value.batchSize,
326+
request.value.seed,
327+
request.value.tag,
328+
], () => {
329+
Object.keys(storage.defaults).forEach(field =>
330+
thread.value[field] = request.value[field] ?? storage.defaults[field])
331+
saveThread()
332+
})
316333

317334
onMounted(async () => {
318335
const api = await client.api(new ActiveMediaModels())

0 commit comments

Comments
 (0)