diff --git a/aidialog/dialog.py b/aidialog/dialog.py index 7811fba..f809dba 100644 --- a/aidialog/dialog.py +++ b/aidialog/dialog.py @@ -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): diff --git a/nbs/01_dialog.ipynb b/nbs/01_dialog.ipynb index eea4e84..566f4b6 100644 --- a/nbs/01_dialog.ipynb +++ b/nbs/01_dialog.ipynb @@ -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", @@ -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." ] }, { @@ -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')" ] }, {