aidialog 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aidialog/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.0.1"
aidialog/_modidx.py ADDED
@@ -0,0 +1,216 @@
1
+ # Autogenerated by nbdev
2
+
3
+ d = { 'settings': { 'branch': 'main',
4
+ 'doc_baseurl': '/aidialog',
5
+ 'doc_host': 'https://AnswerDotAI.github.io',
6
+ 'git_url': 'https://github.com/AnswerDotAI/aidialog',
7
+ 'lib_path': 'aidialog'},
8
+ 'syms': { 'aidialog.compact': { 'aidialog.compact.Dialog.compact': ('compact.html#dialog.compact', 'aidialog/compact.py'),
9
+ 'aidialog.compact.Message.compact': ('compact.html#message.compact', 'aidialog/compact.py'),
10
+ 'aidialog.compact._plumbing': ('compact.html#_plumbing', 'aidialog/compact.py'),
11
+ 'aidialog.compact._substantive': ('compact.html#_substantive', 'aidialog/compact.py'),
12
+ 'aidialog.compact.bash_call': ('compact.html#bash_call', 'aidialog/compact.py'),
13
+ 'aidialog.compact.compact_asst': ('compact.html#compact_asst', 'aidialog/compact.py'),
14
+ 'aidialog.compact.compact_asst_part': ('compact.html#compact_asst_part', 'aidialog/compact.py'),
15
+ 'aidialog.compact.compact_body': ('compact.html#compact_body', 'aidialog/compact.py'),
16
+ 'aidialog.compact.compact_call': ('compact.html#compact_call', 'aidialog/compact.py'),
17
+ 'aidialog.compact.compact_chat': ('compact.html#compact_chat', 'aidialog/compact.py'),
18
+ 'aidialog.compact.compact_content': ('compact.html#compact_content', 'aidialog/compact.py'),
19
+ 'aidialog.compact.compact_enc': ('compact.html#compact_enc', 'aidialog/compact.py'),
20
+ 'aidialog.compact.compact_msg': ('compact.html#compact_msg', 'aidialog/compact.py'),
21
+ 'aidialog.compact.compact_reply': ('compact.html#compact_reply', 'aidialog/compact.py'),
22
+ 'aidialog.compact.compact_result': ('compact.html#compact_result', 'aidialog/compact.py'),
23
+ 'aidialog.compact.compact_text': ('compact.html#compact_text', 'aidialog/compact.py'),
24
+ 'aidialog.compact.compact_tool': ('compact.html#compact_tool', 'aidialog/compact.py'),
25
+ 'aidialog.compact.compact_user': ('compact.html#compact_user', 'aidialog/compact.py'),
26
+ 'aidialog.compact.compact_user_part': ('compact.html#compact_user_part', 'aidialog/compact.py'),
27
+ 'aidialog.compact.enc_toks': ('compact.html#enc_toks', 'aidialog/compact.py'),
28
+ 'aidialog.compact.fenced_code': ('compact.html#fenced_code', 'aidialog/compact.py'),
29
+ 'aidialog.compact.generic_call': ('compact.html#generic_call', 'aidialog/compact.py'),
30
+ 'aidialog.compact.join_compacts': ('compact.html#join_compacts', 'aidialog/compact.py'),
31
+ 'aidialog.compact.len_toks': ('compact.html#len_toks', 'aidialog/compact.py'),
32
+ 'aidialog.compact.tool_part': ('compact.html#tool_part', 'aidialog/compact.py'),
33
+ 'aidialog.compact.tool_result': ('compact.html#tool_result', 'aidialog/compact.py'),
34
+ 'aidialog.compact.trunctoks_mid': ('compact.html#trunctoks_mid', 'aidialog/compact.py')},
35
+ 'aidialog.dialog': { 'aidialog.dialog.Attachment': ('dialog.html#attachment', 'aidialog/dialog.py'),
36
+ 'aidialog.dialog.Attachment.__init__': ('dialog.html#attachment.__init__', 'aidialog/dialog.py'),
37
+ 'aidialog.dialog.Dialog': ('dialog.html#dialog', 'aidialog/dialog.py'),
38
+ 'aidialog.dialog.Dialog.__bool__': ('dialog.html#dialog.__bool__', 'aidialog/dialog.py'),
39
+ 'aidialog.dialog.Dialog.__getitem__': ('dialog.html#dialog.__getitem__', 'aidialog/dialog.py'),
40
+ 'aidialog.dialog.Dialog.__init__': ('dialog.html#dialog.__init__', 'aidialog/dialog.py'),
41
+ 'aidialog.dialog.Dialog.__iter__': ('dialog.html#dialog.__iter__', 'aidialog/dialog.py'),
42
+ 'aidialog.dialog.Dialog.__len__': ('dialog.html#dialog.__len__', 'aidialog/dialog.py'),
43
+ 'aidialog.dialog.Dialog._repr_markdown_': ('dialog.html#dialog._repr_markdown_', 'aidialog/dialog.py'),
44
+ 'aidialog.dialog.Dialog.find_msg': ('dialog.html#dialog.find_msg', 'aidialog/dialog.py'),
45
+ 'aidialog.dialog.Dialog.mk_message': ('dialog.html#dialog.mk_message', 'aidialog/dialog.py'),
46
+ 'aidialog.dialog.Dialog.mk_messages': ('dialog.html#dialog.mk_messages', 'aidialog/dialog.py'),
47
+ 'aidialog.dialog.Dialog.remove_msgs': ('dialog.html#dialog.remove_msgs', 'aidialog/dialog.py'),
48
+ 'aidialog.dialog.Dialog.todict': ('dialog.html#dialog.todict', 'aidialog/dialog.py'),
49
+ 'aidialog.dialog.Dialog.validate': ('dialog.html#dialog.validate', 'aidialog/dialog.py'),
50
+ 'aidialog.dialog.Message': ('dialog.html#message', 'aidialog/dialog.py'),
51
+ 'aidialog.dialog.Message.__deepcopy__': ('dialog.html#message.__deepcopy__', 'aidialog/dialog.py'),
52
+ 'aidialog.dialog.Message.__flds__': ('dialog.html#message.__flds__', 'aidialog/dialog.py'),
53
+ 'aidialog.dialog.Message.__init__': ('dialog.html#message.__init__', 'aidialog/dialog.py'),
54
+ 'aidialog.dialog.Message._neighbor': ('dialog.html#message._neighbor', 'aidialog/dialog.py'),
55
+ 'aidialog.dialog.Message._repr_markdown_': ('dialog.html#message._repr_markdown_', 'aidialog/dialog.py'),
56
+ 'aidialog.dialog.Message.add_output': ('dialog.html#message.add_output', 'aidialog/dialog.py'),
57
+ 'aidialog.dialog.Message.ai_res': ('dialog.html#message.ai_res', 'aidialog/dialog.py'),
58
+ 'aidialog.dialog.Message.clear_inp_cache': ('dialog.html#message.clear_inp_cache', 'aidialog/dialog.py'),
59
+ 'aidialog.dialog.Message.clear_out_cache': ('dialog.html#message.clear_out_cache', 'aidialog/dialog.py'),
60
+ 'aidialog.dialog.Message.clear_output': ('dialog.html#message.clear_output', 'aidialog/dialog.py'),
61
+ 'aidialog.dialog.Message.content': ('dialog.html#message.content', 'aidialog/dialog.py'),
62
+ 'aidialog.dialog.Message.directives': ('dialog.html#message.directives', 'aidialog/dialog.py'),
63
+ 'aidialog.dialog.Message.dlg': ('dialog.html#message.dlg', 'aidialog/dialog.py'),
64
+ 'aidialog.dialog.Message.flds': ('dialog.html#message.flds', 'aidialog/dialog.py'),
65
+ 'aidialog.dialog.Message.has_error': ('dialog.html#message.has_error', 'aidialog/dialog.py'),
66
+ 'aidialog.dialog.Message.header_level': ('dialog.html#message.header_level', 'aidialog/dialog.py'),
67
+ 'aidialog.dialog.Message.insert_after': ('dialog.html#message.insert_after', 'aidialog/dialog.py'),
68
+ 'aidialog.dialog.Message.merge_content': ('dialog.html#message.merge_content', 'aidialog/dialog.py'),
69
+ 'aidialog.dialog.Message.mk_attachment': ('dialog.html#message.mk_attachment', 'aidialog/dialog.py'),
70
+ 'aidialog.dialog.Message.msg_type': ('dialog.html#message.msg_type', 'aidialog/dialog.py'),
71
+ 'aidialog.dialog.Message.next': ('dialog.html#message.next', 'aidialog/dialog.py'),
72
+ 'aidialog.dialog.Message.output': ('dialog.html#message.output', 'aidialog/dialog.py'),
73
+ 'aidialog.dialog.Message.preview': ('dialog.html#message.preview', 'aidialog/dialog.py'),
74
+ 'aidialog.dialog.Message.previous': ('dialog.html#message.previous', 'aidialog/dialog.py'),
75
+ 'aidialog.dialog.Message.rel_msg': ('dialog.html#message.rel_msg', 'aidialog/dialog.py'),
76
+ 'aidialog.dialog.Message.remove_from_dlg': ('dialog.html#message.remove_from_dlg', 'aidialog/dialog.py'),
77
+ 'aidialog.dialog.Message.summ': ('dialog.html#message.summ', 'aidialog/dialog.py'),
78
+ 'aidialog.dialog.Message.update': ('dialog.html#message.update', 'aidialog/dialog.py'),
79
+ 'aidialog.dialog.Message.validate': ('dialog.html#message.validate', 'aidialog/dialog.py'),
80
+ 'aidialog.dialog.MsgRow': ('dialog.html#msgrow', 'aidialog/dialog.py'),
81
+ 'aidialog.dialog.MsgRow.__init__': ('dialog.html#msgrow.__init__', 'aidialog/dialog.py'),
82
+ 'aidialog.dialog.MsgRow.__repr__': ('dialog.html#msgrow.__repr__', 'aidialog/dialog.py'),
83
+ 'aidialog.dialog.MsgRows': ('dialog.html#msgrows', 'aidialog/dialog.py'),
84
+ 'aidialog.dialog.MsgRows.__repr__': ('dialog.html#msgrows.__repr__', 'aidialog/dialog.py'),
85
+ 'aidialog.dialog.Msgs': ('dialog.html#msgs', 'aidialog/dialog.py'),
86
+ 'aidialog.dialog.Msgs.__repr__': ('dialog.html#msgs.__repr__', 'aidialog/dialog.py'),
87
+ 'aidialog.dialog.Msgs.show': ('dialog.html#msgs.show', 'aidialog/dialog.py'),
88
+ 'aidialog.dialog._get_exported': ('dialog.html#_get_exported', 'aidialog/dialog.py'),
89
+ 'aidialog.dialog._set_exported': ('dialog.html#_set_exported', 'aidialog/dialog.py'),
90
+ 'aidialog.dialog.add_id_hash': ('dialog.html#add_id_hash', 'aidialog/dialog.py'),
91
+ 'aidialog.dialog.code_output': ('dialog.html#code_output', 'aidialog/dialog.py'),
92
+ 'aidialog.dialog.copy_export': ('dialog.html#copy_export', 'aidialog/dialog.py'),
93
+ 'aidialog.dialog.displayobj': ('dialog.html#displayobj', 'aidialog/dialog.py'),
94
+ 'aidialog.dialog.dlg2py': ('dialog.html#dlg2py', 'aidialog/dialog.py'),
95
+ 'aidialog.dialog.get_msg': ('dialog.html#get_msg', 'aidialog/dialog.py'),
96
+ 'aidialog.dialog.get_output_mds': ('dialog.html#get_output_mds', 'aidialog/dialog.py'),
97
+ 'aidialog.dialog.header_info': ('dialog.html#header_info', 'aidialog/dialog.py'),
98
+ 'aidialog.dialog.merge_metas': ('dialog.html#merge_metas', 'aidialog/dialog.py'),
99
+ 'aidialog.dialog.merge_parts': ('dialog.html#merge_parts', 'aidialog/dialog.py'),
100
+ 'aidialog.dialog.mk_code_output': ('dialog.html#mk_code_output', 'aidialog/dialog.py'),
101
+ 'aidialog.dialog.mk_dispdata': ('dialog.html#mk_dispdata', 'aidialog/dialog.py'),
102
+ 'aidialog.dialog.mk_displayobj': ('dialog.html#mk_displayobj', 'aidialog/dialog.py'),
103
+ 'aidialog.dialog.mk_error': ('dialog.html#mk_error', 'aidialog/dialog.py'),
104
+ 'aidialog.dialog.mk_execresult': ('dialog.html#mk_execresult', 'aidialog/dialog.py'),
105
+ 'aidialog.dialog.mk_jmsg': ('dialog.html#mk_jmsg', 'aidialog/dialog.py'),
106
+ 'aidialog.dialog.mk_output': ('dialog.html#mk_output', 'aidialog/dialog.py'),
107
+ 'aidialog.dialog.mk_stream': ('dialog.html#mk_stream', 'aidialog/dialog.py'),
108
+ 'aidialog.dialog.output_from_msg': ('dialog.html#output_from_msg', 'aidialog/dialog.py'),
109
+ 'aidialog.dialog.prompt_output': ('dialog.html#prompt_output', 'aidialog/dialog.py'),
110
+ 'aidialog.dialog.ruuid4': ('dialog.html#ruuid4', 'aidialog/dialog.py'),
111
+ 'aidialog.dialog.section_msgs': ('dialog.html#section_msgs', 'aidialog/dialog.py')},
112
+ 'aidialog.dlgskill': { 'aidialog.dlgskill.Dialog.copy_msgs': ('dlgskill.html#dialog.copy_msgs', 'aidialog/dlgskill.py'),
113
+ 'aidialog.dlgskill.Dialog.cut_msgs': ('dlgskill.html#dialog.cut_msgs', 'aidialog/dlgskill.py'),
114
+ 'aidialog.dlgskill.Dialog.find_msgs': ('dlgskill.html#dialog.find_msgs', 'aidialog/dlgskill.py'),
115
+ 'aidialog.dlgskill.Dialog.merge_msgs': ('dlgskill.html#dialog.merge_msgs', 'aidialog/dlgskill.py'),
116
+ 'aidialog.dlgskill.Dialog.move_msgs': ('dlgskill.html#dialog.move_msgs', 'aidialog/dlgskill.py'),
117
+ 'aidialog.dlgskill.Dialog.msg': ('dlgskill.html#dialog.msg', 'aidialog/dlgskill.py'),
118
+ 'aidialog.dlgskill.Dialog.paste_msgs': ('dlgskill.html#dialog.paste_msgs', 'aidialog/dlgskill.py'),
119
+ 'aidialog.dlgskill.Dialog.summary': ('dlgskill.html#dialog.summary', 'aidialog/dlgskill.py'),
120
+ 'aidialog.dlgskill.Dialog.view': ('dlgskill.html#dialog.view', 'aidialog/dlgskill.py'),
121
+ 'aidialog.dlgskill.Message.exhash': ('dlgskill.html#message.exhash', 'aidialog/dlgskill.py'),
122
+ 'aidialog.dlgskill.Message.lnhashview': ('dlgskill.html#message.lnhashview', 'aidialog/dlgskill.py'),
123
+ 'aidialog.dlgskill.Message.split': ('dlgskill.html#message.split', 'aidialog/dlgskill.py'),
124
+ 'aidialog.dlgskill.Message.to_xml': ('dlgskill.html#message.to_xml', 'aidialog/dlgskill.py'),
125
+ 'aidialog.dlgskill.Message.view': ('dlgskill.html#message.view', 'aidialog/dlgskill.py'),
126
+ 'aidialog.dlgskill._atts_for': ('dlgskill.html#_atts_for', 'aidialog/dlgskill.py'),
127
+ 'aidialog.dlgskill._load_dlg': ('dlgskill.html#_load_dlg', 'aidialog/dlgskill.py'),
128
+ 'aidialog.dlgskill._match_head': ('dlgskill.html#_match_head', 'aidialog/dlgskill.py'),
129
+ 'aidialog.dlgskill._msg_edit': ('dlgskill.html#_msg_edit', 'aidialog/dlgskill.py'),
130
+ 'aidialog.dlgskill._msg_method': ('dlgskill.html#_msg_method', 'aidialog/dlgskill.py'),
131
+ 'aidialog.dlgskill._out_text': ('dlgskill.html#_out_text', 'aidialog/dlgskill.py'),
132
+ 'aidialog.dlgskill._save': ('dlgskill.html#_save', 'aidialog/dlgskill.py'),
133
+ 'aidialog.dlgskill._set_out_text': ('dlgskill.html#_set_out_text', 'aidialog/dlgskill.py'),
134
+ 'aidialog.dlgskill._to_dlg': ('dlgskill.html#_to_dlg', 'aidialog/dlgskill.py'),
135
+ 'aidialog.dlgskill.add_msg': ('dlgskill.html#add_msg', 'aidialog/dlgskill.py'),
136
+ 'aidialog.dlgskill.add_msg_magic': ('dlgskill.html#add_msg_magic', 'aidialog/dlgskill.py'),
137
+ 'aidialog.dlgskill.ast_finder': ('dlgskill.html#ast_finder', 'aidialog/dlgskill.py'),
138
+ 'aidialog.dlgskill.copy_msgs': ('dlgskill.html#copy_msgs', 'aidialog/dlgskill.py'),
139
+ 'aidialog.dlgskill.create_dlg': ('dlgskill.html#create_dlg', 'aidialog/dlgskill.py'),
140
+ 'aidialog.dlgskill.cur_dlg': ('dlgskill.html#cur_dlg', 'aidialog/dlgskill.py'),
141
+ 'aidialog.dlgskill.cut_msgs': ('dlgskill.html#cut_msgs', 'aidialog/dlgskill.py'),
142
+ 'aidialog.dlgskill.del_msgs': ('dlgskill.html#del_msgs', 'aidialog/dlgskill.py'),
143
+ 'aidialog.dlgskill.find_msgs': ('dlgskill.html#find_msgs', 'aidialog/dlgskill.py'),
144
+ 'aidialog.dlgskill.lnhashview_msg': ('dlgskill.html#lnhashview_msg', 'aidialog/dlgskill.py'),
145
+ 'aidialog.dlgskill.load_ipython_extension': ( 'dlgskill.html#load_ipython_extension',
146
+ 'aidialog/dlgskill.py'),
147
+ 'aidialog.dlgskill.merge_msgs': ('dlgskill.html#merge_msgs', 'aidialog/dlgskill.py'),
148
+ 'aidialog.dlgskill.move_msgs': ('dlgskill.html#move_msgs', 'aidialog/dlgskill.py'),
149
+ 'aidialog.dlgskill.msg2xml': ('dlgskill.html#msg2xml', 'aidialog/dlgskill.py'),
150
+ 'aidialog.dlgskill.msg_exhash': ('dlgskill.html#msg_exhash', 'aidialog/dlgskill.py'),
151
+ 'aidialog.dlgskill.paste_msgs': ('dlgskill.html#paste_msgs', 'aidialog/dlgskill.py'),
152
+ 'aidialog.dlgskill.set_dlg': ('dlgskill.html#set_dlg', 'aidialog/dlgskill.py'),
153
+ 'aidialog.dlgskill.split_msg': ('dlgskill.html#split_msg', 'aidialog/dlgskill.py'),
154
+ 'aidialog.dlgskill.summary_dlg': ('dlgskill.html#summary_dlg', 'aidialog/dlgskill.py'),
155
+ 'aidialog.dlgskill.symdef_finder': ('dlgskill.html#symdef_finder', 'aidialog/dlgskill.py'),
156
+ 'aidialog.dlgskill.symref_finder': ('dlgskill.html#symref_finder', 'aidialog/dlgskill.py'),
157
+ 'aidialog.dlgskill.view_dlg': ('dlgskill.html#view_dlg', 'aidialog/dlgskill.py'),
158
+ 'aidialog.dlgskill.view_msg': ('dlgskill.html#view_msg', 'aidialog/dlgskill.py'),
159
+ 'aidialog.dlgskill.view_msgs': ('dlgskill.html#view_msgs', 'aidialog/dlgskill.py')},
160
+ 'aidialog.hist': { 'aidialog.hist.Message.ai_output': ('hist.html#message.ai_output', 'aidialog/hist.py'),
161
+ 'aidialog.hist.Message.hist_xml': ('hist.html#message.hist_xml', 'aidialog/hist.py'),
162
+ 'aidialog.hist.Message.local_time': ('hist.html#message.local_time', 'aidialog/hist.py'),
163
+ 'aidialog.hist.Message.media_extra': ('hist.html#message.media_extra', 'aidialog/hist.py'),
164
+ 'aidialog.hist.Message.prep_img': ('hist.html#message.prep_img', 'aidialog/hist.py'),
165
+ 'aidialog.hist.Message.prompt_txt': ('hist.html#message.prompt_txt', 'aidialog/hist.py'),
166
+ 'aidialog.hist.Message.render_out': ('hist.html#message.render_out', 'aidialog/hist.py'),
167
+ 'aidialog.hist.Message.to_media': ('hist.html#message.to_media', 'aidialog/hist.py'),
168
+ 'aidialog.hist.Message.to_parts': ('hist.html#message.to_parts', 'aidialog/hist.py'),
169
+ 'aidialog.hist.Message.todict': ('hist.html#message.todict', 'aidialog/hist.py'),
170
+ 'aidialog.hist.Message.tool_call': ('hist.html#message.tool_call', 'aidialog/hist.py'),
171
+ 'aidialog.hist._MissError': ('hist.html#_misserror', 'aidialog/hist.py'),
172
+ 'aidialog.hist._dotted_name': ('hist.html#_dotted_name', 'aidialog/hist.py'),
173
+ 'aidialog.hist._explode': ('hist.html#_explode', 'aidialog/hist.py'),
174
+ 'aidialog.hist._img_id': ('hist.html#_img_id', 'aidialog/hist.py'),
175
+ 'aidialog.hist._img_item': ('hist.html#_img_item', 'aidialog/hist.py'),
176
+ 'aidialog.hist._img_output': ('hist.html#_img_output', 'aidialog/hist.py'),
177
+ 'aidialog.hist._latex_parts': ('hist.html#_latex_parts', 'aidialog/hist.py'),
178
+ 'aidialog.hist._media_atts': ('hist.html#_media_atts', 'aidialog/hist.py'),
179
+ 'aidialog.hist._media_unavailable': ('hist.html#_media_unavailable', 'aidialog/hist.py'),
180
+ 'aidialog.hist._media_xml': ('hist.html#_media_xml', 'aidialog/hist.py'),
181
+ 'aidialog.hist._mime_kind': ('hist.html#_mime_kind', 'aidialog/hist.py'),
182
+ 'aidialog.hist._mime_supported': ('hist.html#_mime_supported', 'aidialog/hist.py'),
183
+ 'aidialog.hist._msg2tr': ('hist.html#_msg2tr', 'aidialog/hist.py'),
184
+ 'aidialog.hist._parse_call': ('hist.html#_parse_call', 'aidialog/hist.py'),
185
+ 'aidialog.hist._seq_tools': ('hist.html#_seq_tools', 'aidialog/hist.py'),
186
+ 'aidialog.hist.ai_fmt': ('hist.html#ai_fmt', 'aidialog/hist.py'),
187
+ 'aidialog.hist.chat2dlg': ('hist.html#chat2dlg', 'aidialog/hist.py'),
188
+ 'aidialog.hist.dlg2chat': ('hist.html#dlg2chat', 'aidialog/hist.py'),
189
+ 'aidialog.hist.dlg2hist': ('hist.html#dlg2hist', 'aidialog/hist.py'),
190
+ 'aidialog.hist.dlg2reply': ('hist.html#dlg2reply', 'aidialog/hist.py'),
191
+ 'aidialog.hist.join_out': ('hist.html#join_out', 'aidialog/hist.py'),
192
+ 'aidialog.hist.jwrap': ('hist.html#jwrap', 'aidialog/hist.py'),
193
+ 'aidialog.hist.media_item': ('hist.html#media_item', 'aidialog/hist.py'),
194
+ 'aidialog.hist.normalize_text_latex': ('hist.html#normalize_text_latex', 'aidialog/hist.py'),
195
+ 'aidialog.hist.render_output_ai': ('hist.html#render_output_ai', 'aidialog/hist.py'),
196
+ 'aidialog.hist.render_outputs_ai': ('hist.html#render_outputs_ai', 'aidialog/hist.py'),
197
+ 'aidialog.hist.reply2dlg': ('hist.html#reply2dlg', 'aidialog/hist.py'),
198
+ 'aidialog.hist.strip_tool_blocks': ('hist.html#strip_tool_blocks', 'aidialog/hist.py'),
199
+ 'aidialog.hist.to_local_time': ('hist.html#to_local_time', 'aidialog/hist.py'),
200
+ 'aidialog.hist.try_eval': ('hist.html#try_eval', 'aidialog/hist.py')},
201
+ 'aidialog.ipynb': { 'aidialog.ipynb.Dialog.cell2msg': ('ipynb.html#dialog.cell2msg', 'aidialog/ipynb.py'),
202
+ 'aidialog.ipynb.Dialog.from_cells': ('ipynb.html#dialog.from_cells', 'aidialog/ipynb.py'),
203
+ 'aidialog.ipynb.Dialog.save': ('ipynb.html#dialog.save', 'aidialog/ipynb.py'),
204
+ 'aidialog.ipynb.Dialog.write': ('ipynb.html#dialog.write', 'aidialog/ipynb.py'),
205
+ 'aidialog.ipynb.Message.cell_meta': ('ipynb.html#message.cell_meta', 'aidialog/ipynb.py'),
206
+ 'aidialog.ipynb.Message.to_cell': ('ipynb.html#message.to_cell', 'aidialog/ipynb.py'),
207
+ 'aidialog.ipynb._clean_out_meta': ('ipynb.html#_clean_out_meta', 'aidialog/ipynb.py'),
208
+ 'aidialog.ipynb._output_from_cell': ('ipynb.html#_output_from_cell', 'aidialog/ipynb.py'),
209
+ 'aidialog.ipynb.att2dict': ('ipynb.html#att2dict', 'aidialog/ipynb.py'),
210
+ 'aidialog.ipynb.dict2att': ('ipynb.html#dict2att', 'aidialog/ipynb.py'),
211
+ 'aidialog.ipynb.get_ipynb': ('ipynb.html#get_ipynb', 'aidialog/ipynb.py'),
212
+ 'aidialog.ipynb.ipynb_cells': ('ipynb.html#ipynb_cells', 'aidialog/ipynb.py'),
213
+ 'aidialog.ipynb.read_ipynb': ('ipynb.html#read_ipynb', 'aidialog/ipynb.py'),
214
+ 'aidialog.ipynb.reads_ipynb': ('ipynb.html#reads_ipynb', 'aidialog/ipynb.py'),
215
+ 'aidialog.ipynb.split_cell_src': ('ipynb.html#split_cell_src', 'aidialog/ipynb.py'),
216
+ 'aidialog.ipynb.write_ipynb': ('ipynb.html#write_ipynb', 'aidialog/ipynb.py')}}}
aidialog/compact.py ADDED
@@ -0,0 +1,237 @@
1
+ """Docs: https://AnswerDotAI.github.io/aidialog/compact.html.md"""
2
+
3
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/04_compact.ipynb.
4
+
5
+ # %% auto #0
6
+ __all__ = ['compact_policy', 'tool_part', 'tool_result', 'compact_enc', 'enc_toks', 'len_toks', 'trunctoks_mid', 'compact_text',
7
+ 'compact_result', 'fenced_code', 'bash_call', 'generic_call', 'compact_call', 'compact_user_part',
8
+ 'compact_user', 'compact_asst_part', 'compact_asst', 'compact_tool', 'compact_msg', 'compact_chat',
9
+ 'compact_content', 'compact_body', 'join_compacts', 'compact_reply']
10
+
11
+ # %% ../nbs/04_compact.ipynb #de23b4fe
12
+ from fastcore.utils import *
13
+ from functools import cache
14
+ from fastllm.types import PartType,Part,Msg
15
+
16
+ import re
17
+ try: import tiktoken
18
+ except ImportError: tiktoken = None
19
+
20
+ # %% ../nbs/04_compact.ipynb #2fe68d07
21
+ def tool_part(tool_name, **arguments):
22
+ "Create a canonical tool-use part"
23
+ return Part(PartType.tool_use, data=dict(name=tool_name, arguments=arguments, id=f'call_{tool_name}'))
24
+
25
+ def tool_result(text, tool_name=None):
26
+ "Create a canonical tool-result message; pass `tool_name` to pair it with its `tool_part` call"
27
+ data = {'id':f'call_{tool_name}', 'name':tool_name} if tool_name else None
28
+ return Msg('tool', [Part(PartType.tool_result, text=text, data=data)])
29
+
30
+ # %% ../nbs/04_compact.ipynb #7ad24f5a
31
+ _compact_enc_name = 'o200k_base'
32
+
33
+ @cache
34
+ def compact_enc():
35
+ assert tiktoken, "Compaction token counting needs `tiktoken` - pip install tiktoken"
36
+ return tiktoken.get_encoding(_compact_enc_name)
37
+
38
+ def enc_toks(s, enc=None):
39
+ "Encode `s` into tokens."
40
+ if enc is None: enc = compact_enc()
41
+ return enc.encode(s, disallowed_special=())
42
+
43
+ def len_toks(s, enc=None):
44
+ "Number of tokens in `s`."
45
+ return len(enc_toks(s, enc))
46
+
47
+ # %% ../nbs/04_compact.ipynb #396a6a3b
48
+ def trunctoks_mid(s, max_toks, enc=None, mark=' … '):
49
+ "Truncate the middle of `s` to at most `max_toks` tokens."
50
+ if enc is None: enc = compact_enc()
51
+ if max_toks <= 0: return ''
52
+ toks = enc_toks(s, enc)
53
+ if len(toks) <= max_toks: return s
54
+ mtoks = enc_toks(mark, enc)[:max_toks]
55
+ n = max_toks - len(mtoks)
56
+ a, b = (n + 1) // 2, n // 2
57
+ tail = toks[-b:] if b else []
58
+ return enc.decode(toks[:a] + mtoks + tail)
59
+
60
+ # %% ../nbs/04_compact.ipynb #f55fe38a
61
+ def compact_text(s, mark, max_toks, enc=None):
62
+ "Render delimited prose within `max_toks`."
63
+ return trunctoks_mid(f'{mark} {s.strip()} {mark}', max_toks, enc)
64
+
65
+ # %% ../nbs/04_compact.ipynb #e3f22ddb
66
+ _re_warnnote = re.compile(r'<(warn|note)>.*?</\1>', re.DOTALL)
67
+
68
+ def compact_result(s, max_toks, enc=None):
69
+ "Render a tool result within `max_toks`; `<warn>`/`<note>` doc-state blocks are dropped, and a `𝍁`-wrapped result is kept whole."
70
+ s = _re_warnnote.sub('', s).strip()
71
+ keep = len(s)>2 and s[0]=='𝍁' and s[-1]=='𝍁'
72
+ if keep: s = s[1:-1]
73
+ text = ' ¶ '.join(line.strip() for line in s.splitlines() if line.strip())
74
+ res = f'> {text}' if text else '>'
75
+ return res if keep else trunctoks_mid(res, max_toks, enc)
76
+
77
+ # %% ../nbs/04_compact.ipynb #783d1ab0
78
+ def fenced_code(code, max_toks, enc=None):
79
+ "Render Python in a safe Markdown fence within `max_toks`."
80
+ code = code.strip()
81
+ runs = re.findall(r'^ {0,3}(`{3,})[ \t]*$', code, flags=re.MULTILINE)
82
+ fence = '`' * max(3, max(map(len, runs), default=0) + 1)
83
+ pre,suf = f'{fence}python\n',f'\n{fence}'
84
+ full = pre + code + suf
85
+ if len_toks(full, enc) <= max_toks: return full
86
+ if len_toks(pre + suf, enc) > max_toks: raise ValueError('Token budget is too small for a fenced block')
87
+ body_toks = min(len_toks(code, enc), max_toks)
88
+ while body_toks:
89
+ body = trunctoks_mid(code, body_toks, enc)
90
+ result = pre + body + suf
91
+ if len_toks(result, enc) <= max_toks: return result
92
+ body_toks -= 1
93
+ return pre + suf
94
+
95
+ # %% ../nbs/04_compact.ipynb #99ed7e9d
96
+ def bash_call(command, max_toks, enc=None):
97
+ "Render a Bash command within `max_toks`."
98
+ text = '! ' + ' ¶ '.join(line.strip() for line in command.splitlines() if line.strip())
99
+ return trunctoks_mid(text, max_toks, enc)
100
+
101
+ # %% ../nbs/04_compact.ipynb #a76c5354
102
+ def generic_call(name, args, max_toks, enc=None):
103
+ "Render a generic tool call within `max_toks`."
104
+ vals = ', '.join(f"{k}={v!r}".replace('\\n', ' ¶ ') for k,v in args.items())
105
+ return trunctoks_mid(f'▶ {name}({vals})', max_toks, enc)
106
+
107
+ # %% ../nbs/04_compact.ipynb #cef7d16f
108
+ def compact_call(p, max_toks, enc=None):
109
+ "Render a tool-use part within `max_toks`."
110
+ name, args = p.data['name'], p.data['arguments']
111
+ if name.removeprefix('tools.') == 'mcp__clikernel__execute': return fenced_code(args['code'], max_toks, enc)
112
+ if name == 'Bash': return bash_call(args.get('command', ''), max_toks, enc)
113
+ return generic_call(name, args, max_toks, enc)
114
+
115
+ # %% ../nbs/04_compact.ipynb #d5c7af9a
116
+ _re_plumbing = re.compile(r'\s*<(command-name|command-message|command-args|local-command-stdout|local-command-caveat|system-reminder)>')
117
+
118
+ def _plumbing(text):
119
+ "Is this user text host plumbing (slash-command records, command stdout, hook output) rather than prose?"
120
+ return bool(_re_plumbing.match(text))
121
+
122
+ def compact_user_part(p, max_toks, enc=None):
123
+ "Render one user-text part, replacing injected skill contents."
124
+ text = '…skill text compacted: re-invoke before relying on it…' if p.text.startswith('Base directory for this skill:') else p.text
125
+ return compact_text(text, '§', max_toks, enc)
126
+
127
+ def compact_user(m, max_toks, enc=None):
128
+ "Render the text parts of a user message, dropping plumbing parts."
129
+ return '\n'.join(compact_user_part(p, max_toks, enc)
130
+ for p in m.content if p.type == PartType.text and not _plumbing(p.text))
131
+
132
+ # %% ../nbs/04_compact.ipynb #c43c4e7e
133
+ def compact_asst_part(p, text_toks, call_toks, enc=None):
134
+ "Render one assistant part."
135
+ if p.type == PartType.text: return compact_text(p.text, '»', text_toks, enc)
136
+ if p.type == PartType.tool_use: return compact_call(p, call_toks, enc)
137
+
138
+ def compact_asst(m, text_toks, call_toks, enc=None):
139
+ "Render an assistant message."
140
+ parts = (compact_asst_part(p, text_toks, call_toks, enc) for p in m.content)
141
+ return '\n'.join(filter(None, parts))
142
+
143
+ # %% ../nbs/04_compact.ipynb #30805c31
144
+ def compact_tool(m, max_toks, enc=None):
145
+ "Render the result parts of a tool message."
146
+ return '\n'.join(compact_result(p.text, max_toks, enc)
147
+ for p in m.content if p.type == PartType.tool_result)
148
+
149
+ def compact_msg(m, user_toks, asst_toks, call_toks, result_toks, enc=None):
150
+ "Render one canonical message."
151
+ if m.role == 'user': return compact_user(m, user_toks, enc)
152
+ if m.role == 'assistant': return compact_asst(m, asst_toks, call_toks, enc)
153
+ if m.role == 'tool': return compact_tool(m, result_toks, enc)
154
+
155
+ # %% ../nbs/04_compact.ipynb #44c88dee
156
+ def _substantive(m):
157
+ "Does the message render any content? Plumbing-only user messages do not, so they never spend `last_n` slots"
158
+ if m.role != 'user': return True
159
+ return any(p.type == PartType.text and not _plumbing(p.text) for p in m.content)
160
+
161
+ def compact_chat(msgs, user_toks, asst_toks, call_toks, result_toks, enc=None, last_n=0):
162
+ "Render canonical messages as compact user-led turns."
163
+ policy = dict(user_toks=user_toks, asst_toks=asst_toks, call_toks=call_toks, result_toks=result_toks)
164
+ full_policy = {k:10**9 for k in policy}
165
+ subst = [i for i,m in enumerate(msgs) if _substantive(m)]
166
+ nfull = len(msgs) if not last_n else (subst[-last_n] if last_n <= len(subst) else 0)
167
+ turns = []
168
+ for i,m in enumerate(msgs):
169
+ if m.role == 'user' or not turns: turns.append([])
170
+ p = full_policy if i >= nfull else policy
171
+ turns[-1].append(compact_msg(m, enc=enc, **p))
172
+ rendered = ('\n'.join(filter(None, turn)) for turn in turns)
173
+ return '\n\n***\n\n'.join(filter(None, rendered))
174
+
175
+ # %% ../nbs/04_compact.ipynb #42df86f5
176
+ compact_policy = dict(user_toks=2000, asst_toks=150, call_toks=60, result_toks=35)
177
+
178
+ # %% ../nbs/04_compact.ipynb #5005ee37
179
+ _re_skill = re.compile(r"▶ Skill\(skill='([^']+)'")
180
+
181
+ def compact_content(chat, path, notes=''):
182
+ "Wrap compact conversation text as a continuation document."
183
+ intro = "This session is being continued from an earlier conversation. `§ … §` encloses user text; `» … »` encloses assistant text; fenced `python` is persistent-kernel execution; `!` marks Bash; `▶` marks another tool call; `>` marks its result; `¶` replaces a newline; `***` separates user-led turns; and ` … ` marks removed middle content. The final five messages are preserved untruncated. This representation is for orientation only: never copy code or commands from it; reopen the original transcript or source file first."
184
+ res = f'{intro}\n\n## Conversation\n\n{chat}'
185
+ if notes: res += f'\n\n## Auto-generated continuation notes\n\n{notes}'
186
+ res += f'\n\nIf further detail is needed, read the complete transcript at: {path}'
187
+ if skills := L(_re_skill.findall(chat)).unique():
188
+ res += '\n\nSkill contents were compacted out above. Before relying on any skill guidance, re-invoke it: ' + ', '.join(f'Skill({s})' for s in skills) + '.'
189
+ return res
190
+
191
+ # %% ../nbs/04_compact.ipynb #01c63a09
192
+ def compact_body(content):
193
+ "Extract the conversation body from a compaction document."
194
+ body = content.split('\n\n## Conversation\n\n', 1)[1]
195
+ body = body.split('\n\n## Auto-generated continuation notes\n\n', 1)[0]
196
+ return body.rsplit('\n\nIf further detail is needed, read the complete transcript at:', 1)[0]
197
+
198
+ # %% ../nbs/04_compact.ipynb #5fac4786
199
+ def join_compacts(*parts):
200
+ "Join non-empty compact conversation segments."
201
+ return '\n\n***\n\n'.join(part for part in parts if part)
202
+
203
+ # %% ../nbs/04_compact.ipynb #0f5f4c5e
204
+ from fastllm.chat import fmt2hist
205
+ from .dialog import *
206
+
207
+ # %% ../nbs/04_compact.ipynb #1f0614f1
208
+ def compact_reply(reply, asst_toks=None, call_toks=None, result_toks=None, enc=None):
209
+ "Render a prompt's reply in the DSL: bare prose, each tool call followed by its result"
210
+ msgs = fmt2hist(reply)
211
+ results = {p.data['id']:p for m in msgs if m.role=='tool' for p in m.content if p.type==PartType.tool_result}
212
+ out = []
213
+ for m in msgs:
214
+ if m.role != 'assistant': continue
215
+ for p in m.content:
216
+ if p.type==PartType.text and p.text != '.':
217
+ out.append(trunctoks_mid(p.text.strip(), ifnone(asst_toks, compact_policy['asst_toks']), enc))
218
+ elif p.type==PartType.tool_use:
219
+ out.append(compact_call(p, ifnone(call_toks, compact_policy['call_toks']), enc))
220
+ if r := results.get(p.data['id']): out.append(compact_result(r.text, ifnone(result_toks, compact_policy['result_toks']), enc))
221
+ return '\n'.join(filter(None, out))
222
+
223
+ # %% ../nbs/04_compact.ipynb #73962ff1
224
+ @patch
225
+ def compact(self:Message, user_toks=None, asst_toks=None, call_toks=None, result_toks=None, enc=None):
226
+ "Compact a prompt message in place: cap the question, re-render the reply in the DSL; other types are left untouched"
227
+ if self.msg_type != sprompt: return self
228
+ self.content = trunctoks_mid(self.content, ifnone(user_toks, compact_policy['user_toks']), enc)
229
+ if r := self.ai_res: self.output = compact_reply(r, asst_toks, call_toks, result_toks, enc)
230
+ return self
231
+
232
+ # %% ../nbs/04_compact.ipynb #e376676d
233
+ @patch
234
+ def compact(self:Dialog, user_toks=None, asst_toks=None, call_toks=None, result_toks=None, enc=None):
235
+ "Compact every prompt message in place; the rest of the notebook is untouched"
236
+ for m in self.messages: m.compact(user_toks, asst_toks, call_toks, result_toks, enc)
237
+ return self