dialoghelper 0.0.20__py3-none-any.whl → 0.0.22__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.20"
1
+ __version__ = "0.0.22"
2
2
  from .core import *
dialoghelper/_modidx.py CHANGED
@@ -25,4 +25,10 @@ d = { 'settings': { 'branch': 'main',
25
25
  'dialoghelper.core.read_msg': ('core.html#read_msg', 'dialoghelper/core.py'),
26
26
  'dialoghelper.core.tool_info': ('core.html#tool_info', 'dialoghelper/core.py'),
27
27
  'dialoghelper.core.update_msg': ('core.html#update_msg', 'dialoghelper/core.py')},
28
- 'dialoghelper.db_dc': {}}}
28
+ 'dialoghelper.db_dc': {},
29
+ 'dialoghelper.experimental': { 'dialoghelper.experimental._load_screenshot_js': ( 'experimental.html#_load_screenshot_js',
30
+ 'dialoghelper/experimental.py'),
31
+ 'dialoghelper.experimental.capture_screen': ( 'experimental.html#capture_screen',
32
+ 'dialoghelper/experimental.py'),
33
+ 'dialoghelper.experimental.create_iife': ( 'experimental.html#create_iife',
34
+ 'dialoghelper/experimental.py')}}}
dialoghelper/core.py CHANGED
@@ -69,9 +69,9 @@ def find_msg_id():
69
69
 
70
70
  # %% ../nbs/00_core.ipynb
71
71
  def msg_idx(
72
- msgid=None # Message id to find (defaults to current message)
72
+ msgid=None, # Message id to find (defaults to current message)
73
73
  ):
74
- "Get relative index of message in dialog."
74
+ "Get absolute index of message in dialog."
75
75
  if not msgid: msgid = find_msg_id()
76
76
  return call_endp('msg_idx_', json=True, msgid=msgid)['msgid']
77
77
 
@@ -141,6 +141,7 @@ def _add_msg_unsafe(
141
141
 
142
142
  # %% ../nbs/00_core.ipynb
143
143
  def _umsg(
144
+ content:str|None=None, # Content of the message (i.e the message prompt, code, or note text)
144
145
  msg_type: str|None = None, # Message type, can be 'code', 'note', or 'prompt'
145
146
  output:str|None = None, # For prompts/code, the output
146
147
  time_run: str | None = None, # When was message executed
@@ -156,14 +157,13 @@ def _umsg(
156
157
  @delegates(_umsg)
157
158
  def update_msg(
158
159
  msgid:str=None, # id of message to update (if None, uses current message)
159
- content:str|None=None, # Content of the message (i.e the message prompt, code, or note text)
160
160
  msg:Optional[Dict]=None, # Dictionary of field keys/values to update
161
161
  **kwargs):
162
162
  """Update an existing message. Provide either `msg` OR field key/values to update.
163
163
  Use `content` param to update contents.
164
164
  Only include parameters to update--missing ones will be left unchanged."""
165
165
  if not msgid and not msg: raise TypeError("update_msg needs either a dict message or `msgid=`")
166
- return call_endp('add_relative_', content=content, placement='update', msgid=msgid, **kwargs)
166
+ return call_endp('add_relative_', placement='update', msgid=msgid, **kwargs)
167
167
 
168
168
  # %% ../nbs/00_core.ipynb
169
169
  def load_gist(gist_id:str):
@@ -236,6 +236,7 @@ def tool_info():
236
236
  cts='''Tools available from `dialoghelper`:
237
237
 
238
238
  - &`curr_dialog`: Get the current dialog info.
239
+ - &`msg_idx`: Get absolute index of message in dialog.
239
240
  - &`add_html`: Send HTML to the browser to be swapped into the DOM using hx-swap-oob.
240
241
  - &`find_msg_id`: Get the current message id.
241
242
  - &`find_msgs`: Find messages in current specific dialog that contain the given information.
@@ -0,0 +1,68 @@
1
+ """Experimental `dialoghelper` capabilities."""
2
+
3
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_experimental.ipynb.
4
+
5
+ # %% auto 0
6
+ __all__ = ['create_iife', 'capture_screen']
7
+
8
+ # %% ../nbs/01_experimental.ipynb
9
+ from importlib import resources
10
+ import uuid
11
+ from fasthtml.common import Div, Script
12
+ from time import sleep
13
+ import base64
14
+ import json
15
+ import time
16
+ from claudette import ToolResult
17
+ from .core import *
18
+ from dataclasses import dataclass
19
+ from httpx import get as xget, post as xpost
20
+
21
+ # %% ../nbs/01_experimental.ipynb
22
+ _js_loaded = False
23
+
24
+ def _load_screenshot_js():
25
+ "Load screenshot capability if not already present."
26
+ global _js_loaded
27
+ if _js_loaded:
28
+ print("screenshot.js already loaded")
29
+ return
30
+ js_content = (resources.files('dialoghelper') / 'screenshot.js').read_text()
31
+ add_html(Div(Script(js_content), hx_swap_oob='beforeend:#js-script'))
32
+ print("Added screenshot.js")
33
+ _js_loaded = True
34
+
35
+ # %% ../nbs/01_experimental.ipynb
36
+ def create_iife(code: str) -> str:
37
+ "Wrap javascript code string in an IIFE"
38
+ return f'''
39
+ (async () => {{
40
+ {code}
41
+ }})();
42
+ '''
43
+
44
+ # %% ../nbs/01_experimental.ipynb
45
+ def capture_screen():
46
+ "Capture current desktop returning the screenshot as a ToolImageResult."
47
+ _load_screenshot_js()
48
+ data_id = str(uuid.uuid4()) # Generate random ID for data communication
49
+ screenshot_code = f'captureScreenAndUpload("{data_id}");'
50
+ trigger_script = create_iife(screenshot_code)
51
+ add_html(Div(Script(trigger_script), hx_swap_oob=f'beforeend:#js-script'))
52
+ max_attempts = 50
53
+ for attempt in range(max_attempts):
54
+ result = xpost('http://localhost:5001/pop_data_', data={'data_id': data_id})
55
+ if result.status_code == 200:
56
+ try:
57
+ if not result.text.strip():
58
+ time.sleep(0.5)
59
+ continue
60
+ data = result.json() # data is a dict
61
+ if 'error' in data: return f"Screenshot failed: {data['error']}"
62
+ if 'img_data' in data and 'img_type' in data:
63
+ return ToolResult(data=data['img_data'], result_type=data['img_type'])
64
+ return f"Screenshot data incomplete: {data}"
65
+ except json.JSONDecodeError as e: print(f"JSON decode error: {e}, Raw text: '{result.text}'")
66
+ except Exception as e: print(f"Error processing screenshot data: {e}")
67
+ time.sleep(0.5)
68
+ return "Screenshot capture timed out"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.20
3
+ Version: 0.0.22
4
4
  Summary: Helper functions for solveit dialogs
5
5
  Home-page: https://github.com/AnswerDotAI/dialoghelper
6
6
  Author: Jeremy Howard
@@ -22,6 +22,7 @@ Requires-Dist: fastcore>=1.8.5
22
22
  Requires-Dist: fastlite
23
23
  Requires-Dist: ghapi
24
24
  Requires-Dist: ipykernel-helper
25
+ Requires-Dist: claudette
25
26
  Provides-Extra: dev
26
27
  Dynamic: author
27
28
  Dynamic: author-email
@@ -0,0 +1,11 @@
1
+ dialoghelper/__init__.py,sha256=C9YgbQJOYL1v4JJrxFdU3NX8aFG4GorkZ6mJFay3Sww,43
2
+ dialoghelper/_modidx.py,sha256=dqZjsj-FkFgiTcIeiCB7rSCpUzStGILPMqC0NRt4jO4,3402
3
+ dialoghelper/core.py,sha256=3zWfyFZPDkzHVIh2sjI4PESpezXhOKMnWNqOJ1zXXBA,10859
4
+ dialoghelper/db_dc.py,sha256=mi2Q2am_SoAPGpNQg7KPFS5pR9WEapRXT8ypkNmMfw0,2330
5
+ dialoghelper/experimental.py,sha256=6tDnbY3JBA8MLdzMZ18uCHnT5BapgzH61sGxfUt8HQ8,2459
6
+ dialoghelper-0.0.22.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
7
+ dialoghelper-0.0.22.dist-info/METADATA,sha256=bbZHjmrMW--7ceB6nDC5Or7DTnRF6CNWlAqSpgoQpDw,2590
8
+ dialoghelper-0.0.22.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ dialoghelper-0.0.22.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
10
+ dialoghelper-0.0.22.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
11
+ dialoghelper-0.0.22.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- dialoghelper/__init__.py,sha256=mkmmPV_a7e3EgojncsapZLZfAn0jyTfnZIQiO1GWA0M,43
2
- dialoghelper/_modidx.py,sha256=wWjLy97PBuZVMAydnBUSJlkZuN9x2bkYyY0SHwZQkrk,2654
3
- dialoghelper/core.py,sha256=AlhLbCO4flkphUItM6bHT7jcdsgVZ0a7Yx3zmwhnkBA,10819
4
- dialoghelper/db_dc.py,sha256=mi2Q2am_SoAPGpNQg7KPFS5pR9WEapRXT8ypkNmMfw0,2330
5
- dialoghelper-0.0.20.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
- dialoghelper-0.0.20.dist-info/METADATA,sha256=LRTH4iHmFc3OvCFpl1SpxvEgq9dRS2ZcQ_C_Ny18LsQ,2565
7
- dialoghelper-0.0.20.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- dialoghelper-0.0.20.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
9
- dialoghelper-0.0.20.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
10
- dialoghelper-0.0.20.dist-info/RECORD,,