|
26 | 26 | "outputs": [], |
27 | 27 | "source": [ |
28 | 28 | "#| export\n", |
29 | | -"import json,importlib,linecache\n", |
| 29 | +"import json,importlib,linecache,re,inspect\n", |
30 | 30 | "from typing import Dict\n", |
31 | 31 | "from tempfile import TemporaryDirectory\n", |
32 | 32 | "from ipykernel_helper import *\n", |
|
239 | 239 | { |
240 | 240 | "data": { |
241 | 241 | "text/plain": [ |
242 | | -"15" |
| 242 | +"14" |
243 | 243 | ] |
244 | 244 | }, |
245 | 245 | "execution_count":null, |
|
396 | 396 | "output_type":"stream", |
397 | 397 | "text": [ |
398 | 398 | "_9c544573\n", |
399 | | -"_34f2d6f2\n" |
| 399 | +"_35c17a89\n" |
400 | 400 | ] |
401 | 401 | } |
402 | 402 | ], |
|
535 | 535 | " dname:str='', # Running dialog to get info for; defaults to current dialog\n", |
536 | 536 | " **kwargs):\n", |
537 | 537 | "\"\"\"Update an existing message. Provide either `msg` OR field key/values to update.\n", |
538 | | -" Use `content` param to update contents.\n", |
539 | | -" Only include parameters to update--missing ones will be left unchanged.\"\"\"\n", |
| 538 | +"-Use `content` param to update contents.\n", |
| 539 | +"-Only include parameters to update--missing ones will be left unchanged.\"\"\"\n", |
540 | 540 | " if not msgid and not msg: raise TypeError(\"update_msg needs either a dict message or `msgid=`\")\n", |
541 | 541 | " res = call_endp('add_relative_', dname, placement='update', msgid=msgid, **kwargs)\n", |
542 | 542 | " set_var('__msg_id', res)\n", |
|
599 | 599 | " nums:bool=False, # Whether to show line numbers\n", |
600 | 600 | " dname:str='' # Running dialog to get info for; defaults to current dialog\n", |
601 | 601 | " ):\n", |
602 | | -"\"Get the `Message` object indexed in the current dialog.\"\n", |
| 602 | +"\"\"\"Get the message indexed in the current dialog.\n", |
| 603 | +" - To get the exact message use `n=0` and `relative=True` together with `msgid`.\n", |
| 604 | +" - To get a relative message use `n` (relative position index).\n", |
| 605 | +" - To get the nth message use `n` with `relative=False`, e.g `n=0` first message, `n=-1` last message.\"\"\"\n", |
603 | 606 | " if not msgid: msgid = find_msg_id()\n", |
604 | 607 | " data = dict(n=n, relative=relative, msgid=msgid)\n", |
605 | 608 | " if view_range: data['view_range'] = view_range # None gets converted to '' so we avoid passing it to use the p.default\n", |
|
697 | 700 | "execution_count":null, |
698 | 701 | "id":"6e354677", |
699 | 702 | "metadata": {}, |
700 | | -"outputs": [ |
701 | | - { |
702 | | -"data": { |
703 | | -"text/plain": [ |
704 | | -"2" |
705 | | - ] |
706 | | - }, |
707 | | -"execution_count":null, |
708 | | -"metadata": {}, |
709 | | -"output_type":"execute_result" |
710 | | - } |
711 | | - ], |
| 703 | +"outputs": [], |
712 | 704 | "source": [ |
713 | 705 | "1+1" |
714 | 706 | ] |
|
908 | 900 | { |
909 | 901 | "data": { |
910 | 902 | "text/plain": [ |
911 | | -"{'success': 'Inserted text after line 5 in message_65ee1825'}" |
| 903 | +"{'success': 'Inserted text after line 5 in message_84b2f8cd'}" |
912 | 904 | ] |
913 | 905 | }, |
914 | 906 | "execution_count":null, |
|
972 | 964 | { |
973 | 965 | "data": { |
974 | 966 | "text/plain": [ |
975 | | -"{'success': 'Replaced text in message_65ee1825'}" |
| 967 | +"{'success': 'Replaced text in message_84b2f8cd'}" |
976 | 968 | ] |
977 | 969 | }, |
978 | 970 | "execution_count":null, |
|
1034 | 1026 | { |
1035 | 1027 | "data": { |
1036 | 1028 | "text/plain": [ |
1037 | | -"{'success': 'Successfully replaced all the strings in message_65ee1825'}" |
| 1029 | +"{'success': 'Successfully replaced all the strings in message_84b2f8cd'}" |
1038 | 1030 | ] |
1039 | 1031 | }, |
1040 | 1032 | "execution_count":null, |
|
1097 | 1089 | { |
1098 | 1090 | "data": { |
1099 | 1091 | "text/plain": [ |
1100 | | -"{'success': 'Replaced lines 2 to 4 in message_65ee1825'}" |
| 1092 | +"{'success': 'Replaced lines 2 to 4 in message_84b2f8cd'}" |
1101 | 1093 | ] |
1102 | 1094 | }, |
1103 | 1095 | "execution_count":null, |
|
1482 | 1474 | "## Tool info" |
1483 | 1475 | ] |
1484 | 1476 | }, |
| 1477 | + { |
| 1478 | +"cell_type":"code", |
| 1479 | +"execution_count":null, |
| 1480 | +"id":"20d90262", |
| 1481 | +"metadata": {}, |
| 1482 | +"outputs": [], |
| 1483 | +"source": [ |
| 1484 | +"from dialoghelper.core import __all__ as _all" |
| 1485 | + ] |
| 1486 | + }, |
1485 | 1487 | { |
1486 | 1488 | "cell_type":"markdown", |
1487 | 1489 | "id":"cab73732", |
|
1526 | 1528 | { |
1527 | 1529 | "cell_type":"code", |
1528 | 1530 | "execution_count":null, |
1529 | | -"id":"0c2d443a", |
1530 | | -"metadata": {}, |
1531 | | -"outputs": [], |
1532 | | -"source": [ |
1533 | | -"from dialoghelper.core import __all__ as _all" |
1534 | | - ] |
1535 | | - }, |
1536 | | - { |
1537 | | -"cell_type":"code", |
1538 | | -"execution_count":null, |
1539 | | -"id":"75f9df8f", |
| 1531 | +"id":"609f529d", |
1540 | 1532 | "metadata": {}, |
1541 | 1533 | "outputs": [], |
1542 | 1534 | "source": [ |
|
1559 | 1551 | { |
1560 | 1552 | "cell_type":"code", |
1561 | 1553 | "execution_count":null, |
1562 | | -"id":"ccc6ffd1", |
| 1554 | +"id":"3b69cb19", |
1563 | 1555 | "metadata": {}, |
1564 | 1556 | "outputs": [ |
1565 | 1557 | { |
1566 | 1558 | "name":"stdout", |
1567 | 1559 | "output_type":"stream", |
1568 | 1560 | "text": [ |
1569 | | -"dh_settings\n", |
1570 | | -"Placements\n", |
1571 | | -"empty\n", |
1572 | | -"find_var\n", |
1573 | 1561 | "- &`find_var`: Search for var in all frames of the call stack\n", |
1574 | | -"set_var\n", |
1575 | 1562 | "- &`set_var`: Set var to val after finding it in all frames of the call stack\n", |
1576 | | -"call_endp\n", |
1577 | | -"find_dname\n", |
1578 | 1563 | "- &`find_dname`: Get the message id by searching the call stack for __dialog_id.\n", |
1579 | | -"find_msg_id\n", |
1580 | 1564 | "- &`find_msg_id`: Get the message id by searching the call stack for __dialog_id.\n", |
1581 | | -"curr_dialog\n", |
1582 | 1565 | "- &`curr_dialog`: Get the current dialog info.\n", |
1583 | | -"find_msgs\n", |
1584 | | -"- &`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", |
1585 | | -"msg_idx\n", |
1586 | 1566 | "- &`msg_idx`: Get absolute index of message in dialog.\n", |
1587 | | -"add_html\n", |
| 1567 | +"- &`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", |
1588 | 1568 | "- &`add_html`: Send HTML to the browser to be swapped into the DOM\n", |
1589 | | -"add_msg\n", |
1590 | 1569 | "- &`add_msg`: Add/update a message to the queue to show after code execution completes.\n", |
1591 | | -"del_msg\n", |
1592 | 1570 | "- &`del_msg`: Delete a message from the dialog.\n", |
1593 | | -"update_msg\n", |
1594 | 1571 | "- &`update_msg`: Update an existing message. Provide either `msg` OR field key/values to update.\n", |
1595 | | -" Use `content` param to update contents.\n", |
1596 | | -" Only include parameters to update--missing ones will be left unchanged.\n", |
1597 | | -"url2note\n", |
| 1572 | +" - Use `content` param to update contents.\n", |
| 1573 | +" - Only include parameters to update--missing ones will be left unchanged.\n", |
| 1574 | +"- &`read_msg`: Get the message indexed in the current dialog.\n", |
| 1575 | +" - To get the exact message use `n=0` and `relative=True` together with `msgid`.\n", |
| 1576 | +" - To get a relative message use `n` (relative position index).\n", |
| 1577 | +" - To get the nth message use `n` with `relative=False`, e.g `n=0` first message, `n=-1` last message.\n", |
| 1578 | +"- &`run_msg`: Adds a message to the run queue. Use read_msg to see the output once it runs.\n", |
1598 | 1579 | "- &`url2note`: Read URL as markdown, and add a note below current message with the result\n", |
1599 | | -"ast_py\n", |
1600 | 1580 | "- &`ast_py`: Get an SgRoot root node for python `code`\n", |
1601 | | -"ast_grep\n", |
1602 | 1581 | "- &`ast_grep`: Use the `ast-grep` command to find `pattern` in `path`\n", |
1603 | | -"read_msg\n", |
1604 | | -"- &`read_msg`: Get the `Message` object indexed in the current dialog.\n", |
1605 | | -"run_msg\n", |
1606 | | -"- &`run_msg`: Adds a message to the run queue. Use read_msg to see the output once it runs.\n", |
1607 | | -"msg_insert_line\n", |
1608 | 1582 | "- &`msg_insert_line`: Insert text at a specific line number in a message\n", |
1609 | | -"msg_str_replace\n", |
1610 | 1583 | "- &`msg_str_replace`: Replace first occurrence of old_str with new_str in a message\n", |
1611 | | -"msg_strs_replace\n", |
1612 | 1584 | "- &`msg_strs_replace`: Replace multiple strings simultaneously in a message\n", |
1613 | | -"msg_replace_lines\n", |
1614 | 1585 | "- &`msg_replace_lines`: Replace a range of lines with new content in a message\n", |
1615 | | -"load_gist\n", |
1616 | 1586 | "- &`load_gist`: Retrieve a gist\n", |
1617 | | -"gist_file\n", |
1618 | 1587 | "- &`gist_file`: Get the first file from a gist\n", |
1619 | | -"import_string\n", |
1620 | | -"is_usable_tool\n", |
1621 | 1588 | "- &`is_usable_tool`: True if the function has a docstring and all parameters have types, meaning that it can be used as an LLM tool.\n", |
1622 | | -"mk_toollist\n", |
1623 | | -"import_gist\n", |
1624 | | -"- &`import_gist`: Import gist directly from string without saving to disk\n", |
1625 | | -"tool_info\n", |
1626 | | -"fc_tool_info\n" |
| 1589 | +"- &`import_gist`: Import gist directly from string without saving to disk\n" |
1627 | 1590 | ] |
1628 | 1591 | } |
1629 | 1592 | ], |
1630 | 1593 | "source": [ |
1631 | 1594 | "for o in _all:\n", |
1632 | 1595 | " s = globals()[o]\n", |
1633 | | -" print(o)\n", |
1634 | 1596 | " if not hasattr(s, '__name__') or s.__name__[0]=='_' or not s.__doc__: continue\n", |
1635 | 1597 | " print(f'- &`{s.__name__}`: {s.__doc__}')" |
1636 | 1598 | ] |
|