dialoghelper 0.0.9__tar.gz → 0.0.10__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.9
3
+ Version: 0.0.10
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.10"
2
+ from .core import *
@@ -9,16 +9,19 @@ d = { 'settings': { 'branch': 'main',
9
9
  'dialoghelper.core._umsg': ('core.html#_umsg', 'dialoghelper/core.py'),
10
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.export_dialog': ('core.html#export_dialog', 'dialoghelper/core.py'),
12
13
  'dialoghelper.core.find_dialog_id': ('core.html#find_dialog_id', 'dialoghelper/core.py'),
13
14
  'dialoghelper.core.find_msg_id': ('core.html#find_msg_id', 'dialoghelper/core.py'),
14
15
  'dialoghelper.core.find_msgs': ('core.html#find_msgs', 'dialoghelper/core.py'),
15
16
  'dialoghelper.core.find_var': ('core.html#find_var', 'dialoghelper/core.py'),
16
17
  'dialoghelper.core.get_db': ('core.html#get_db', 'dialoghelper/core.py'),
17
18
  'dialoghelper.core.gist_file': ('core.html#gist_file', 'dialoghelper/core.py'),
19
+ 'dialoghelper.core.import_dialog': ('core.html#import_dialog', 'dialoghelper/core.py'),
18
20
  'dialoghelper.core.import_gist': ('core.html#import_gist', 'dialoghelper/core.py'),
19
21
  'dialoghelper.core.import_string': ('core.html#import_string', 'dialoghelper/core.py'),
20
22
  'dialoghelper.core.load_gist': ('core.html#load_gist', 'dialoghelper/core.py'),
21
23
  'dialoghelper.core.msg_idx': ('core.html#msg_idx', 'dialoghelper/core.py'),
22
24
  'dialoghelper.core.read_msg': ('core.html#read_msg', 'dialoghelper/core.py'),
23
25
  'dialoghelper.core.read_msg_ids': ('core.html#read_msg_ids', 'dialoghelper/core.py'),
24
- 'dialoghelper.core.update_msg': ('core.html#update_msg', 'dialoghelper/core.py')}}}
26
+ 'dialoghelper.core.update_msg': ('core.html#update_msg', 'dialoghelper/core.py')},
27
+ 'dialoghelper.db_dc': {}}}
@@ -2,13 +2,15 @@
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', 'add_html', 'load_gist', 'gist_file', 'import_string', 'import_gist', 'asdict']
5
+ 'update_msg', 'add_html', 'load_gist', 'gist_file', 'import_string', 'import_gist', 'export_dialog',
6
+ 'import_dialog', 'asdict']
6
7
 
7
8
  # %% ../nbs/00_core.ipynb
8
9
  import inspect, json, importlib, linecache
9
10
  from typing import Dict
10
11
  from tempfile import TemporaryDirectory
11
12
  from ipykernel_helper import *
13
+ from dataclasses import dataclass
12
14
 
13
15
  from fastcore.utils import *
14
16
  from fastcore.meta import delegates
@@ -197,3 +199,29 @@ def import_gist(
197
199
  module = import_string(fil['content'], mod_name)
198
200
  if add_global: inspect.currentframe().f_back.f_globals[mod_name] = module
199
201
  return module
202
+
203
+ # %% ../nbs/00_core.ipynb
204
+ __EXPORT_FIELDS = set('content output input_tokens output_tokens msg_type is_exported skipped pinned i_collapsed o_collapsed header_collapsed'.split())
205
+
206
+ __REQUIRED_FIELDS = set('content output msg_type'.split())
207
+
208
+ # %% ../nbs/00_core.ipynb
209
+ def export_dialog(filename: str, did:int=None):
210
+ "Export dialog messages and optionally attachments to JSON"
211
+ if did is None: did = find_dialog_id()
212
+ db = get_db()
213
+ msgs = db.t.message('did=? and (pinned=0 or pinned is null)', [did], order_by='mid')
214
+ msg_data = [{k:getattr(msg,k) for k in __EXPORT_FIELDS if hasattr(msg, k)}
215
+ for msg in msgs]
216
+ result = {'messages': msg_data, 'dialog_name': db.t.dialog[did].name}
217
+ with open(filename, 'w') as f: json.dump(result, f, indent=2)
218
+
219
+ # %% ../nbs/00_core.ipynb
220
+ def import_dialog(fname, add_header=True):
221
+ "Import dialog messages from JSON file using `add_msg`"
222
+ data = json.loads(Path(fname).read_text())
223
+ for msg in data['messages'][::-1]:
224
+ opts = {k:msg[k] for k in __EXPORT_FIELDS - __REQUIRED_FIELDS if k in msg}
225
+ add_msg(msg.get('content',''), msg.get('msg_type','note'), msg.get('output',''), 'at_end', **opts)
226
+ if add_header: add_msg(f"# Imported Dialog `{fname}`", 'note', placement='at_end')
227
+ return f"Imported {len(data['messages'])} messages"
@@ -0,0 +1,91 @@
1
+ __all__ = ["_Meta", "Attachment", "Completion", "Completion_Mode", "Context", "Dialog", "Message", "Secret", "User"]
2
+ from dataclasses import dataclass
3
+ @dataclass
4
+ class _Meta:
5
+ id: int | None = None
6
+ version: int | None = 0
7
+
8
+ @dataclass
9
+ class Attachment:
10
+ id: str | None = None
11
+ data: bytes | None = None
12
+ content_type: str | None = None
13
+ sid: int | None = None
14
+
15
+ @dataclass
16
+ class Completion:
17
+ req_id: str | None = None
18
+ did: int | None = None
19
+ mid: int | None = None
20
+ mtype: str | None = None
21
+ pfx: str | None = None
22
+ sfx: str | None = None
23
+ ctx: str | None = ''
24
+ mode: str | None = None
25
+ comp: str | None = None
26
+ logprobs: str | None = None
27
+ status: str | None = None
28
+
29
+ @dataclass
30
+ class Completion_Mode:
31
+ id: int | None = None
32
+ name: str | None = None
33
+ c_acceptichars: int | None = None
34
+ c_scon: int | None = None
35
+ c_triggerc: str | None = None
36
+ c_triggeronaccept: int | None = None
37
+ c_mftp: float | None = None
38
+ c_model: str | None = None
39
+ c_nlines: str | None = None
40
+ c_temp: float | None = None
41
+ p_acceptichars: int | None = None
42
+ p_scon: int | None = None
43
+ p_triggerc: str | None = None
44
+ p_triggeronaccept: int | None = None
45
+ p_mftp: float | None = None
46
+ p_model: str | None = None
47
+ p_nlines: str | None = None
48
+ p_temp: float | None = None
49
+
50
+ @dataclass
51
+ class Context:
52
+ name: str | None = None
53
+ context: str | None = None
54
+ token_count: int | None = 0
55
+ did: int | None = None
56
+
57
+ @dataclass
58
+ class Dialog:
59
+ id: int | None = None
60
+ name: str | None = None
61
+ mode: int | None = 2
62
+
63
+ @dataclass
64
+ class Message:
65
+ sid: str | None = None
66
+ mid: str | None = None
67
+ content: str | None = None
68
+ output: str | None = ''
69
+ input_tokens: int | None = '0'
70
+ output_tokens: int | None = '0'
71
+ msg_type: str | None = 'code'
72
+ time_run: str | None = ''
73
+ is_exported: int | None = '0'
74
+ skipped: int | None = '0'
75
+ did: int | None = None
76
+ i_collapsed: int | None = '0'
77
+ o_collapsed: int | None = '0'
78
+ header_collapsed: int | None = '0'
79
+ pinned: int | None = '0'
80
+
81
+ @dataclass
82
+ class Secret:
83
+ name: str | None = None
84
+ secret: str | None = None
85
+
86
+ @dataclass
87
+ class User:
88
+ id: int | None = None
89
+ version: int | None = None
90
+ settings: str | None = None
91
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.9
3
+ Version: 0.0.10
4
4
  Summary: Helper functions for solveit dialogs
5
5
  Home-page: https://github.com/AnswerDotAI/dialoghelper
6
6
  Author: Jeremy Howard
@@ -7,6 +7,7 @@ setup.py
7
7
  dialoghelper/__init__.py
8
8
  dialoghelper/_modidx.py
9
9
  dialoghelper/core.py
10
+ dialoghelper/db_dc.py
10
11
  dialoghelper.egg-info/PKG-INFO
11
12
  dialoghelper.egg-info/SOURCES.txt
12
13
  dialoghelper.egg-info/dependency_links.txt
@@ -1,7 +1,7 @@
1
1
  [DEFAULT]
2
2
  repo = dialoghelper
3
3
  lib_name = dialoghelper
4
- version = 0.0.9
4
+ version = 0.0.10
5
5
  min_python = 3.9
6
6
  license = apache2
7
7
  black_formatting = False
@@ -1,2 +0,0 @@
1
- __version__ = "0.0.9"
2
- from .core import *
File without changes
File without changes
File without changes
File without changes
File without changes