Merge 167f9b20fc
into 1f5cd83275
This commit is contained in:
commit
04f199e512
1 changed files with 14 additions and 4 deletions
|
@ -32,6 +32,15 @@ def is_present(json, key):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def extract_content_text(content):
|
||||||
|
if isinstance(content, str):
|
||||||
|
return content
|
||||||
|
if isinstance(content, list):
|
||||||
|
return ''.join(extract_content_text(item) for item in content)
|
||||||
|
else:
|
||||||
|
return content['text']
|
||||||
|
|
||||||
#convert chat to prompt
|
#convert chat to prompt
|
||||||
def convert_chat(messages):
|
def convert_chat(messages):
|
||||||
prompt = "" + args.chat_prompt.replace("\\n", "\n")
|
prompt = "" + args.chat_prompt.replace("\\n", "\n")
|
||||||
|
@ -44,11 +53,11 @@ def convert_chat(messages):
|
||||||
|
|
||||||
for line in messages:
|
for line in messages:
|
||||||
if (line["role"] == "system"):
|
if (line["role"] == "system"):
|
||||||
prompt += f"{system_n}{line['content']}"
|
prompt += f"{system_n}{extract_content_text(line['content'])}"
|
||||||
if (line["role"] == "user"):
|
if (line["role"] == "user"):
|
||||||
prompt += f"{user_n}{line['content']}"
|
prompt += f"{user_n}{extract_content_text(line['content'])}"
|
||||||
if (line["role"] == "assistant"):
|
if (line["role"] == "assistant"):
|
||||||
prompt += f"{ai_n}{line['content']}{stop}"
|
prompt += f"{ai_n}{extract_content_text(line['content'])}{stop}"
|
||||||
prompt += ai_n.rstrip()
|
prompt += ai_n.rstrip()
|
||||||
|
|
||||||
return prompt
|
return prompt
|
||||||
|
@ -130,6 +139,7 @@ def make_resData_stream(data, chat=False, time_now = 0, start=False):
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
if "slot_id" in data:
|
||||||
slot_id = data["slot_id"]
|
slot_id = data["slot_id"]
|
||||||
if (chat):
|
if (chat):
|
||||||
if (start):
|
if (start):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue