Skip to content

Commit

Permalink
Tweak universal prompt and fix prompt preview (#790) [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
sceuick authored Jan 2, 2024
1 parent 68f9296 commit 14624ae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
14 changes: 9 additions & 5 deletions common/presets/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,18 @@ export const templates = {
{{#if user_embed}}Relevant information to the conversation
{{user_embed}}
{{/if}}
{{#if scenario}}The scenario of the conversation: {{scenario}}
{{#if scenario}}The scenario of the conversation:
{{scenario}}
{{/if}}
{{#if chat_embed}}Relevant past conversation history
{{chat_embed}}
{{/if}}
{{#if example_dialogue}}This is how {{char}} should talk: {{example_dialogue}}
{{#if example_dialogue}}This is how {{char}} should talk:
{{example_dialogue}}
{{/if}}
***
Then the roleplay chat between {{char}} and {{user}} begins.
{{#each msg}}{{#if .isbot}}<bot>{{.name}}: {{.msg}}</bot>{{/if}}{{#if .isuser}}<user>{{.name}}: {{.msg}}</user>{{/if}}
{{/each}}
{{#if ujb}}<bot>
Expand Down Expand Up @@ -163,7 +167,7 @@ export const templates = {
{{#if example_dialogue}}This is how {{char}} should talk:
{{example_dialogue}}
{{/if}}
***
{{#each msg}}{{#if .isbot}}ASSISTANT:\n{{.name}}: {{.msg}}{{/if}}{{#if .isuser}}USER:\n{{.name}}: {{.msg}}{{/if}}
{{/each}}
{{#if ujb}}SYSTEM:{{ujb}}
Expand Down Expand Up @@ -221,7 +225,7 @@ export const templates = {
{{#if example_dialogue}}This is how {{char}} should talk:
{{example_dialogue}}
{{/if}}
***
{{#each msg}}{{#if .isbot}}<|model|>{{/if}}{{#if .isuser}}<|user|>{{/if}}{{.name}}: {{.msg}}
{{/each}}
{{#if ujb}}<|system|>{{ujb}}
Expand Down
28 changes: 23 additions & 5 deletions web/shared/PromptEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { toBotMsg, toChar, toChat, toPersona, toProfile, toUser, toUserMsg } fro
import { ensureValidTemplate, buildPromptParts } from '/common/prompt'
import { AppSchema } from '/common/types/schema'
import { v4 } from 'uuid'
import { isDefaultTemplate } from '../../../common/presets/templates'
import { isDefaultTemplate, replaceTags } from '../../../common/presets/templates'
import Select from '../Select'
import TextInput from '../TextInput'
import { presetStore } from '/web/store'
Expand Down Expand Up @@ -185,12 +185,30 @@ const PromptEditor: Component<
return template?.name || ''
})

createEffect(async () => {
const togglePreview = async () => {
const opts = await getExampleOpts(props.inherit)
const template = props.noDummyPreview ? input() : ensureValidTemplate(input(), opts.parts)
const { parsed } = await parseTemplate(template, opts)
let { parsed } = await parseTemplate(template, opts)

if (props.inherit?.modelFormat) {
parsed = replaceTags(parsed, props.inherit.modelFormat)
}

setRendered(parsed)
})
setPreview(!preview())
}

// createEffect(async () => {
// const opts = await getExampleOpts(props.inherit)
// const template = props.noDummyPreview ? input() : ensureValidTemplate(input(), opts.parts)
// let { parsed } = await parseTemplate(template, opts)

// if (props.inherit?.modelFormat) {
// parsed = replaceTags(parsed, props.inherit.modelFormat)
// }

// setRendered(parsed)
// })

const onChange = (ev: Event & { currentTarget: HTMLTextAreaElement }) => {
setInput(ev.currentTarget.value)
Expand Down Expand Up @@ -274,7 +292,7 @@ const PromptEditor: Component<
</div>
</div>
<div class="flex gap-2">
<Button size="sm" onClick={() => setPreview(!preview())}>
<Button size="sm" onClick={togglePreview}>
Toggle Preview
</Button>
<Show when={props.showTemplates}>
Expand Down

0 comments on commit 14624ae

Please sign in to comment.