Moot packs for the forest¶
gutenberg_kg.export_web_moots
¶
Moot packs for the Knowledge Press Forest.
gutenkg converse --out writes a transcript: every turn, its retrieval,
the model's raw reply and the grounding results. The forest needs less and
must not depend on that format, so this module turns transcripts into small
moot packs, version :data:PACK_VERSION, and keeps an index of them:
moots/<id>.json: the trees (with each author's voice: gender and accent fromcorpus/authors/voices.json), topic, date and model, and each turn as the reader sees it -- the snapped text, the speaker (0 or 1), the passages it cites, whether it was grounded and the corrections made.moots/index.json: one entry per moot, merged by id.
A tree is named by its worker key, "<genre>/<book>", which the forest's
catalog entries also carry as genre and book. A pack never carries
the raw reply, prompts or retrieval queries.
MootPackError
¶
Bases: ValueError
Raised when a file is not a converse --out transcript.
index_entry(pack)
¶
One moot's line in index.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pack
|
dict
|
A moot pack. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in src/gutenberg_kg/export_web_moots.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
moot_id(transcript)
¶
The pack id: a slug of both book names and the topic.
Re-running a pairing on the same topic gives the same id, so its pack replaces the earlier one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transcript
|
dict
|
A |
required |
Returns:
| Type | Description |
|---|---|
str
|
e.g. |
Source code in src/gutenberg_kg/export_web_moots.py
42 43 44 45 46 47 48 49 50 51 52 | |
moot_pack(transcript, voices=None)
¶
Turn a transcript into a moot pack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transcript
|
dict
|
A |
required |
voices
|
dict[str, dict] | None
|
The author voice table; each tree's |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
The pack, JSON-ready. |
Raises:
| Type | Description |
|---|---|
MootPackError
|
When the transcript lacks two trees or any turns. |
Source code in src/gutenberg_kg/export_web_moots.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
pack_tree(tree, voices)
¶
One tree as a pack carries it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
dict
|
A transcript tree, |
required |
voices
|
dict[str, dict]
|
The author voice table. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in src/gutenberg_kg/export_web_moots.py
55 56 57 58 59 60 61 62 63 64 65 66 67 | |
pack_turn(utterance, side)
¶
One utterance as a pack turn: what the reader sees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
utterance
|
dict
|
A transcript utterance. |
required |
side
|
dict[str, int]
|
Each tree's key -> 0 or 1, its speaking order. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
|
Source code in src/gutenberg_kg/export_web_moots.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
write_moots(transcripts, out_dir, voices=None)
¶
Write a pack per transcript and merge them into the index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transcripts
|
list[Path]
|
|
required |
out_dir
|
Path
|
The forest's |
required |
voices
|
dict[str, dict] | None
|
The author voice table; |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The ids written, in input order. |
Raises:
| Type | Description |
|---|---|
MootPackError
|
When a file is not valid JSON or not a transcript. |
Source code in src/gutenberg_kg/export_web_moots.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |