dialoghelper 0.0.21__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.21"
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')}}}
@@ -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.21
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=731zsPSn_ikal3tSw5-jTdqXWpxeTh4lO9otJwO7wOE,43
2
- dialoghelper/_modidx.py,sha256=wWjLy97PBuZVMAydnBUSJlkZuN9x2bkYyY0SHwZQkrk,2654
3
- dialoghelper/core.py,sha256=3zWfyFZPDkzHVIh2sjI4PESpezXhOKMnWNqOJ1zXXBA,10859
4
- dialoghelper/db_dc.py,sha256=mi2Q2am_SoAPGpNQg7KPFS5pR9WEapRXT8ypkNmMfw0,2330
5
- dialoghelper-0.0.21.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
- dialoghelper-0.0.21.dist-info/METADATA,sha256=RcShJ1NQgVYRjy8ZVC45cKsyiidtcWPBn8Ymp1KilMA,2565
7
- dialoghelper-0.0.21.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- dialoghelper-0.0.21.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
9
- dialoghelper-0.0.21.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
10
- dialoghelper-0.0.21.dist-info/RECORD,,