Skip to content

Commit

Permalink
Improvements and fixes (#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
sceuick authored Jan 5, 2024
1 parent 14624ae commit b4bf5f4
Show file tree
Hide file tree
Showing 52 changed files with 1,254 additions and 636 deletions.
6 changes: 5 additions & 1 deletion common/guidance/guidance-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export async function runGuidance<T extends Record<string, string> = Record<stri
let values: any = {}
const previous: any = opts.previous || {}

const reruns = new Set(opts.reguidance || [])

const done = new Set<string>()

for (const node of nodes) {
Expand Down Expand Up @@ -92,8 +94,10 @@ export async function runGuidance<T extends Record<string, string> = Record<stri
prompt += value
values[name] = value

reruns.delete(name)

/** If all re-guidance values have been fulfilled, return */
if (opts.reguidance && done.size === opts.reguidance.length) {
if (opts.reguidance && reruns.size === 0) {
break
}

Expand Down
15 changes: 13 additions & 2 deletions common/guidance/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const parser = peggy.generate(grammar.trim(), {
* This cannot be used for guidance yet
*/

export function parseTemplateV2(template: string): GuidanceNode[] {
export function parseTemplateV2(template: string) {
const ast = parser.parse(template, {}) as GuidanceNode[]

for (const node of ast) {
Expand All @@ -48,5 +48,16 @@ export function parseTemplateV2(template: string): GuidanceNode[] {
}
}
}
return ast

const placeholders: string[] = []

const matches = template.match(/{{[a-zA-Z0-9_-]+}}/g)
if (!matches) return { ast, placeholders }

for (const match of matches) {
const name = match.replace(/({|}| )/g, '')
placeholders.push(name)
}

return { ast, placeholders }
}
338 changes: 169 additions & 169 deletions common/presets/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,180 +84,180 @@ export function replaceTags(prompt: string, format: FormatTags | ModelFormat) {

export const templates = {
Universal: neat`
{{#if system_prompt}}<system>{{system_prompt}}</system>
{{/if}}
Below is an instruction that describes a task. Write a response that appropriately completes the request.
Write {{char}}'s next reply in a fictional roleplay chat between {{#each bot}}{{.name}}, {{/each}}{{char}}.
{{char}}'s Persona:
{{personality}}
{{#if memory}}{{char}}'s Memory:
{{memory}}
{{/if}}
{{#if user_embed}}Relevant information to the conversation
{{user_embed}}
{{/if}}
{{#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}}
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>
{{ujb}}</bot>
{{/if}}
<bot>{{post}}`,
{{#if system_prompt}}<system>{{system_prompt}}</system>
{{/if}}
Below is an instruction that describes a task. Write a response that appropriately completes the request.
Write {{char}}'s next reply in a fictional roleplay chat between {{#each bot}}{{.name}}, {{/each}}{{char}}.
{{char}}'s Persona:
{{personality}}
{{#if memory}}{{char}}'s Memory:
{{memory}}
{{/if}}
{{#if user_embed}}Relevant information to the conversation
{{user_embed}}
{{/if}}
{{#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}}
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>
{{ujb}}</bot>
{{/if}}
<bot>{{post}}`,
Alpaca: neat`
{{#if system_prompt}}{{system_prompt}}
{{/if}}
Below is an instruction that describes a task. Write a response that appropriately completes the request.
Write {{char}}'s next reply in a fictional roleplay chat between {{#each bot}}{{.name}}, {{/each}}{{char}}.
{{char}}'s Persona:
{{personality}}
{{#if memory}}{{char}}'s Memory:
{{memory}}
{{/if}}
{{#if user_embed}}Relevant information to the conversation
{{user_embed}}
{{/if}}
{{#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}}
***
{{#each msg}}{{#if .isbot}}### Response:\n{{.name}}: {{.msg}}{{/if}}{{#if .isuser}}### Instruction:\n{{.name}}: {{.msg}}{{/if}}
{{/each}}
{{#if ujb}}### Instruction:
{{ujb}}
{{/if}}
### Response:
{{#if system_prompt}}{{system_prompt}}
{{/if}}
Below is an instruction that describes a task. Write a response that appropriately completes the request.
Write {{char}}'s next reply in a fictional roleplay chat between {{#each bot}}{{.name}}, {{/each}}{{char}}.
{{char}}'s Persona:
{{personality}}
{{#if memory}}{{char}}'s Memory:
{{memory}}
{{/if}}
{{#if user_embed}}Relevant information to the conversation
{{user_embed}}
{{/if}}
{{#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}}
***
{{#each msg}}{{#if .isbot}}### Response:\n{{.name}}: {{.msg}}{{/if}}{{#if .isuser}}### Instruction:\n{{.name}}: {{.msg}}{{/if}}
{{/each}}
{{#if ujb}}### Instruction:
{{ujb}}
{{/if}}
### Response:
{{post}}`,
Vicuna: neat`
{{#if system_prompt}}{{system_prompt}}
{{/if}}
Below is an instruction that describes a task. Write a response that appropriately completes the request.
Write {{char}}'s next reply in a fictional roleplay chat between {{#each bot}}{{.name}}, {{/each}}{{char}}.
{{char}}'s Persona:
{{personality}}
{{#if memory}}{{char}}'s Memories:
{{memory}}
{{/if}}
{{#if scenario}}This scenario of the conversation:
{{scenario}}
{{/if}}
{{#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}}
{{/if}}
ASSISTANT:\n{{post}}`,
{{#if system_prompt}}{{system_prompt}}
{{/if}}
Below is an instruction that describes a task. Write a response that appropriately completes the request.
Write {{char}}'s next reply in a fictional roleplay chat between {{#each bot}}{{.name}}, {{/each}}{{char}}.
{{char}}'s Persona:
{{personality}}
{{#if memory}}{{char}}'s Memories:
{{memory}}
{{/if}}
{{#if scenario}}This scenario of the conversation:
{{scenario}}
{{/if}}
{{#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}}
{{/if}}
ASSISTANT:\n{{post}}`,
NovelAI: neat`
{{#if system_prompt}}{{system_prompt}}
{{/if}}
{{#if memory}}{{char}}'s Memory:
{{memory}}{{/if}}
Description of {{char}}:
{{personality}}
How {{char}} speaks:
{{example_dialogue}}
[ Title: Dialogue between {{char}} and {{user}}; Tags: conversation; Genre: online roleplay ]
***
Summary: {{scenario}}
{{history}}
{{ujb}}
{{#if system_prompt}}{{system_prompt}}
{{/if}}
{{#if memory}}{{char}}'s Memory:
{{memory}}{{/if}}
Description of {{char}}:
{{personality}}
How {{char}} speaks:
{{example_dialogue}}
[ Title: Dialogue between {{char}} and {{user}}; Tags: conversation; Genre: online roleplay ]
***
Summary: {{scenario}}
{{history}}
{{ujb}}
{{post}}`,
Pyg: neat`{{char}}'s Persona:
{{personality}}
{{#if scenario}}Scenario: {{scenario}}
{{/if}}
{{#if memory}}Facts:{{memory}}
{{/if}}
{{#if example_dialogue}}How {{char}} speaks: {{example_dialogue}}
{{/if}}
<START>
{{history}}
{{#if ujb}}{{ujb}
{{/if}}
{{post}}
`,
Pyg: neat`
{{char}}'s Persona:
{{personality}}
{{#if scenario}}Scenario: {{scenario}}
{{/if}}
{{#if memory}}Facts:{{memory}}
{{/if}}
{{#if example_dialogue}}How {{char}} speaks: {{example_dialogue}}
{{/if}}
<START>
{{history}}
{{#if ujb}}{{ujb}
{{/if}}
{{post}}`,
Metharme: neat`
{{#if system_prompt}}{{system_prompt}}{{/if}}
Below is an instruction that describes a task. Write a response that appropriately completes the request.
Write {{char}}'s next reply in a fictional roleplay chat between {{#each bot}}{{.name}}, {{/each}}{{char}}.
{{char}}'s Persona:
{{personality}}
{{#if memory}}{{char}}'s Memory:
{{memory}}
{{/if}}
{{#if scenario}}This scenario of the conversation:
{{scenario}}
{{/if}}
{{#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}}
{{/if}}
<|model|>{{post}}`,
{{#if system_prompt}}{{system_prompt}}{{/if}}
Below is an instruction that describes a task. Write a response that appropriately completes the request.
Write {{char}}'s next reply in a fictional roleplay chat between {{#each bot}}{{.name}}, {{/each}}{{char}}.
{{char}}'s Persona:
{{personality}}
{{#if memory}}{{char}}'s Memory:
{{memory}}
{{/if}}
{{#if scenario}}This scenario of the conversation:
{{scenario}}
{{/if}}
{{#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}}
{{/if}}
<|model|>{{post}}`,
ChatML: neat`
{{#if system_prompt}}<|im_start|>system
{{system_prompt}}<|im_end|>{{/if}}
<|im_start|>system
Below is an instruction that describes a task. Write a response that appropriately completes the request.<|im_end|>
<|im_start|>system
Write {{char}}'s next reply in a fictional roleplay chat between {{#each bot}}{{.name}}, {{/each}}{{char}}.
{{char}}'s Persona:
{{personality}}
{{#if memory}}{{char}}'s Memory: {{memory}}
{{/if}}
{{#if scenario}}This scenario of the conversation: {{scenario}}
{{/if}}
{{#if example_dialogue}}This is how {{char}} should talk: {{example_dialogue}}
{{/if}}
Then the roleplay chat between {{#each bot}}{{.name}}, {{/each}}{{char}} begins.<|im_end|>
{{#each msg}}{{#if .isbot}}<|im_start|>assistant{{/if}}{{#if .isuser}}<|im_start|>user{{/if}}
{{.name}}: {{.msg}}<|im_end|>
{{/each}}
{{#if ujb}}<|im_start|>system
{{ujb}}<|im_end|>
{{/if}}
<|im_start|>assistant
{{post}}`,
{{#if system_prompt}}<|im_start|>system
{{system_prompt}}<|im_end|>{{/if}}
<|im_start|>system
Below is an instruction that describes a task. Write a response that appropriately completes the request.<|im_end|>
<|im_start|>system
Write {{char}}'s next reply in a fictional roleplay chat between {{#each bot}}{{.name}}, {{/each}}{{char}}.
{{char}}'s Persona:
{{personality}}
{{#if memory}}{{char}}'s Memory: {{memory}}
{{/if}}
{{#if scenario}}This scenario of the conversation: {{scenario}}
{{/if}}
{{#if example_dialogue}}This is how {{char}} should talk: {{example_dialogue}}
{{/if}}
Then the roleplay chat between {{#each bot}}{{.name}}, {{/each}}{{char}} begins.<|im_end|>
{{#each msg}}{{#if .isbot}}<|im_start|>assistant{{/if}}{{#if .isuser}}<|im_start|>user{{/if}}
{{.name}}: {{.msg}}<|im_end|>
{{/each}}
{{#if ujb}}<|im_start|>system
{{ujb}}<|im_end|>
{{/if}}
<|im_start|>assistant
{{post}}`,
}
Loading

0 comments on commit b4bf5f4

Please sign in to comment.