dialoghelper 0.0.30__py3-none-any.whl → 0.0.32__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.

Potentially problematic release.


This version of dialoghelper might be problematic. Click here for more details.

dialoghelper/__init__.py CHANGED
@@ -1,2 +1,2 @@
1
- __version__ = "0.0.30"
1
+ __version__ = "0.0.32"
2
2
  from .core import *
dialoghelper/_modidx.py CHANGED
@@ -9,6 +9,8 @@ d = { 'settings': { 'branch': 'main',
9
9
  'dialoghelper.core._umsg': ('core.html#_umsg', 'dialoghelper/core.py'),
10
10
  'dialoghelper.core.add_html': ('core.html#add_html', 'dialoghelper/core.py'),
11
11
  'dialoghelper.core.add_msg': ('core.html#add_msg', 'dialoghelper/core.py'),
12
+ 'dialoghelper.core.ast_grep': ('core.html#ast_grep', 'dialoghelper/core.py'),
13
+ 'dialoghelper.core.ast_py': ('core.html#ast_py', 'dialoghelper/core.py'),
12
14
  'dialoghelper.core.call_endp': ('core.html#call_endp', 'dialoghelper/core.py'),
13
15
  'dialoghelper.core.curr_dialog': ('core.html#curr_dialog', 'dialoghelper/core.py'),
14
16
  'dialoghelper.core.del_msg': ('core.html#del_msg', 'dialoghelper/core.py'),
@@ -26,7 +28,8 @@ d = { 'settings': { 'branch': 'main',
26
28
  'dialoghelper.core.read_msg': ('core.html#read_msg', 'dialoghelper/core.py'),
27
29
  'dialoghelper.core.run_msg': ('core.html#run_msg', 'dialoghelper/core.py'),
28
30
  'dialoghelper.core.tool_info': ('core.html#tool_info', 'dialoghelper/core.py'),
29
- 'dialoghelper.core.update_msg': ('core.html#update_msg', 'dialoghelper/core.py')},
31
+ 'dialoghelper.core.update_msg': ('core.html#update_msg', 'dialoghelper/core.py'),
32
+ 'dialoghelper.core.url2note': ('core.html#url2note', 'dialoghelper/core.py')},
30
33
  'dialoghelper.db_dc': {},
31
34
  'dialoghelper.experimental': { 'dialoghelper.experimental._pop_data': ( 'experimental.html#_pop_data',
32
35
  'dialoghelper/experimental.py'),
dialoghelper/core.py CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  # %% auto 0
4
4
  __all__ = ['Placements', 'empty', 'find_var', 'call_endp', 'find_dname', 'find_msg_id', 'curr_dialog', 'find_msgs', 'msg_idx',
5
- 'read_msg', 'add_html', 'del_msg', 'run_msg', 'add_msg', 'update_msg', 'load_gist', 'gist_file',
6
- 'import_string', 'is_usable_tool', 'mk_toollist', 'import_gist', 'tool_info', 'asdict']
5
+ 'read_msg', 'add_html', 'run_msg', 'add_msg', 'del_msg', 'update_msg', 'url2note', 'ast_py', 'ast_grep',
6
+ 'load_gist', 'gist_file', 'import_string', 'is_usable_tool', 'mk_toollist', 'import_gist', 'tool_info',
7
+ 'asdict']
7
8
 
8
9
  # %% ../nbs/00_core.ipynb
9
10
  import json, importlib, linecache
@@ -106,14 +107,6 @@ def add_html(
106
107
  "Send HTML to the browser to be swapped into the DOM"
107
108
  call_endp('add_html_', dname, content=to_xml(content))
108
109
 
109
- # %% ../nbs/00_core.ipynb
110
- def del_msg(
111
- msgid:str=None, # id of message to delete
112
- dname:str='' # Running dialog to get info for; defaults to current dialog
113
- ):
114
- "Delete a message from the dialog."
115
- call_endp('rm_msg_', dname, raiseex=True, msid=msgid)
116
-
117
110
  # %% ../nbs/00_core.ipynb
118
111
  def run_msg(
119
112
  msgid:str=None, # id of message to execute
@@ -148,6 +141,14 @@ def add_msg(
148
141
  time_run=time_run, is_exported=is_exported, skipped=skipped, pinned=pinned,
149
142
  i_collapsed=i_collapsed, o_collapsed=o_collapsed, heading_collapsed=heading_collapsed)
150
143
 
144
+ # %% ../nbs/00_core.ipynb
145
+ def del_msg(
146
+ msgid:str=None, # id of message to delete
147
+ dname:str='' # Running dialog to get info for; defaults to current dialog
148
+ ):
149
+ "Delete a message from the dialog."
150
+ call_endp('rm_msg_', dname, raiseex=True, msid=msgid)
151
+
151
152
  # %% ../nbs/00_core.ipynb
152
153
  @delegates(add_msg)
153
154
  def _add_msg_unsafe(
@@ -155,12 +156,12 @@ def _add_msg_unsafe(
155
156
  placement:str='add_after', # Can be 'add_after', 'add_before', 'at_start', 'at_end'
156
157
  msgid:str=None, # id of message that placement is relative to (if None, uses current message)
157
158
  run:bool=False, # For prompts, send it to the AI; for code, execute it (*DANGEROUS -- be careful of what you run!)
159
+ dname:str='', # Running dialog to get info for; defaults to current dialog
158
160
  **kwargs
159
161
  ):
160
162
  """Add/update a message to the queue to show after code execution completes, and optionally run it. Be sure to pass a `sid` (stable id) not a `mid` (which is used only for sorting, and can change).
161
163
  *WARNING*--This can execute arbitrary code, so check carefully what you run!--*WARNING"""
162
164
  if placement not in ('at_start','at_end') and not msgid: msgid = find_msg_id()
163
- dname = kwargs.pop('dname')
164
165
  return call_endp(
165
166
  'add_relative_', dname, content=content, placement=placement, msgid=msgid, run=run, **kwargs)
166
167
 
@@ -191,6 +192,35 @@ def update_msg(
191
192
  if not msgid and not msg: raise TypeError("update_msg needs either a dict message or `msgid=`")
192
193
  return call_endp('add_relative_', dname, placement='update', msgid=msgid, **kwargs)
193
194
 
195
+ # %% ../nbs/00_core.ipynb
196
+ def url2note(
197
+ url:str, # URL to read
198
+ extract_section:bool=True, # If url has an anchor, return only that section
199
+ selector:str=None # Select section(s) using BeautifulSoup.select (overrides extract_section)
200
+ ):
201
+ "Read URL as markdown, and add a note below current message with the result"
202
+ res = read_url(url, as_md=True, extract_section=extract_section, selector=selector)
203
+ return add_msg(res)
204
+
205
+ # %% ../nbs/00_core.ipynb
206
+ def ast_py(code:str):
207
+ "Get an SgRoot root node for python `code`"
208
+ from ast_grep_py import SgRoot
209
+ return SgRoot(code, "python").root()
210
+
211
+ # %% ../nbs/00_core.ipynb
212
+ def ast_grep(
213
+ pattern:str, # ast-grep pattern to search
214
+ path=".", # path to recursively search for files
215
+ lang="python" # language to search/scan
216
+ ):
217
+ "Use the `ast-grep` command to find `pattern` in `path`"
218
+ import json, subprocess
219
+ cmd = f"ast-grep --pattern '{pattern}' --lang {lang} --json=compact"
220
+ if path != ".": cmd = f"cd {path} && {cmd}"
221
+ res = subprocess.run(cmd, shell=True, capture_output=True, text=True)
222
+ return json.loads(res.stdout) if res.stdout else res.stderr
223
+
194
224
  # %% ../nbs/00_core.ipynb
195
225
  def load_gist(gist_id:str):
196
226
  "Retrieve a gist"
@@ -270,5 +300,6 @@ def tool_info():
270
300
  - &`read_msg`: Get the message indexed in the current dialog.
271
301
  - &`del_msg`: Delete a message from the dialog.
272
302
  - &`add_msg`: Add/update a message to the queue to show after code execution completes.
273
- - &`update_msg`: Update an existing message.'''
303
+ - &`update_msg`: Update an existing message.
304
+ - &`url2note`: Read URL as markdown, and add a note below current message with the result'''
274
305
  add_msg(cts)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.30
3
+ Version: 0.0.32
4
4
  Summary: Helper functions for solveit dialogs
5
5
  Home-page: https://github.com/AnswerDotAI/dialoghelper
6
6
  Author: Jeremy Howard
@@ -23,6 +23,8 @@ Requires-Dist: fastlite
23
23
  Requires-Dist: ghapi
24
24
  Requires-Dist: ipykernel-helper
25
25
  Requires-Dist: claudette
26
+ Requires-Dist: ast-grep-cli
27
+ Requires-Dist: ast-grep-py
26
28
  Provides-Extra: dev
27
29
  Requires-Dist: python-fasthtml; extra == "dev"
28
30
  Dynamic: author
@@ -0,0 +1,12 @@
1
+ dialoghelper/__init__.py,sha256=xCO6wIOmUkstMqdlaHvUJ0lO8rN3Pp5NRbeq65mLndE,43
2
+ dialoghelper/_modidx.py,sha256=uC3rfgmEe6SwBeLiFhlxx_F-v9TxiPDTpx-QZX9m_V0,4608
3
+ dialoghelper/core.py,sha256=UTan-A1j8bkRTg9ojvE4P5LPvapV1a3QChF8PVbjObw,13650
4
+ dialoghelper/db_dc.py,sha256=mi2Q2am_SoAPGpNQg7KPFS5pR9WEapRXT8ypkNmMfw0,2330
5
+ dialoghelper/experimental.py,sha256=yTXzyY37MPW-9mqzbem-q6CCPXElN0GwAyOK-iJofMY,3910
6
+ dialoghelper/screenshot.js,sha256=DDqlRhemwj8I0AloxMJBnBqDDIqu5knlT1lpG_0rphI,4851
7
+ dialoghelper-0.0.32.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
+ dialoghelper-0.0.32.dist-info/METADATA,sha256=R5fK2Xh4GLnxoIGlXFrpPtSX_67W8B0v6qtG-wD0t2Q,2692
9
+ dialoghelper-0.0.32.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ dialoghelper-0.0.32.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
11
+ dialoghelper-0.0.32.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
12
+ dialoghelper-0.0.32.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- dialoghelper/__init__.py,sha256=Y4J_58Un2NkktVq246vbfUB1fr9alL7LxlQNIsZE5ec,43
2
- dialoghelper/_modidx.py,sha256=Au4FWcKVoSRyKPwVeiqCCKTL8cZ2vGPnjgk4FQfMlyg,4273
3
- dialoghelper/core.py,sha256=c7wGjFYucWTCDfOYGex3QX728elUdqGR34FfxsspvsA,12319
4
- dialoghelper/db_dc.py,sha256=mi2Q2am_SoAPGpNQg7KPFS5pR9WEapRXT8ypkNmMfw0,2330
5
- dialoghelper/experimental.py,sha256=yTXzyY37MPW-9mqzbem-q6CCPXElN0GwAyOK-iJofMY,3910
6
- dialoghelper/screenshot.js,sha256=DDqlRhemwj8I0AloxMJBnBqDDIqu5knlT1lpG_0rphI,4851
7
- dialoghelper-0.0.30.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
- dialoghelper-0.0.30.dist-info/METADATA,sha256=PhB6_-rVkKRmbPunN35xi7qJpZ1HeS7BQkjOXCGQpcY,2637
9
- dialoghelper-0.0.30.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- dialoghelper-0.0.30.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
11
- dialoghelper-0.0.30.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
12
- dialoghelper-0.0.30.dist-info/RECORD,,