|
645 | 645 | "output_type": "stream", |
646 | 646 | "text": [ |
647 | 647 | "_9c544573\n", |
648 | | - "\n" |
| 648 | + "_9558b075\n" |
649 | 649 | ] |
650 | 650 | } |
651 | 651 | ], |
|
855 | 855 | "_edit_id = add_msg('This message should be found.\\n\\nThis is a multiline message.')" |
856 | 856 | ] |
857 | 857 | }, |
| 858 | + { |
| 859 | + "cell_type": "markdown", |
| 860 | + "id": "57797a25", |
| 861 | + "metadata": {}, |
| 862 | + "source": [ |
| 863 | + "This message should be found.\n", |
| 864 | + "\n", |
| 865 | + "This is a multiline message." |
| 866 | + ] |
| 867 | + }, |
858 | 868 | { |
859 | 869 | "cell_type": "code", |
860 | 870 | "execution_count": null, |
|
936 | 946 | "id": "6e354677", |
937 | 947 | "metadata": {}, |
938 | 948 | "outputs": [ |
| 949 | + { |
| 950 | + "data": { |
| 951 | + "text/plain": [ |
| 952 | + "2" |
| 953 | + ] |
| 954 | + }, |
| 955 | + "execution_count": null, |
| 956 | + "metadata": {}, |
| 957 | + "output_type": "execute_result" |
| 958 | + }, |
939 | 959 | { |
940 | 960 | "data": { |
941 | 961 | "text/plain": [ |
|
993 | 1013 | "def url2note(\n", |
994 | 1014 | " url:str, # URL to read\n", |
995 | 1015 | " extract_section:bool=True, # If url has an anchor, return only that section\n", |
996 | | - " selector:str=None # Select section(s) using BeautifulSoup.select (overrides extract_section)\n", |
| 1016 | + " selector:str=None, # Select section(s) using BeautifulSoup.select (overrides extract_section)\n", |
| 1017 | + " ai_img:bool=True, # Make images visible to the AI\n", |
| 1018 | + " split_re:str=r'(?=^#{1,6} .+)' # Regex to split content into multiple notes, set to False for single note\n", |
997 | 1019 | "):\n", |
998 | | - " \"Read URL as markdown, and add a note below current message with the result\"\n", |
999 | | - " res = read_url(url, as_md=True, extract_section=extract_section, selector=selector)\n", |
1000 | | - " return add_msg(res)" |
| 1020 | + " \"Read URL as markdown, and add note(s) below current message with the result\"\n", |
| 1021 | + " res = read_url(url, as_md=True, extract_section=extract_section, selector=selector, ai_img=ai_img)\n", |
| 1022 | + " if split_re: return [add_msg(s) for s in re.split(split_re, res, flags=re.MULTILINE) if s.strip()]\n", |
| 1023 | + " return add_msg(res)\n" |
1001 | 1024 | ] |
1002 | 1025 | }, |
1003 | 1026 | { |
|
1020 | 1043 | "del_msg(_id)" |
1021 | 1044 | ] |
1022 | 1045 | }, |
| 1046 | + { |
| 1047 | + "cell_type": "code", |
| 1048 | + "execution_count": null, |
| 1049 | + "id": "43554bd9", |
| 1050 | + "metadata": {}, |
| 1051 | + "outputs": [], |
| 1052 | + "source": [ |
| 1053 | + "_ids = url2note('https://www.answer.ai/posts/2025-10-01-cachy.html')" |
| 1054 | + ] |
| 1055 | + }, |
| 1056 | + { |
| 1057 | + "cell_type": "code", |
| 1058 | + "execution_count": null, |
| 1059 | + "id": "b02115e6", |
| 1060 | + "metadata": {}, |
| 1061 | + "outputs": [], |
| 1062 | + "source": [ |
| 1063 | + "_ = [del_msg(i) for i in _ids]" |
| 1064 | + ] |
| 1065 | + }, |
1023 | 1066 | { |
1024 | 1067 | "cell_type": "code", |
1025 | 1068 | "execution_count": null, |
|
1089 | 1132 | { |
1090 | 1133 | "data": { |
1091 | 1134 | "text/plain": [ |
1092 | | - "[(\"xpost('http://localhost:5001/pop_data_blocking_', data={'data_id': idx})\",\n", |
1093 | | - " {'B': {'text': \"{'data_id': idx}\",\n", |
1094 | | - " 'range': {'byteOffset': {'start': 1185, 'end': 1201},\n", |
1095 | | - " 'start': {'line': 38, 'column': 72},\n", |
1096 | | - " 'end': {'line': 38, 'column': 88}}},\n", |
1097 | | - " 'A': {'text': \"'http://localhost:5001/pop_data_blocking_'\",\n", |
1098 | | - " 'range': {'byteOffset': {'start': 1136, 'end': 1178},\n", |
1099 | | - " 'start': {'line': 38, 'column': 23},\n", |
1100 | | - " 'end': {'line': 38, 'column': 65}}}},\n", |
1101 | | - " 'dialoghelper/experimental.py'),\n", |
1102 | | - " ('xpost(f\\'http://localhost:{dh_settings[\"port\"]}/{path}\\', data=data)',\n", |
1103 | | - " {'A': {'text': 'f\\'http://localhost:{dh_settings[\"port\"]}/{path}\\'',\n", |
1104 | | - " 'range': {'byteOffset': {'start': 2624, 'end': 2672},\n", |
1105 | | - " 'start': {'line': 70, 'column': 16},\n", |
1106 | | - " 'end': {'line': 70, 'column': 64}}},\n", |
1107 | | - " 'B': {'text': 'data',\n", |
1108 | | - " 'range': {'byteOffset': {'start': 2679, 'end': 2683},\n", |
| 1135 | + "[('xpost(f\\'http://localhost:{dh_settings[\"port\"]}/{path}\\', data=data)',\n", |
| 1136 | + " {'B': {'text': 'data',\n", |
| 1137 | + " 'range': {'byteOffset': {'start': 2753, 'end': 2757},\n", |
1109 | 1138 | " 'start': {'line': 70, 'column': 71},\n", |
1110 | | - " 'end': {'line': 70, 'column': 75}}}},\n", |
| 1139 | + " 'end': {'line': 70, 'column': 75}}},\n", |
| 1140 | + " 'A': {'text': 'f\\'http://localhost:{dh_settings[\"port\"]}/{path}\\'',\n", |
| 1141 | + " 'range': {'byteOffset': {'start': 2698, 'end': 2746},\n", |
| 1142 | + " 'start': {'line': 70, 'column': 16},\n", |
| 1143 | + " 'end': {'line': 70, 'column': 64}}}},\n", |
| 1144 | + " 'dialoghelper/core.py'),\n", |
| 1145 | + " (\"xpost(url, data={'data_id': idx, 'timeout': timeout})\",\n", |
| 1146 | + " {'B': {'text': \"{'data_id': idx, 'timeout': timeout}\",\n", |
| 1147 | + " 'range': {'byteOffset': {'start': 4450, 'end': 4486},\n", |
| 1148 | + " 'start': {'line': 121, 'column': 36},\n", |
| 1149 | + " 'end': {'line': 121, 'column': 72}}},\n", |
| 1150 | + " 'A': {'text': 'url',\n", |
| 1151 | + " 'range': {'byteOffset': {'start': 4440, 'end': 4443},\n", |
| 1152 | + " 'start': {'line': 121, 'column': 26},\n", |
| 1153 | + " 'end': {'line': 121, 'column': 29}}}},\n", |
1111 | 1154 | " 'dialoghelper/core.py')]" |
1112 | 1155 | ] |
1113 | 1156 | }, |
|
1156 | 1199 | { |
1157 | 1200 | "data": { |
1158 | 1201 | "text/plain": [ |
1159 | | - "{'success': 'Inserted text after line 5 in message _c3581eea'}" |
| 1202 | + "{'success': 'Inserted text after line 5 in message _f813f590'}" |
1160 | 1203 | ] |
1161 | 1204 | }, |
1162 | 1205 | "execution_count": null, |
|
1220 | 1263 | { |
1221 | 1264 | "data": { |
1222 | 1265 | "text/plain": [ |
1223 | | - "{'success': 'Replaced text in message _c3581eea'}" |
| 1266 | + "{'success': 'Replaced text in message _f813f590'}" |
1224 | 1267 | ] |
1225 | 1268 | }, |
1226 | 1269 | "execution_count": null, |
|
1282 | 1325 | { |
1283 | 1326 | "data": { |
1284 | 1327 | "text/plain": [ |
1285 | | - "{'success': 'Successfully replaced all the strings in message _c3581eea'}" |
| 1328 | + "{'success': 'Successfully replaced all the strings in message _f813f590'}" |
1286 | 1329 | ] |
1287 | 1330 | }, |
1288 | 1331 | "execution_count": null, |
|
1345 | 1388 | { |
1346 | 1389 | "data": { |
1347 | 1390 | "text/plain": [ |
1348 | | - "{'success': 'Replaced lines 2 to 4 in message _c3581eea'}" |
| 1391 | + "{'success': 'Replaced lines 2 to 4 in message _f813f590'}" |
1349 | 1392 | ] |
1350 | 1393 | }, |
1351 | 1394 | "execution_count": null, |
|
1818 | 1861 | "- &`find_var`: Search for var in all frames of the call stack\n", |
1819 | 1862 | "- &`set_var`: Set var to val after finding it in all frames of the call stack\n", |
1820 | 1863 | "- &`find_dname`: Get the message id by searching the call stack for __dialog_id.\n", |
1821 | | - "- &`find_msg_id`: Get the message id by searching the call stack for __dialog_id.\n", |
| 1864 | + "- &`find_msg_id`: Get the message id by searching the call stack for __msg_id.\n", |
1822 | 1865 | "- &`curr_dialog`: Get the current dialog info.\n", |
1823 | 1866 | "- &`msg_idx`: Get absolute index of message in dialog.\n", |
| 1867 | + "- &`add_scr`: Swap a script element to the end of the js-script element\n", |
| 1868 | + "- &`iife`: Wrap javascript code string in an IIFE and execute it via `add_html`\n", |
| 1869 | + "- &`event_get`: Call `fire_event` and then `pop_data` to get a response\n", |
1824 | 1870 | "- &`find_msgs`: Find `list[dict]` of messages in current specific dialog that contain the given information. To refer to a message found later, use its `id` field.\n", |
1825 | 1871 | "- &`add_html`: Send HTML to the browser to be swapped into the DOM\n", |
1826 | 1872 | "- &`read_msg`: Get the message indexed in the current dialog.\n", |
|
1833 | 1879 | " - Use `content` param to update contents.\n", |
1834 | 1880 | " - Only include parameters to update--missing ones will be left unchanged.\n", |
1835 | 1881 | "- &`run_msg`: Adds a message to the run queue. Use read_msg to see the output once it runs.\n", |
1836 | | - "- &`url2note`: Read URL as markdown, and add a note below current message with the result\n", |
| 1882 | + "- &`url2note`: Read URL as markdown, and add note(s) below current message with the result\n", |
1837 | 1883 | "- &`ast_py`: Get an SgRoot root node for python `code`\n", |
1838 | 1884 | "- &`ast_grep`: Use the `ast-grep` command to find `pattern` in `path`\n", |
1839 | 1885 | "- &`msg_insert_line`: Insert text at a specific line number in a message\n", |
|
0 commit comments