UI: Add a new "User description" field for user personality/biography (#5691)

This commit is contained in:
oobabooga 2024-03-11 23:41:57 -03:00 committed by GitHub
parent 63701f59cf
commit 28076928ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 62 additions and 43 deletions

View file

@ -86,10 +86,16 @@ def generate_chat_prompt(user_input, state, **kwargs):
if state['mode'] != 'instruct':
chat_template_str = replace_character_names(chat_template_str, state['name1'], state['name2'])
chat_template = jinja_env.from_string(chat_template_str)
instruction_template = jinja_env.from_string(state['instruction_template_str'])
chat_renderer = partial(chat_template.render, add_generation_prompt=False, name1=state['name1'], name2=state['name2'])
instruct_renderer = partial(instruction_template.render, add_generation_prompt=False)
chat_template = jinja_env.from_string(chat_template_str)
chat_renderer = partial(
chat_template.render,
add_generation_prompt=False,
name1=state['name1'],
name2=state['name2'],
user_bio=replace_character_names(state['user_bio'], state['name1'], state['name2']),
)
messages = []
@ -99,7 +105,7 @@ def generate_chat_prompt(user_input, state, **kwargs):
messages.append({"role": "system", "content": state['custom_system_message']})
else:
renderer = chat_renderer
if state['context'].strip() != '':
if state['context'].strip() != '' or state['user_bio'].strip() != '':
context = replace_character_names(state['context'], state['name1'], state['name2'])
messages.append({"role": "system", "content": context})
@ -140,6 +146,7 @@ def generate_chat_prompt(user_input, state, **kwargs):
command = state['chat-instruct_command']
command = command.replace('<|character|>', state['name2'] if not impersonate else state['name1'])
command = command.replace('<|prompt|>', prompt)
command = replace_character_names(command, state['name1'], state['name2'])
if _continue:
prefix = get_generation_prompt(renderer, impersonate=impersonate, strip_trailing_spaces=False)[0]