dialoghelper 0.0.34__py3-none-any.whl → 0.0.35__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.
dialoghelper/__init__.py CHANGED
@@ -1,2 +1,2 @@
1
- __version__ = "0.0.34"
1
+ __version__ = "0.0.35"
2
2
  from .core import *
dialoghelper/_modidx.py CHANGED
@@ -26,6 +26,10 @@ d = { 'settings': { 'branch': 'main',
26
26
  'dialoghelper.core.load_gist': ('core.html#load_gist', 'dialoghelper/core.py'),
27
27
  'dialoghelper.core.mk_toollist': ('core.html#mk_toollist', 'dialoghelper/core.py'),
28
28
  'dialoghelper.core.msg_idx': ('core.html#msg_idx', 'dialoghelper/core.py'),
29
+ 'dialoghelper.core.msg_insert_line': ('core.html#msg_insert_line', 'dialoghelper/core.py'),
30
+ 'dialoghelper.core.msg_replace_lines': ('core.html#msg_replace_lines', 'dialoghelper/core.py'),
31
+ 'dialoghelper.core.msg_str_replace': ('core.html#msg_str_replace', 'dialoghelper/core.py'),
32
+ 'dialoghelper.core.msg_strs_replace': ('core.html#msg_strs_replace', 'dialoghelper/core.py'),
29
33
  'dialoghelper.core.read_msg': ('core.html#read_msg', 'dialoghelper/core.py'),
30
34
  'dialoghelper.core.run_msg': ('core.html#run_msg', 'dialoghelper/core.py'),
31
35
  'dialoghelper.core.tool_info': ('core.html#tool_info', 'dialoghelper/core.py'),
dialoghelper/core.py CHANGED
@@ -2,9 +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', '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
- 'fc_tool_info', 'asdict']
5
+ 'add_html', 'add_msg', 'del_msg', 'update_msg', 'url2note', 'ast_py', 'ast_grep', 'read_msg', 'run_msg',
6
+ 'msg_insert_line', 'msg_str_replace', 'msg_strs_replace', 'msg_replace_lines', 'load_gist', 'gist_file',
7
+ 'import_string', 'is_usable_tool', 'mk_toollist', 'import_gist', 'tool_info', 'fc_tool_info', 'asdict']
8
8
 
9
9
  # %% ../nbs/00_core.ipynb
10
10
  import json, importlib, linecache
@@ -88,17 +88,6 @@ def msg_idx(
88
88
  if not msgid: msgid = find_msg_id()
89
89
  return call_endp('msg_idx_', dname, json=True, msgid=msgid)['msgid']
90
90
 
91
- # %% ../nbs/00_core.ipynb
92
- def read_msg(
93
- n:int=-1, # Message index (if relative, +ve is downwards)
94
- msgid=None, # Message id to find (defaults to current message)
95
- relative:bool=True, # Is `n` relative to current message (True) or absolute (False)?
96
- dname:str='' # Running dialog to get info for; defaults to current dialog
97
- ):
98
- "Get the `Message` object indexed in the current dialog."
99
- if not msgid: msgid = find_msg_id()
100
- return call_endp('read_msg_', dname, json=True, msgid=msgid, n=n, relative=relative)['msg']
101
-
102
91
  # %% ../nbs/00_core.ipynb
103
92
  def add_html(
104
93
  content:str, # The HTML to send to the client (generally should include hx-swap-oob)
@@ -107,14 +96,6 @@ def add_html(
107
96
  "Send HTML to the browser to be swapped into the DOM"
108
97
  call_endp('add_html_', dname, content=to_xml(content))
109
98
 
110
- # %% ../nbs/00_core.ipynb
111
- def run_msg(
112
- msgid:str=None, # id of message to execute
113
- dname:str='' # Running dialog to get info for; defaults to current dialog
114
- ):
115
- "Adds a message to the run queue. Use read_msg to see the output once it runs."
116
- return call_endp('add_runq_', dname, msgid=msgid, api=True)
117
-
118
99
  # %% ../nbs/00_core.ipynb
119
100
  Placements = str_enum('Placements', 'add_after', 'add_before', 'at_start', 'at_end')
120
101
 
@@ -221,6 +202,71 @@ def ast_grep(
221
202
  res = subprocess.run(cmd, shell=True, capture_output=True, text=True)
222
203
  return json.loads(res.stdout) if res.stdout else res.stderr
223
204
 
205
+ # %% ../nbs/00_core.ipynb
206
+ def read_msg(
207
+ n:int=-1, # Message index (if relative, +ve is downwards)
208
+ relative:bool=True, # Is `n` relative to current message (True) or absolute (False)?
209
+ msgid:str=None, # Message id to find (defaults to current message)
210
+ view_range:list[int,int]=None, # Optional 1-indexed (start, end) line range for files, end=-1 for EOF
211
+ nums:bool=False, # Whether to show line numbers
212
+ dname:str='' # Running dialog to get info for; defaults to current dialog
213
+ ):
214
+ "Get the `Message` object indexed in the current dialog."
215
+ if not msgid: msgid = find_msg_id()
216
+ data = dict(n=n, relative=relative, msgid=msgid)
217
+ if view_range: data['view_range'] = view_range # None gets converted to '' so we avoid passing it to use the p.default
218
+ if nums: data['nums'] = nums
219
+ return call_endp('read_msg_', dname, json=True, **data)
220
+
221
+ # %% ../nbs/00_core.ipynb
222
+ def run_msg(
223
+ msgid:str=None, # id of message to execute
224
+ dname:str='' # Running dialog to get info for; defaults to current dialog
225
+ ):
226
+ "Adds a message to the run queue. Use read_msg to see the output once it runs."
227
+ return call_endp('add_runq_', dname, msgid=msgid, api=True)
228
+
229
+ # %% ../nbs/00_core.ipynb
230
+ def msg_insert_line(
231
+ msgid:str, # Message id to edit
232
+ insert_line: int, # The line number after which to insert the text (0 for beginning of file)
233
+ new_str: str, # The text to insert
234
+ dname:str='' # Running dialog to get info for; defaults to current dialog
235
+ ):
236
+ "Insert text at a specific line number in a message"
237
+ return call_endp('msg_insert_line_', dname, json=True, msgid=msgid, insert_line=insert_line, new_str=new_str)
238
+
239
+ # %% ../nbs/00_core.ipynb
240
+ def msg_str_replace(
241
+ msgid:str, # Message id to edit
242
+ old_str: str, # Text to find and replace
243
+ new_str: str, # Text to replace with
244
+ dname:str='' # Running dialog to get info for; defaults to current dialog
245
+ ):
246
+ "Replace first occurrence of old_str with new_str in a message"
247
+ return call_endp('msg_str_replace_', dname, json=True, msgid=msgid, old_str=old_str, new_str=new_str)
248
+
249
+ # %% ../nbs/00_core.ipynb
250
+ def msg_strs_replace(
251
+ msgid:str, # Message id to edit
252
+ old_strs:list[str], # List of strings to find and replace
253
+ new_strs:list[str], # List of replacement strings (must match length of old_strs)
254
+ dname:str='' # Running dialog to get info for; defaults to current dialog
255
+ ):
256
+ "Replace multiple strings simultaneously in a message"
257
+ return call_endp('msg_strs_replace_', dname, json=True, msgid=msgid, old_strs=old_strs, new_strs=new_strs)
258
+
259
+ # %% ../nbs/00_core.ipynb
260
+ def msg_replace_lines(
261
+ msgid:str, # Message id to edit
262
+ start_line:int, # Starting line number to replace (1-based indexing)
263
+ end_line:int, # Ending line number to replace (1-based indexing, inclusive)
264
+ new_content:str, # New content to replace the specified lines
265
+ dname:str='' # Running dialog to get info for; defaults to current dialog
266
+ ):
267
+ "Replace a range of lines with new content in a message"
268
+ return call_endp('msg_replace_lines_', dname, json=True, msgid=msgid, start_line=start_line, end_line=end_line, new_content=new_content)
269
+
224
270
  # %% ../nbs/00_core.ipynb
225
271
  def load_gist(gist_id:str):
226
272
  "Retrieve a gist"
@@ -298,10 +344,18 @@ def tool_info():
298
344
  - &`find_msgs`: Find messages in current specific dialog that contain the given information.
299
345
  - (solveit can often get this id directly from its context, and will not need to use this if the required information is already available to it.)
300
346
  - &`read_msg`: Get the message indexed in the current dialog.
347
+ - To get the exact message use `n=0` and `relative=True` together with `msgid`.
348
+ - To get a relative message use `n` (relative position index).
349
+ - To get the nth message use `n` with `relative=False`, e.g `n=0` first message, `n=-1` last message.
301
350
  - &`del_msg`: Delete a message from the dialog.
302
351
  - &`add_msg`: Add/update a message to the queue to show after code execution completes.
303
352
  - &`update_msg`: Update an existing message.
304
- - &`url2note`: Read URL as markdown, and add a note below current message with the result'''
353
+ - &`url2note`: Read URL as markdown, and add a note below current message with the result
354
+ - &`msg_insert_line`: Insert text at a specific location in a message.
355
+ - &`msg_str_replace`: Find and replace text in a message.
356
+ - &`msg_strs_replace`: Find and replace multiple strings in a message.
357
+ - &`msg_replace_lines`: Replace a range of lines in a message with new content.
358
+ - Always first use `read_msg( msgid=msgid, n=0, relative=True, nums=True)` to view the content with line numbers.'''
305
359
  add_msg(cts)
306
360
 
307
361
  # %% ../nbs/00_core.ipynb
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.34
3
+ Version: 0.0.35
4
4
  Summary: Helper functions for solveit dialogs
5
5
  Home-page: https://github.com/AnswerDotAI/dialoghelper
6
6
  Author: Jeremy Howard
@@ -0,0 +1,12 @@
1
+ dialoghelper/__init__.py,sha256=nXRRWJpKFa9Fjsny-pNH8T_A-gGKLYZSnNT-NX70XbI,43
2
+ dialoghelper/_modidx.py,sha256=ivpKN2mT49JlnSFMiyGaNwIKo8AUckJ_gf78haqTJr0,5243
3
+ dialoghelper/core.py,sha256=_-kEJFjnSnS24l0KQ5-NxnHAeAqjHtCujjBxYVm2wu8,17492
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.35.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
+ dialoghelper-0.0.35.dist-info/METADATA,sha256=L6Wmq1Qm1ZqccjP3da6LmwcwlJxRRP6ctPG1jQSEV5Q,2693
9
+ dialoghelper-0.0.35.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ dialoghelper-0.0.35.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
11
+ dialoghelper-0.0.35.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
12
+ dialoghelper-0.0.35.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- dialoghelper/__init__.py,sha256=8mcogOZ_ie-Z3aJVBiQMnD1KSBbRomzzoqbVQ6PCn-c,43
2
- dialoghelper/_modidx.py,sha256=eTbxI20Yc34F1iYVMWScgfT2dHd3QeGr6WyyIAB-LKY,4729
3
- dialoghelper/core.py,sha256=O3hp7LttumSifEN4y4M6l2JtYE5rpj52pmQP8gTCxSM,14453
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.34.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
- dialoghelper-0.0.34.dist-info/METADATA,sha256=ru47XjciRC5vJ-d-oX5pvvzYbh613fSZOSAiPtB3y4Y,2693
9
- dialoghelper-0.0.34.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- dialoghelper-0.0.34.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
11
- dialoghelper-0.0.34.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
12
- dialoghelper-0.0.34.dist-info/RECORD,,