Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aidialog/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def ai_res(self):
if self.msg_type != sprompt: return ''
if isinstance(self.output, str): return self.output # Handle legacy/direct string
if res := first(L(self.output).filter(lambda x: nested_idx(x, 'metadata', 'is_ai_res'))):
return nested_idx(res, 'data', 'text/markdown') or ''
return join_out(nested_idx(res, 'data', 'text/markdown')) or ''
return ''

def __deepcopy__(self, memo):
Expand Down
8 changes: 5 additions & 3 deletions nbs/01_dialog.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
" if self.msg_type != sprompt: return ''\n",
" if isinstance(self.output, str): return self.output # Handle legacy/direct string\n",
" if res := first(L(self.output).filter(lambda x: nested_idx(x, 'metadata', 'is_ai_res'))):\n",
" return nested_idx(res, 'data', 'text/markdown') or ''\n",
" return join_out(nested_idx(res, 'data', 'text/markdown')) or ''\n",
" return ''\n",
"\n",
" def __deepcopy__(self, memo):\n",
Expand Down Expand Up @@ -488,7 +488,7 @@
"id": "018a4289",
"metadata": {},
"source": [
"Prompt outputs normalize on the way in: a string assigned to a prompt message's `output`, at construction or any time later, wraps through `prompt_output`, so `ai_res` and history rendering always see the one list format."
"Prompt outputs normalize in both directions. A string assigned to `Message.output` wraps through `prompt_output`. An ipynb MIME value can be a string or a list of lines. `ai_res` joins either form into one string for history rendering."
]
},
{
Expand All @@ -502,7 +502,9 @@
"test_eq(pm.ai_res, 'A reply')\n",
"pm.output = 'Edited reply'\n",
"test_eq(pm.output, prompt_output('Edited reply'))\n",
"test_eq(pm.ai_res, 'Edited reply')"
"test_eq(pm.ai_res, 'Edited reply')\n",
"pm_lines = Message('q', msg_type=sprompt, output=prompt_output(['Line 1\\n', 'Line 2']))\n",
"test_eq(pm_lines.ai_res, 'Line 1\\nLine 2')"
]
},
{
Expand Down