|
7 | 7 |
|
8 | 8 | from botbuilder.core import TurnContext
|
9 | 9 |
|
10 |
| -from ...state import Memory |
11 |
| -from ..tokenizers import Tokenizer |
12 |
| -from ..utilities import to_string |
13 |
| -from .message import Message |
14 |
| -from .prompt_functions import PromptFunctions |
| 10 | +from ....state import Memory |
| 11 | +from ...tokenizers import Tokenizer |
| 12 | +from ...utilities import to_string |
| 13 | +from ..message import Message |
| 14 | +from ..prompt_functions import PromptFunctions |
| 15 | +from ..rendered_prompt_section import RenderedPromptSection |
15 | 16 | from .prompt_section_base import PromptSectionBase
|
16 |
| -from .rendered_prompt_section import RenderedPromptSection |
17 | 17 |
|
18 | 18 |
|
19 |
| -class ConversationHistory(PromptSectionBase): |
| 19 | +class ConversationHistorySection(PromptSectionBase): |
20 | 20 | """
|
21 | 21 | A section that renders the conversation history.
|
22 | 22 | """
|
@@ -109,7 +109,7 @@ async def render_as_text(
|
109 | 109 | for msg in reversed(history):
|
110 | 110 | msg = Message(role=msg.role, content=to_string(tokenizer, msg.content))
|
111 | 111 | prefix = self.user_prefix if msg.role == "user" else self.assistant_prefix
|
112 |
| - line = prefix + msg.content |
| 112 | + line = prefix + (msg.content if msg.content is not None else "") |
113 | 113 | length = len(tokenizer.encode(line)) + (separator_length if len(lines) > 0 else 0)
|
114 | 114 |
|
115 | 115 | # Add initial line if required
|
@@ -169,7 +169,13 @@ async def render_as_messages(
|
169 | 169 |
|
170 | 170 | # Add length of any image parts
|
171 | 171 | if isinstance(message.content, list):
|
172 |
| - length += sum(1 for part in message.content if part.type == "image") * 85 |
| 172 | + count = 0 |
| 173 | + |
| 174 | + for part in message.content: |
| 175 | + if not isinstance(part, str) and part.type == "image": |
| 176 | + count += 1 |
| 177 | + |
| 178 | + length += count * 85 |
173 | 179 |
|
174 | 180 | # Add initial message if required
|
175 | 181 | if len(messages) == 0 and self.required:
|
|
0 commit comments