Update app.py
Browse files
app.py
CHANGED
|
@@ -28,31 +28,21 @@ def convert_history_to_openai_format(history):
|
|
| 28 |
list of dict: The formatted history for OpenAI with "role" as either "user" or "assistant".
|
| 29 |
"""
|
| 30 |
global global_system_prompt
|
| 31 |
-
if global_system_prompt
|
| 32 |
global_system_prompt = "You are a helpful assistant."
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
encoded_image = encode_image(user_msg[0])
|
| 43 |
-
text = 'Help me based on the image'
|
| 44 |
-
if user_msg[1] != '':
|
| 45 |
-
text = user_msg[1]
|
| 46 |
-
content = [{'type':'text', 'text':text}, {'type':'image_url', 'image_url':{'url':f'data:image/jpeg;base64,{encoded_image}'}}]
|
| 47 |
-
formatted_history.append({"role": 'user', "content": content})
|
| 48 |
-
else:
|
| 49 |
-
formatted_history.append({"role": 'user', "content": user_msg})
|
| 50 |
-
|
| 51 |
-
if isinstance(assistant_msg, str):
|
| 52 |
-
formatted_history.append({"role": 'assistant', "content": assistant_msg})
|
| 53 |
else:
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 56 |
return formatted_history
|
| 57 |
|
| 58 |
def bot(history):
|
|
|
|
| 28 |
list of dict: The formatted history for OpenAI with "role" as either "user" or "assistant".
|
| 29 |
"""
|
| 30 |
global global_system_prompt
|
| 31 |
+
if global_system_prompt == None:
|
| 32 |
global_system_prompt = "You are a helpful assistant."
|
| 33 |
+
formatted_history = [{"role": "system", "content": global_system_prompt},]
|
| 34 |
+
for user_msg, assistant_msg in history:
|
| 35 |
+
if ('.png' in user_msg[0]) or ('.jpg' in user_msg[0]):
|
| 36 |
+
encoded_image = encode_image(user_msg[0])
|
| 37 |
+
text = 'help me based on the image'
|
| 38 |
+
if user_msg[1] != '':
|
| 39 |
+
text = user_msg[1]
|
| 40 |
+
content = [{'type':'text', 'text':text},{'type':'image_url','image_url':{'url':f'data:image/jpeg;base64,{encoded_image}'}}]
|
| 41 |
+
formatted_history.append({"role": 'user', "content": content})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
else:
|
| 43 |
+
formatted_history.append({"role": 'user', "content": user_msg})
|
| 44 |
+
if isinstance(assistant_msg,str):
|
| 45 |
+
formatted_history.append({"role": 'assistant', "content": assistant_msg})
|
| 46 |
return formatted_history
|
| 47 |
|
| 48 |
def bot(history):
|