dialoghelper 0.0.12__tar.gz → 0.0.14__tar.gz

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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.12
3
+ Version: 0.0.14
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,2 @@
1
+ __version__ = "0.0.14"
2
+ from .core import *
@@ -5,10 +5,11 @@ d = { 'settings': { 'branch': 'main',
5
5
  'doc_host': 'https://AnswerDotAI.github.io',
6
6
  'git_url': 'https://github.com/AnswerDotAI/dialoghelper',
7
7
  'lib_path': 'dialoghelper'},
8
- 'syms': { 'dialoghelper.core': { 'dialoghelper.core._msg': ('core.html#_msg', 'dialoghelper/core.py'),
8
+ 'syms': { 'dialoghelper.core': { 'dialoghelper.core._add_msg_unsafe': ('core.html#_add_msg_unsafe', 'dialoghelper/core.py'),
9
+ 'dialoghelper.core._msg': ('core.html#_msg', 'dialoghelper/core.py'),
9
10
  'dialoghelper.core._umsg': ('core.html#_umsg', 'dialoghelper/core.py'),
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.del_msg': ('core.html#del_msg', 'dialoghelper/core.py'),
12
13
  'dialoghelper.core.export_dialog': ('core.html#export_dialog', 'dialoghelper/core.py'),
13
14
  'dialoghelper.core.find_dialog_id': ('core.html#find_dialog_id', 'dialoghelper/core.py'),
14
15
  'dialoghelper.core.find_msg_id': ('core.html#find_msg_id', 'dialoghelper/core.py'),
@@ -25,5 +26,6 @@ d = { 'settings': { 'branch': 'main',
25
26
  'dialoghelper.core.msg_idx': ('core.html#msg_idx', 'dialoghelper/core.py'),
26
27
  'dialoghelper.core.read_msg': ('core.html#read_msg', 'dialoghelper/core.py'),
27
28
  'dialoghelper.core.read_msg_ids': ('core.html#read_msg_ids', 'dialoghelper/core.py'),
29
+ 'dialoghelper.core.tool_info': ('core.html#tool_info', 'dialoghelper/core.py'),
28
30
  'dialoghelper.core.update_msg': ('core.html#update_msg', 'dialoghelper/core.py')},
29
31
  'dialoghelper.db_dc': {}}}
@@ -2,8 +2,8 @@
2
2
 
3
3
  # %% auto 0
4
4
  __all__ = ['Placements', 'empty', 'get_db', 'find_var', 'find_dialog_id', 'find_msgs', 'find_msg_id', 'read_msg_ids', 'msg_idx',
5
- 'read_msg', 'add_msg', 'update_msg', 'add_html', 'load_gist', 'gist_file', 'import_string', 'is_usable_tool',
6
- 'mk_toollist', 'import_gist', 'export_dialog', 'import_dialog', 'asdict']
5
+ 'read_msg', 'del_msg', 'add_msg', 'update_msg', 'load_gist', 'gist_file', 'import_string', 'is_usable_tool',
6
+ 'mk_toollist', 'import_gist', 'export_dialog', 'import_dialog', 'tool_info', 'asdict']
7
7
 
8
8
  # %% ../nbs/00_core.ipynb
9
9
  import json, importlib, linecache
@@ -18,6 +18,9 @@ from ghapi.all import *
18
18
  from fastlite import *
19
19
  from fastcore.xtras import asdict
20
20
  from inspect import currentframe,Parameter,signature
21
+ from httpx import get as xget, post as xpost
22
+ from .core import __all__ as _all
23
+ from IPython.display import display,Markdown
21
24
 
22
25
  # %% ../nbs/00_core.ipynb
23
26
  _all_ = ["asdict"]
@@ -54,8 +57,8 @@ def find_msgs(
54
57
  msg_type:str=None, # optional limit by message type ('code', 'note', or 'prompt')
55
58
  limit:int=None, # Optionally limit number of returned items
56
59
  include_output:bool=True # Include output in returned dict?
57
- ):
58
- "Find messages in current specific dialog that contain the given information. To refer to a message found later, use its `sid` field (which is the pk)."
60
+ )->list[dict]:
61
+ "Find `list[dict]` of messages in current specific dialog that contain the given information. To refer to a message found later, use its `sid` field (which is the pk)."
59
62
  did = find_dialog_id()
60
63
  db = get_db()
61
64
  res = db.t.message('did=? AND content LIKE ? ORDER BY mid', [did, f'%{pattern}%'], limit=limit)
@@ -70,7 +73,7 @@ def find_msg_id():
70
73
  return find_var('__msg_id')
71
74
 
72
75
  # %% ../nbs/00_core.ipynb
73
- def read_msg_ids():
76
+ def read_msg_ids()->list[str]:
74
77
  "Get all ids in current dialog."
75
78
  did = find_dialog_id()
76
79
  db = get_db()
@@ -86,14 +89,21 @@ def msg_idx():
86
89
  def read_msg(n:int=-1, # Message index (if relative, +ve is downwards)
87
90
  relative:bool=True # Is `n` relative to current message (True) or absolute (False)?
88
91
  ):
89
- "Get the message indexed in the current dialog."
92
+ "Get the `Message` object indexed in the current dialog."
90
93
  ids,idx = msg_idx()
91
94
  if relative:
92
95
  idx = idx+n
93
96
  if not 0<=idx<len(ids): return None
94
97
  else: idx = n
95
98
  db = get_db()
96
- return db.t.message.fetchone('sid=?', [ids[idx]])
99
+ return db.t.message.selectone('sid=?', [ids[idx]])
100
+
101
+ # %% ../nbs/00_core.ipynb
102
+ def del_msg(
103
+ sid:str=None, # sid (stable id -- pk) of message that placement is relative to (if None, uses current message)
104
+ ):
105
+ "Delete a message from the dialog. Be sure to pass a `sid`, not a `mid`."
106
+ xpost('http://localhost:5001/rm_msg_', data=dict(msid=sid)).raise_for_status()
97
107
 
98
108
  # %% ../nbs/00_core.ipynb
99
109
  def _msg(
@@ -119,13 +129,25 @@ def add_msg(
119
129
  **kwargs
120
130
  ):
121
131
  "Add/update a message to the queue to show after code execution completes. Be sure to pass a `sid` (stable id) not a `mid` (which is used only for sorting, and can change)."
122
- assert msg_type in ('note', 'code', 'prompt'), "msg_type must be 'code', 'note', or 'prompt'."
123
- assert msg_type not in ('note') or not output, "'note' messages cannot have an output."
124
- run_cmd('add_msg', content=content, msg_type=msg_type, output=output, placement=placement, sid=sid, **kwargs)
132
+ if msg_type not in ('note', 'code', 'prompt'): return "msg_type must be 'code', 'note', or 'prompt'."
133
+ if msg_type=='note' and output: return "note messages cannot have an output."
134
+ if not sid: sid = find_msg_id()
135
+ data = dict(content=content, msg_type=msg_type, output=output, placement=placement, sid=sid, **kwargs)
136
+ return xpost('http://localhost:5001/add_relative_', data=data).text
137
+
138
+ # %% ../nbs/00_core.ipynb
139
+ @delegates(add_msg)
140
+ def _add_msg_unsafe(
141
+ content:str, # Content of the message (i.e the message prompt, code, or note text)
142
+ run:bool=False, # For prompts, send it to the AI; for code, execute it (*DANGEROUS -- be careful of what you run!)
143
+ **kwargs
144
+ ):
145
+ """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).
146
+ *WARNING*--This can execute arbitrary code, so check carefully what you run!--*WARNING"""
147
+ return add_msg(content=content, run=run, **kwargs)
125
148
 
126
149
  # %% ../nbs/00_core.ipynb
127
150
  def _umsg(
128
- content:str|None = None, # Content of the message (i.e the message prompt, code, or note text)
129
151
  msg_type: str|None = None, # Message type, can be 'code', 'note', or 'prompt'
130
152
  output:str|None = None, # For prompts/code, the output
131
153
  time_run: str | None = None, # When was message executed
@@ -140,8 +162,9 @@ def _umsg(
140
162
  # %% ../nbs/00_core.ipynb
141
163
  @delegates(_umsg)
142
164
  def update_msg(
143
- msg:Optional[Dict]=None, # Dictionary of field keys/values to update
144
165
  sid:str=None, # sid (stable id -- pk) of message to update (if None, uses current message)
166
+ content:str|None = None, # Content of the message (i.e the message prompt, code, or note text)
167
+ msg:Optional[Dict]=None, # Dictionary of field keys/values to update
145
168
  **kwargs):
146
169
  """Update an existing message. Provide either `msg` OR field key/values to update.
147
170
  Use `content` param to update contents. Be sure to pass a `sid` (stable id -- the pk) not a `mid`
@@ -151,14 +174,7 @@ def update_msg(
151
174
  sid = kw.pop('sid', sid)
152
175
  if not sid: raise TypeError("update_msg needs either a dict message or `sid=...`")
153
176
  kw.pop('did', None)
154
- run_cmd('add_msg', placement='update', sid=sid, **kw)
155
-
156
- # %% ../nbs/00_core.ipynb
157
- def add_html(
158
- html:str, # HTML to add to the DOM
159
- ):
160
- "Dynamically add HTML to the current web page. Supports HTMX attrs too."
161
- run_cmd('add_ft', html=html)
177
+ add_msg(content, placement='update', sid=sid, **kw)
162
178
 
163
179
  # %% ../nbs/00_core.ipynb
164
180
  def load_gist(gist_id:str):
@@ -221,7 +237,9 @@ def import_gist(
221
237
  syms = [getattr(module, nm) for nm in syms]
222
238
  if import_wildcard:
223
239
  for sym in syms: glbs[sym.__name__] = sym
224
- if create_msg: add_msg(f"Tools added to dialog:\n\n{mk_toollist(syms)}")
240
+ if create_msg:
241
+ pref = getattr(module, '__doc__', "Tools added to dialog:")
242
+ add_msg(f"{pref}\n\n{mk_toollist(syms)}")
225
243
  return module
226
244
 
227
245
  # %% ../nbs/00_core.ipynb
@@ -249,3 +267,16 @@ def import_dialog(fname, add_header=True):
249
267
  add_msg(msg.get('content',''), msg.get('msg_type','note'), msg.get('output',''), 'at_end', **opts)
250
268
  if add_header: add_msg(f"# Imported Dialog `{fname}`", 'note', placement='at_end')
251
269
  return f"Imported {len(data['messages'])} messages"
270
+
271
+ # %% ../nbs/00_core.ipynb
272
+ def tool_info():
273
+ cts='''Tools available from `dialoghelper`:
274
+
275
+ - &`find_dialog_id`: Get the current dialog id.
276
+ - &`find_msg_id`: Get the current message id.
277
+ - &`find_msgs`: Find messages in current specific dialog that contain the given information.
278
+ - &`read_msg`: Get the message indexed in the current dialog.
279
+ - &`del_msg`: Delete a message from the dialog.
280
+ - &`add_msg`: Add/update a message to the queue to show after code execution completes.
281
+ - &`update_msg`: Update an existing message.'''
282
+ add_msg(cts)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.12
3
+ Version: 0.0.14
4
4
  Summary: Helper functions for solveit dialogs
5
5
  Home-page: https://github.com/AnswerDotAI/dialoghelper
6
6
  Author: Jeremy Howard
@@ -1,7 +1,7 @@
1
1
  [DEFAULT]
2
2
  repo = dialoghelper
3
3
  lib_name = dialoghelper
4
- version = 0.0.12
4
+ version = 0.0.14
5
5
  min_python = 3.9
6
6
  license = apache2
7
7
  black_formatting = False
@@ -1,2 +0,0 @@
1
- __version__ = "0.0.12"
2
- from .core import *
File without changes
File without changes
File without changes
File without changes
File without changes