Update OpenAI API to support text in mixed-mode data
This commit is contained in:
parent
8da46278e1
commit
167f9b20fc
1 changed files with 14 additions and 4 deletions
|
@ -32,6 +32,15 @@ def is_present(json, key):
|
|||
return False
|
||||
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
|
||||
def convert_chat(messages):
|
||||
prompt = "" + args.chat_prompt.replace("\\n", "\n")
|
||||
|
@ -44,11 +53,11 @@ def convert_chat(messages):
|
|||
|
||||
for line in messages:
|
||||
if (line["role"] == "system"):
|
||||
prompt += f"{system_n}{line['content']}"
|
||||
prompt += f"{system_n}{extract_content_text(line['content'])}"
|
||||
if (line["role"] == "user"):
|
||||
prompt += f"{user_n}{line['content']}"
|
||||
prompt += f"{user_n}{extract_content_text(line['content'])}"
|
||||
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()
|
||||
|
||||
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"]
|
||||
if (chat):
|
||||
if (start):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue