dialoghelper 0.0.2__tar.gz → 0.0.4__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.2
3
+ Version: 0.0.4
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.4"
2
+ from .core import *
@@ -5,7 +5,9 @@ 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.add_msg': ('core.html#add_msg', 'dialoghelper/core.py'),
8
+ 'syms': { 'dialoghelper.core': { 'dialoghelper.core._msg': ('core.html#_msg', 'dialoghelper/core.py'),
9
+ 'dialoghelper.core.add_html': ('core.html#add_html', 'dialoghelper/core.py'),
10
+ 'dialoghelper.core.add_msg': ('core.html#add_msg', 'dialoghelper/core.py'),
9
11
  'dialoghelper.core.find_dialog_id': ('core.html#find_dialog_id', 'dialoghelper/core.py'),
10
12
  'dialoghelper.core.find_msg_id': ('core.html#find_msg_id', 'dialoghelper/core.py'),
11
13
  'dialoghelper.core.find_msgs': ('core.html#find_msgs', 'dialoghelper/core.py'),
@@ -2,7 +2,7 @@
2
2
 
3
3
  # %% auto 0
4
4
  __all__ = ['get_db', 'find_var', 'find_dialog_id', 'find_msgs', 'find_msg_id', 'read_msg_ids', 'msg_idx', 'read_msg', 'add_msg',
5
- 'update_msg', 'load_gist', 'gist_file', 'import_string', 'import_gist']
5
+ 'update_msg', 'add_html', 'load_gist', 'gist_file', 'import_string', 'import_gist']
6
6
 
7
7
  # %% ../nbs/00_core.ipynb
8
8
  import inspect, json, importlib, linecache
@@ -10,12 +10,14 @@ from tempfile import TemporaryDirectory
10
10
  from ipykernel_helper import *
11
11
 
12
12
  from fastcore.utils import *
13
+ from fastcore.meta import delegates
13
14
  from ghapi.all import *
14
15
  from fastlite import *
15
16
 
16
17
  # %% ../nbs/00_core.ipynb
17
18
  def get_db(ns:dict=None):
18
- if os.environ.get('IN_SOLVEIT', False): dataparent,nm = Path('/app'),'data.db'
19
+ app_path = Path('/app') if Path('/.dockerenv').exists() else Path('.')
20
+ if os.environ.get('IN_SOLVEIT', False): dataparent,nm = app_path, 'data.db'
19
21
  else: dataparent,nm = Path('..'),'dev_data.db'
20
22
  db = database(dataparent/'data'/nm)
21
23
  dcs = [o for o in all_dcs(db) if o.__name__[0]!='_']
@@ -45,6 +47,7 @@ def find_msgs(
45
47
  ):
46
48
  "Find messages in a specific dialog that contain the given pattern."
47
49
  did = find_dialog_id()
50
+ db = get_db()
48
51
  return db.t.message('did=? AND content LIKE ?', [did, f'%{pattern}%'], limit=limit)
49
52
 
50
53
  # %% ../nbs/00_core.ipynb
@@ -56,6 +59,7 @@ def find_msg_id():
56
59
  def read_msg_ids():
57
60
  "Get all ids in current dialog."
58
61
  did = find_dialog_id()
62
+ db = get_db()
59
63
  return [o.sid for o in db.t.message('did=?', [did], select='sid', order_by='id')]
60
64
 
61
65
  # %% ../nbs/00_core.ipynb
@@ -74,27 +78,52 @@ def read_msg(n:int=-1, # Message index (if relative, +ve is downwards)
74
78
  idx = idx+n
75
79
  if not 0<=idx<len(ids): return None
76
80
  else: idx = n
81
+ db = get_db()
77
82
  return db.t.message.fetchone('sid=?', [ids[idx]])
78
83
 
79
84
  # %% ../nbs/00_core.ipynb
85
+ def _msg(
86
+ input_tokens: int | None = 0,
87
+ output_tokens: int | None = 0,
88
+ time_run: str | None = '',
89
+ is_exported: int | None = 0,
90
+ skipped: int | None = 0,
91
+ did: int | None = None,
92
+ i_collapsed: int | None = 0,
93
+ o_collapsed: int | None = 0,
94
+ header_collapsed: int | None = 0,
95
+ pinned: int | None = 0
96
+ ): ...
97
+
98
+ # %% ../nbs/00_core.ipynb
99
+ @delegates(_msg)
80
100
  def add_msg(
81
101
  content:str, # message that we are updating or adding before/after
82
102
  msg_type: str='note', # message type, can be 'code', 'note', or 'prompt'
83
- output='', # for prompts/code, initial output
84
- placement='add_after', # can be 'add_after', 'add_before', 'update', 'at_start', 'at_end'
85
- msg_id:str=None # id of message that placement is relative to (if None, uses current message)
103
+ output:str='', # for prompts/code, initial output
104
+ placement:str='add_after', # can be 'add_after', 'add_before', 'update', 'at_start', 'at_end'
105
+ msg_id:str=None, # id of message that placement is relative to (if None, uses current message)
106
+ **kwargs # additional Message fields such as skipped i/o_collapsed, etc, passed through to the server
86
107
  ):
87
108
  "Add/update a message to the queue to show after code execution completes."
88
109
  assert msg_type in ('note', 'code', 'prompt'), "msg_type must be 'code', 'note', or 'prompt'."
89
- kwargs = dict(content=content, msg_type=msg_type, output=output, placement=placement)
90
- if msg_id: kwargs['msg_id']=msg_id
91
- run_cmd('add_msg', **kwargs)
110
+ run_cmd('add_msg', content=content, msg_type=msg_type, output=output, placement=placement, msg_id=msg_id, **kwargs)
92
111
 
93
112
  # %% ../nbs/00_core.ipynb
94
- def update_msg(msg:dict):
113
+ def update_msg(msg: dict):
95
114
  "Update an existing message in the dialog."
96
- if not isinstance(msg,dict): msg = asdict(msg)
97
- add_msg(content=msg['content'], msg_type=msg['msg_type'], output=msg['output'], placement='update', msg_id=msg['id'])
115
+ if not isinstance(msg, dict): msg = asdict(msg)
116
+ exclude = {'id', 'content', 'msg_type', 'output'} # explicit args
117
+ kw = {k: v for k, v in msg.items() if k not in exclude}
118
+ add_msg(content=msg['content'], msg_type=msg['msg_type'], output=msg['output'],
119
+ placement='update', msg_id=msg['id'], **kw)
120
+
121
+ # %% ../nbs/00_core.ipynb
122
+ def add_html(
123
+ html:str, # HTML to add to the DOM
124
+ ):
125
+ "Dynamically add HTML to the current web page. Supports HTMX attrs too."
126
+ run_cmd('add_ft', html=html)
98
127
 
99
128
  # %% ../nbs/00_core.ipynb
100
129
  def load_gist(gist_id:str):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.2
3
+ Version: 0.0.4
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.2
4
+ version = 0.0.4
5
5
  min_python = 3.9
6
6
  license = apache2
7
7
  black_formatting = False
@@ -1,2 +0,0 @@
1
- __version__ = "0.0.1"
2
- from .core import *
File without changes
File without changes
File without changes
File without changes
File without changes