Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitccc14bd

Browse files
committed
docs
1 parent50edaf1 commitccc14bd

File tree

2 files changed

+42
-77
lines changed

2 files changed

+42
-77
lines changed

‎dialoghelper/core.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'fc_tool_info']
99

1010
# %% ../nbs/00_core.ipynb
11-
importjson,importlib,linecache
11+
importjson,importlib,linecache,re,inspect
1212
fromtypingimportDict
1313
fromtempfileimportTemporaryDirectory
1414
fromipykernel_helperimport*
@@ -178,8 +178,8 @@ def update_msg(
178178
dname:str='',# Running dialog to get info for; defaults to current dialog
179179
**kwargs):
180180
"""Update an existing message. Provide either `msg` OR field key/values to update.
181-
Use `content` param to update contents.
182-
Only include parameters to update--missing ones will be left unchanged."""
181+
-Use `content` param to update contents.
182+
-Only include parameters to update--missing ones will be left unchanged."""
183183
ifnotmsgidandnotmsg:raiseTypeError("update_msg needs either a dict message or `msgid=`")
184184
res=call_endp('add_relative_',dname,placement='update',msgid=msgid,**kwargs)
185185
set_var('__msg_id',res)
@@ -194,7 +194,10 @@ def read_msg(
194194
nums:bool=False,# Whether to show line numbers
195195
dname:str=''# Running dialog to get info for; defaults to current dialog
196196
):
197-
"Get the `Message` object indexed in the current dialog."
197+
"""Get the message indexed in the current dialog.
198+
- To get the exact message use `n=0` and `relative=True` together with `msgid`.
199+
- To get a relative message use `n` (relative position index).
200+
- To get the nth message use `n` with `relative=False`, e.g `n=0` first message, `n=-1` last message."""
198201
ifnotmsgid:msgid=find_msg_id()
199202
data=dict(n=n,relative=relative,msgid=msgid)
200203
ifview_range:data['view_range']=view_range# None gets converted to '' so we avoid passing it to use the p.default

‎nbs/00_core.ipynb‎

Lines changed: 35 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"outputs": [],
2727
"source": [
2828
"#| export\n",
29-
"import json,importlib,linecache\n",
29+
"import json,importlib,linecache,re,inspect\n",
3030
"from typing import Dict\n",
3131
"from tempfile import TemporaryDirectory\n",
3232
"from ipykernel_helper import *\n",
@@ -239,7 +239,7 @@
239239
{
240240
"data": {
241241
"text/plain": [
242-
"15"
242+
"14"
243243
]
244244
},
245245
"execution_count":null,
@@ -396,7 +396,7 @@
396396
"output_type":"stream",
397397
"text": [
398398
"_9c544573\n",
399-
"_34f2d6f2\n"
399+
"_35c17a89\n"
400400
]
401401
}
402402
],
@@ -535,8 +535,8 @@
535535
" dname:str='', # Running dialog to get info for; defaults to current dialog\n",
536536
" **kwargs):\n",
537537
"\"\"\"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",
540540
" if not msgid and not msg: raise TypeError(\"update_msg needs either a dict message or `msgid=`\")\n",
541541
" res = call_endp('add_relative_', dname, placement='update', msgid=msgid, **kwargs)\n",
542542
" set_var('__msg_id', res)\n",
@@ -599,7 +599,10 @@
599599
" nums:bool=False, # Whether to show line numbers\n",
600600
" dname:str='' # Running dialog to get info for; defaults to current dialog\n",
601601
" ):\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",
603606
" if not msgid: msgid = find_msg_id()\n",
604607
" data = dict(n=n, relative=relative, msgid=msgid)\n",
605608
" if view_range: data['view_range'] = view_range # None gets converted to '' so we avoid passing it to use the p.default\n",
@@ -697,18 +700,7 @@
697700
"execution_count":null,
698701
"id":"6e354677",
699702
"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": [],
712704
"source": [
713705
"1+1"
714706
]
@@ -908,7 +900,7 @@
908900
{
909901
"data": {
910902
"text/plain": [
911-
"{'success': 'Inserted text after line 5 in message_65ee1825'}"
903+
"{'success': 'Inserted text after line 5 in message_84b2f8cd'}"
912904
]
913905
},
914906
"execution_count":null,
@@ -972,7 +964,7 @@
972964
{
973965
"data": {
974966
"text/plain": [
975-
"{'success': 'Replaced text in message_65ee1825'}"
967+
"{'success': 'Replaced text in message_84b2f8cd'}"
976968
]
977969
},
978970
"execution_count":null,
@@ -1034,7 +1026,7 @@
10341026
{
10351027
"data": {
10361028
"text/plain": [
1037-
"{'success': 'Successfully replaced all the strings in message_65ee1825'}"
1029+
"{'success': 'Successfully replaced all the strings in message_84b2f8cd'}"
10381030
]
10391031
},
10401032
"execution_count":null,
@@ -1097,7 +1089,7 @@
10971089
{
10981090
"data": {
10991091
"text/plain": [
1100-
"{'success': 'Replaced lines 2 to 4 in message_65ee1825'}"
1092+
"{'success': 'Replaced lines 2 to 4 in message_84b2f8cd'}"
11011093
]
11021094
},
11031095
"execution_count":null,
@@ -1482,6 +1474,16 @@
14821474
"## Tool info"
14831475
]
14841476
},
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+
},
14851487
{
14861488
"cell_type":"markdown",
14871489
"id":"cab73732",
@@ -1526,17 +1528,7 @@
15261528
{
15271529
"cell_type":"code",
15281530
"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",
15401532
"metadata": {},
15411533
"outputs": [],
15421534
"source": [
@@ -1559,78 +1551,48 @@
15591551
{
15601552
"cell_type":"code",
15611553
"execution_count":null,
1562-
"id":"ccc6ffd1",
1554+
"id":"3b69cb19",
15631555
"metadata": {},
15641556
"outputs": [
15651557
{
15661558
"name":"stdout",
15671559
"output_type":"stream",
15681560
"text": [
1569-
"dh_settings\n",
1570-
"Placements\n",
1571-
"empty\n",
1572-
"find_var\n",
15731561
"- &`find_var`: Search for var in all frames of the call stack\n",
1574-
"set_var\n",
15751562
"- &`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",
15781563
"- &`find_dname`: Get the message id by searching the call stack for __dialog_id.\n",
1579-
"find_msg_id\n",
15801564
"- &`find_msg_id`: Get the message id by searching the call stack for __dialog_id.\n",
1581-
"curr_dialog\n",
15821565
"- &`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",
15861566
"- &`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",
15881568
"- &`add_html`: Send HTML to the browser to be swapped into the DOM\n",
1589-
"add_msg\n",
15901569
"- &`add_msg`: Add/update a message to the queue to show after code execution completes.\n",
1591-
"del_msg\n",
15921570
"- &`del_msg`: Delete a message from the dialog.\n",
1593-
"update_msg\n",
15941571
"- &`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",
15981579
"- &`url2note`: Read URL as markdown, and add a note below current message with the result\n",
1599-
"ast_py\n",
16001580
"- &`ast_py`: Get an SgRoot root node for python `code`\n",
1601-
"ast_grep\n",
16021581
"- &`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",
16081582
"- &`msg_insert_line`: Insert text at a specific line number in a message\n",
1609-
"msg_str_replace\n",
16101583
"- &`msg_str_replace`: Replace first occurrence of old_str with new_str in a message\n",
1611-
"msg_strs_replace\n",
16121584
"- &`msg_strs_replace`: Replace multiple strings simultaneously in a message\n",
1613-
"msg_replace_lines\n",
16141585
"- &`msg_replace_lines`: Replace a range of lines with new content in a message\n",
1615-
"load_gist\n",
16161586
"- &`load_gist`: Retrieve a gist\n",
1617-
"gist_file\n",
16181587
"- &`gist_file`: Get the first file from a gist\n",
1619-
"import_string\n",
1620-
"is_usable_tool\n",
16211588
"- &`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"
16271590
]
16281591
}
16291592
],
16301593
"source": [
16311594
"for o in _all:\n",
16321595
" s = globals()[o]\n",
1633-
" print(o)\n",
16341596
" if not hasattr(s, '__name__') or s.__name__[0]=='_' or not s.__doc__: continue\n",
16351597
" print(f'- &`{s.__name__}`: {s.__doc__}')"
16361598
]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp