Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
18db0e6
1
Parent(s):
b0883d9
Add logging for message history and improve question formatting in Conversation class
Browse files- app.py +1 -0
- conversation.py +6 -3
app.py
CHANGED
@@ -214,6 +214,7 @@ def predict(message,
|
|
214 |
if first_user_message is not None and \
|
215 |
DEFAULT_IMAGE_TOKEN not in first_user_message:
|
216 |
state.update_message(state.USER, DEFAULT_IMAGE_TOKEN + "\n" + first_user_message, None, index)
|
|
|
217 |
|
218 |
history = state.get_history()
|
219 |
logger.info(f"==== History ====\n{history}")
|
|
|
214 |
if first_user_message is not None and \
|
215 |
DEFAULT_IMAGE_TOKEN not in first_user_message:
|
216 |
state.update_message(state.USER, DEFAULT_IMAGE_TOKEN + "\n" + first_user_message, None, index)
|
217 |
+
|
218 |
|
219 |
history = state.get_history()
|
220 |
logger.info(f"==== History ====\n{history}")
|
conversation.py
CHANGED
@@ -10,7 +10,8 @@ from typing import Any, List, Dict, Union
|
|
10 |
from dataclasses import field
|
11 |
|
12 |
from utils import LOGDIR
|
13 |
-
|
|
|
14 |
|
15 |
def pil2base64(img: Image.Image) -> str:
|
16 |
buffered = BytesIO()
|
@@ -140,6 +141,8 @@ class Conversation:
|
|
140 |
system_message = self.system_message
|
141 |
messages = self.messages[:-1]
|
142 |
|
|
|
|
|
143 |
for i in range(len(messages)):
|
144 |
if messages[i]['role'] == 'user':
|
145 |
# Create the question by combining system and user messages
|
@@ -147,8 +150,8 @@ class Conversation:
|
|
147 |
|
148 |
# Check if it's the first user message and contains <image>
|
149 |
if i == 0 and '<image>' in user_content:
|
150 |
-
question = f"<image
|
151 |
-
elif i == 0 and '<
|
152 |
question = f"{system_message}\n{user_content}"
|
153 |
else:
|
154 |
question = f"{user_content}"
|
|
|
10 |
from dataclasses import field
|
11 |
|
12 |
from utils import LOGDIR
|
13 |
+
import logging
|
14 |
+
logger = logging.getLogger(__name__)
|
15 |
|
16 |
def pil2base64(img: Image.Image) -> str:
|
17 |
buffered = BytesIO()
|
|
|
141 |
system_message = self.system_message
|
142 |
messages = self.messages[:-1]
|
143 |
|
144 |
+
logger.info(f"=== Raw messages ===\n{messages}")
|
145 |
+
|
146 |
for i in range(len(messages)):
|
147 |
if messages[i]['role'] == 'user':
|
148 |
# Create the question by combining system and user messages
|
|
|
150 |
|
151 |
# Check if it's the first user message and contains <image>
|
152 |
if i == 0 and '<image>' in user_content:
|
153 |
+
question = f"<image>\n{system_message}\n{user_content}"
|
154 |
+
elif i == 0 and '<image>' not in user_content:
|
155 |
question = f"{system_message}\n{user_content}"
|
156 |
else:
|
157 |
question = f"{user_content}"
|