Skip to content

Commit 8724bc6

Browse files
committed
fixes #222
1 parent 9e2fad0 commit 8724bc6

8 files changed

Lines changed: 29 additions & 110 deletions

File tree

dialoghelper/_modidx.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
'dialoghelper.core._iife_scr': ('core.html#_iife_scr', 'dialoghelper/core.py'),
2121
'dialoghelper.core._maybe_xml': ('core.html#_maybe_xml', 'dialoghelper/core.py'),
2222
'dialoghelper.core._msg_edit': ('core.html#_msg_edit', 'dialoghelper/core.py'),
23-
'dialoghelper.core._norm_lines': ('core.html#_norm_lines', 'dialoghelper/core.py'),
2423
'dialoghelper.core._prep_endp': ('core.html#_prep_endp', 'dialoghelper/core.py'),
2524
'dialoghelper.core._python_edit': ('core.html#_python_edit', 'dialoghelper/core.py'),
2625
'dialoghelper.core._umsg': ('core.html#_umsg', 'dialoghelper/core.py'),

dialoghelper/core.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -743,15 +743,6 @@ async def _one(mid):
743743
msg_strs_replace = _msg_edit (strs_replace, 'msg_strs_replace')
744744

745745

746-
# %% ../nbs/00_core.ipynb #7b11e714
747-
def _norm_lines(n:int, start:int, end:int=None):
748-
"Normalize and validate line range. Returns (start, end) or raises ValueError."
749-
if end is None: end = start
750-
if end < 0: end = n + end + 1
751-
if not (1 <= start <= n): raise ValueError(f'Invalid start line {start}. Valid range: 1-{n}')
752-
if not (start <= end <= n): raise ValueError(f'Invalid end line {end}. Valid range: {start}-{n}')
753-
return start, end
754-
755746
# %% ../nbs/00_core.ipynb #1002423f
756747
msg_replace_lines = _msg_edit (replace_lines, 'msg_replace_lines')
757748

@@ -772,13 +763,13 @@ async def _python_edit(
772763
msg_python = _msg_edit (_python_edit, 'msg_python')
773764

774765
# %% ../nbs/00_core.ipynb #11ee26d9
775-
def solveit_docs():
766+
async def solveit_docs():
776767
"""Full reference documentation for Solveit - use this to answer questions about how to use Solveit.
777768
**NB**: The whole docs fit in LLM context, so read the whole thing, don't search/filter it. *Always* re-run rather than relying on truncated history or assumptions."""
778769
_ref_gist_id = '9e7b444aba5ecf6d14295ba2cee890c3'
779770
pre = f"""⚠️ This content will be truncated in your next turn. Re-call this function if you need it again.
780771
If the user wants more info, give them a link to https://gist.github.com/jph00/{_ref_gist_id}."""
781-
return pre + GhApi().gist_file(_ref_gist_id)['content']
772+
return pre + (await GhApi().gist_file(_ref_gist_id))['content']
782773

783774
# %% ../nbs/00_core.ipynb #70ec67db
784775
def dialog_link(

dialoghelper/exhash.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
async def msg_lnhashview(
1313
id:str, # id of message to view
1414
dname:str='', # Dialog containing message; defaults to current dialog
15-
start:int=None, # Starting line (1-based) to view (defaults to 1st line if None)
16-
end:int=None, # End line (defaults to last line if None)
15+
start_line:int=None, # Starting line (1-based) to view (defaults to 1st line if None)
16+
end_line:int=None, # End line (defaults to last line if None)
1717
) -> str:
1818
"Show lnhash-addressed lines of a message"
1919
msg = await read_msgid(id=id, dname=dname)
2020
if not msg: return 'No such message.'
21-
return PrettyString('\n'.join(lnhashview(msg['content'], start=start, end=end)))
21+
return PrettyString('\n'.join(lnhashview(msg['content'], start=start_line, end=end_line)))
22+
2223

2324
# %% ../nbs/04_exhash.ipynb #9bdae034
2425
async def msg_exhash(

dialoghelper/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ async def ctx_repo(
144144
**kwargs
145145
):
146146
"Convert GitHub repo to XML context and place in a new message"
147-
res = repo2ctx(owner, repo, out=out, types=types, exts=exts, **kwargs)
147+
res = await repo2ctx(owner, repo, out=out, types=types, exts=exts, **kwargs)
148148
if exts: types=None
149149
if not raw: res = f'```\n{res}\n```'
150150
return await add_msg(res, msg_type='raw' if raw else 'note')
@@ -193,7 +193,7 @@ def import_string(
193193
def mk_toollist(syms):
194194
return "\n".join(f"- &`{sym.__name__}`: {sym.__doc__}" for sym in syms if is_usable_tool(sym))
195195

196-
# %% ../nbs/06_utils.ipynb #84868ea2
196+
# %% ../nbs/06_utils.ipynb #4d3e1b46
197197
def import_gist(
198198
gist_id:str, # user/id or just id of gist to import as a module
199199
mod_name:str=None, # module name to create (taken from gist filename if not passed)
@@ -202,7 +202,7 @@ def import_gist(
202202
create_msg:bool=False # Add a message that lists usable tools
203203
):
204204
"Import gist directly from string without saving to disk"
205-
fil = GhApi().gist_file(gist_id)
205+
fil = GhApi(sync=True).gist_file(gist_id)
206206
mod_name = mod_name or Path(fil['filename']).stem
207207
module = import_string(fil['content'], mod_name)
208208
glbs = currentframe().f_back.f_globals

nbs/00_core.ipynb

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,23 +2863,6 @@
28632863
"print((await read_msg(n=0, id=_edit_id, nums=True))['content'])"
28642864
]
28652865
},
2866-
{
2867-
"cell_type": "code",
2868-
"execution_count": null,
2869-
"id": "7b11e714",
2870-
"metadata": {},
2871-
"outputs": [],
2872-
"source": [
2873-
"#| export\n",
2874-
"def _norm_lines(n:int, start:int, end:int=None):\n",
2875-
" \"Normalize and validate line range. Returns (start, end) or raises ValueError.\"\n",
2876-
" if end is None: end = start\n",
2877-
" if end < 0: end = n + end + 1\n",
2878-
" if not (1 <= start <= n): raise ValueError(f'Invalid start line {start}. Valid range: 1-{n}')\n",
2879-
" if not (start <= end <= n): raise ValueError(f'Invalid end line {end}. Valid range: {start}-{n}')\n",
2880-
" return start, end"
2881-
]
2882-
},
28832866
{
28842867
"cell_type": "code",
28852868
"execution_count": null,
@@ -3144,13 +3127,13 @@
31443127
"outputs": [],
31453128
"source": [
31463129
"#| export\n",
3147-
"def solveit_docs():\n",
3130+
"async def solveit_docs():\n",
31483131
" \"\"\"Full reference documentation for Solveit - use this to answer questions about how to use Solveit.\n",
31493132
" **NB**: The whole docs fit in LLM context, so read the whole thing, don't search/filter it. *Always* re-run rather than relying on truncated history or assumptions.\"\"\"\n",
31503133
" _ref_gist_id = '9e7b444aba5ecf6d14295ba2cee890c3'\n",
31513134
" pre = f\"\"\"⚠️ This content will be truncated in your next turn. Re-call this function if you need it again.\n",
31523135
"If the user wants more info, give them a link to https://gist.github.com/jph00/{_ref_gist_id}.\"\"\"\n",
3153-
" return pre + GhApi().gist_file(_ref_gist_id)['content']"
3136+
" return pre + (await GhApi().gist_file(_ref_gist_id))['content']"
31543137
]
31553138
},
31563139
{

nbs/04_exhash.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@
6161
"async def msg_lnhashview(\n",
6262
" id:str, # id of message to view\n",
6363
" dname:str='', # Dialog containing message; defaults to current dialog\n",
64-
" start:int=None, # Starting line (1-based) to view (defaults to 1st line if None)\n",
65-
" end:int=None, # End line (defaults to last line if None)\n",
64+
" start_line:int=None, # Starting line (1-based) to view (defaults to 1st line if None)\n",
65+
" end_line:int=None, # End line (defaults to last line if None)\n",
6666
") -> str:\n",
6767
" \"Show lnhash-addressed lines of a message\"\n",
6868
" msg = await read_msgid(id=id, dname=dname)\n",
6969
" if not msg: return 'No such message.'\n",
70-
" return PrettyString('\\n'.join(lnhashview(msg['content'], start=start, end=end)))"
70+
" return PrettyString('\\n'.join(lnhashview(msg['content'], start=start_line, end=end_line)))\n"
7171
]
7272
},
7373
{

nbs/06_utils.ipynb

Lines changed: 13 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@
569569
" **kwargs\n",
570570
"):\n",
571571
" \"Convert GitHub repo to XML context and place in a new message\"\n",
572-
" res = repo2ctx(owner, repo, out=out, types=types, exts=exts, **kwargs)\n",
572+
" res = await repo2ctx(owner, repo, out=out, types=types, exts=exts, **kwargs)\n",
573573
" if exts: types=None\n",
574574
" if not raw: res = f'```\\n{res}\\n```'\n",
575575
" return await add_msg(res, msg_type='raw' if raw else 'note')"
@@ -749,7 +749,7 @@
749749
{
750750
"cell_type": "code",
751751
"execution_count": null,
752-
"id": "84868ea2",
752+
"id": "4d3e1b46",
753753
"metadata": {},
754754
"outputs": [],
755755
"source": [
@@ -762,7 +762,7 @@
762762
" create_msg:bool=False # Add a message that lists usable tools\n",
763763
"):\n",
764764
" \"Import gist directly from string without saving to disk\"\n",
765-
" fil = GhApi().gist_file(gist_id)\n",
765+
" fil = GhApi(sync=True).gist_file(gist_id)\n",
766766
" mod_name = mod_name or Path(fil['filename']).stem\n",
767767
" module = import_string(fil['content'], mod_name)\n",
768768
" glbs = currentframe().f_back.f_globals\n",
@@ -781,20 +781,9 @@
781781
{
782782
"cell_type": "code",
783783
"execution_count": null,
784-
"id": "aefee238",
784+
"id": "be823d4c",
785785
"metadata": {},
786-
"outputs": [
787-
{
788-
"data": {
789-
"text/plain": [
790-
"'testbar'"
791-
]
792-
},
793-
"execution_count": null,
794-
"metadata": {},
795-
"output_type": "execute_result"
796-
}
797-
],
786+
"outputs": [],
798787
"source": [
799788
"gistid = 'jph00/e7cfd4ded593e8ef6217e78a0131960c'\n",
800789
"import_gist(gistid)\n",
@@ -804,41 +793,19 @@
804793
{
805794
"cell_type": "code",
806795
"execution_count": null,
807-
"id": "4a4f7f89",
796+
"id": "d6c5b31a",
808797
"metadata": {},
809-
"outputs": [
810-
{
811-
"data": {
812-
"text/plain": [
813-
"'Import gist directly from string without saving to disk'"
814-
]
815-
},
816-
"execution_count": null,
817-
"metadata": {},
818-
"output_type": "execute_result"
819-
}
820-
],
798+
"outputs": [],
821799
"source": [
822800
"import_gist.__doc__"
823801
]
824802
},
825803
{
826804
"cell_type": "code",
827805
"execution_count": null,
828-
"id": "e80a7944",
806+
"id": "b76ed687",
829807
"metadata": {},
830-
"outputs": [
831-
{
832-
"data": {
833-
"text/plain": [
834-
"'testbar'"
835-
]
836-
},
837-
"execution_count": null,
838-
"metadata": {},
839-
"output_type": "execute_result"
840-
}
841-
],
808+
"outputs": [],
842809
"source": [
843810
"import_gist(gistid, import_wildcard=True)\n",
844811
"importtest.testfoo"
@@ -847,41 +814,19 @@
847814
{
848815
"cell_type": "code",
849816
"execution_count": null,
850-
"id": "573abb48",
817+
"id": "1c62fa89",
851818
"metadata": {},
852-
"outputs": [
853-
{
854-
"data": {
855-
"text/plain": [
856-
"'Hello Sarah'"
857-
]
858-
},
859-
"execution_count": null,
860-
"metadata": {},
861-
"output_type": "execute_result"
862-
}
863-
],
819+
"outputs": [],
864820
"source": [
865821
"hi(\"Sarah\")"
866822
]
867823
},
868824
{
869825
"cell_type": "code",
870826
"execution_count": null,
871-
"id": "392dc090",
827+
"id": "a32dd2d3",
872828
"metadata": {},
873-
"outputs": [
874-
{
875-
"data": {
876-
"text/plain": [
877-
"['hi', 'whoami']"
878-
]
879-
},
880-
"execution_count": null,
881-
"metadata": {},
882-
"output_type": "execute_result"
883-
}
884-
],
829+
"outputs": [],
885830
"source": [
886831
"importtest.__all__"
887832
]

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ keywords = ['nbdev', 'jupyter', 'notebook', 'python']
1414
classifiers = ["Natural Language :: English", "Intended Audience :: Developers", "Development Status :: 3 - Alpha",
1515
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only"]
1616
dependencies = [
17-
'fastcore>=1.13.4',
18-
'ghapi>=1.0.16',
17+
'fastcore>=1.14.3',
18+
'ghapi>=2.0.0',
1919
'ipykernel-helper>=0.0.28',
2020
'ipymini>=0.1.9',
2121
'MonsterUI',

0 commit comments

Comments
 (0)