Skip to content

Fix find_msg by enusring ai_res always return str or None - #45

Merged
jph00 merged 1 commit into
mainfrom
fix-ai-res-list-output
Aug 30, 2026
Merged

Fix find_msg by enusring ai_res always return str or None#45
jph00 merged 1 commit into
mainfrom
fix-ai-res-list-output

Conversation

@PiotrCzapla

@PiotrCzapla PiotrCzapla commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

If I understand correctly, prompt now looks like this;

res = {
    'output_type': 'display_data',
    'metadata': {'is_ai_res': True},
    'data': {
        'text/markdown': ['Line 1\n', 'Line 2']
    }
}

Then nested_idx(res, 'data', 'text/markdown') returns a list: ['Line 1\n', 'Line 2']
that needs joining. Using: join_out as it accept also moments where nested_idx returns a string.

Here is the error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[27], line 1
----> 1 await sync_updates('mini-updates')

Cell In[24], line 4, in sync_updates(ch, dname, limit)
      1 async def sync_updates(ch, dname='', limit=500):
      2     "Add new Discord msgs from channel `ch` (name, url, or obj) into the dialog"
      3     ch = await to_channel(ch)
----> 4     synced = await find_msgs(r':::\{#sf(\d+)', dname=dname)
      5     synced_by_id = {sfid: msg for msg in synced
      6                     for sfid in re.findall(r':::\{#sf(\d+)', msg['content'])}
      7     msgs, before = [], None

File ~/aai-ws/fastaudit/fastaudit/core.py:64, in CallTracker.wrap.<locals>._fn(*args, **kwargs)
     62 @wraps(fn)
     63 async def _fn(*args, **kwargs):
---> 64     with self.track(fn, args, kwargs): return await fn(*args, **kwargs)

File ~/aai-ws/dialoghelper/dialoghelper/core.py:543, in find_msgs(re_pattern, msg_type, before, after, context, use_case, use_regex, only_err, only_exp, ids, limit, include_output, include_meta, as_xml, nums, trunc_out, trunc_in, headers_only, header_section, include_skipped, dname)
    541 d = _cells2dlg(await cells_client(dname).cells(), name=find_dname(dname, required=False) or '-')
    542 ms = [m for m in d.messages if include_skipped or not m.skipped]
--> 543 found = Dialog(ms).find_msgs(re_pattern, msg_type=msg_type, only_err=only_err, only_exp=only_exp, ids=ids, limit=limit,
    544     use_case=use_case, use_regex=use_regex, headers_only=headers_only, header_section=header_section,
    545     before=max(before, context), after=max(after, context), context=0)
    546 def _d(m):
    547     o = m.todict()

File ~/aai-ws/aidialog/aidialog/dlgskill.py:218, in find_msgs(self, re_pattern, msg_type, only_err, only_exp, ids, before, after, context, limit, use_case, use_regex, headers_only, header_section, pred)
    216     if idset is not None and m.id not in idset: return False
    217     return not pat or bool(pat.search(_txt(m)))
--> 218 hits = [i for i,m in enumerate(ms) if _ok(m)]
    219 if limit is not None: hits = hits[:limit]
    220 matched = {ms[i].id for i in hits}

File ~/aai-ws/aidialog/aidialog/dlgskill.py:217, in find_msgs.<locals>._ok(m)
    215 if pred and not pred(m): return False
    216 if idset is not None and m.id not in idset: return False
--> 217 return not pat or bool(pat.search(_txt(m)))

File ~/aai-ws/aidialog/aidialog/dlgskill.py:209, in find_msgs.<locals>._txt(m)
--> 209 def _txt(m): return m.content + ('\n'+m.ai_res if m.msg_type==sprompt and m.ai_res else '')

TypeError: can only concatenate str (not "list") to str

@PiotrCzapla
PiotrCzapla requested a review from jph00 August 30, 2026 10:53
@jph00
jph00 merged commit 4ffebbf into main Aug 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants