@mailwoman/corpus 11.5.0 → 12.1.0

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.
Files changed (232) hide show
  1. package/data/address-source-register.json +545 -11
  2. package/data/builds/v0.8.22-wofrank-overlay/OVERLAY_PLAN.json +51 -0
  3. package/data/builds/v0.8.24-everyplace/inputs.json +35 -0
  4. package/data/license-decisions.json +440 -9
  5. package/data/licenses/PROVENANCE.md +27 -18
  6. package/data/licenses/at-bev-adressregister-cc-by-4.0.md +25 -0
  7. package/data/licenses/br-ibge-cnefe-open-data.md +21 -0
  8. package/data/licenses/ca-qc-mrnf-cc-by-4.0.md +29 -0
  9. package/data/licenses/ca-statcan-open-licence.md +41 -0
  10. package/data/licenses/ca-yukon-ogl-2.0.md +19 -0
  11. package/data/licenses/dk-dmikg-cc-by-4.0.md +43 -0
  12. package/data/licenses/jp-mlit-isj-pdl-1.0.md +35 -0
  13. package/data/source-additions.json +90 -0
  14. package/data/source-resolutions.json +3 -2
  15. package/data/training-configs/v8.17.0-stage1-gazetteer-v0822-s42.yaml +557 -0
  16. package/data/training-configs/v8.17.0-stage2-corpus-v0822-s42.yaml +1008 -0
  17. package/data/training-configs/v8.18.0-gazetteer-then-mixture-v0822-s42.yaml +1225 -0
  18. package/data/training-configs/v8.20.0-wofrank-v0822-s42.yaml +863 -0
  19. package/data/training-configs/v8.21.0-outcomes-v0822-s42.yaml +873 -0
  20. package/data/training-configs/v8.22.0-stage1-everyplace-v0824-s42.yaml +374 -0
  21. package/data/training-configs/v8.22.0-stage2-corpus-v0824-s42.yaml +808 -0
  22. package/data/training-configs/v8.22.1-stage1-everyplace-v0824-s42.yaml +376 -0
  23. package/data/training-configs/v8.22.1-stage2-corpus-v0824-s42.yaml +793 -0
  24. package/data/training-configs/v9.0.0-bytestem-v090-s42.yaml +665 -0
  25. package/data/training-configs/v9.1.0-bytestem-global-v091-s42.yaml +710 -0
  26. package/data/training-configs/v9.2.0-bytestem-global-v092-s42.yaml +714 -0
  27. package/data/training-manifests/v0.8.22-wofrank-overlay.json +9000 -0
  28. package/data/training-manifests/v0.8.24-everyplace-overlay.json +9000 -0
  29. package/data/training-manifests/v0.9.0-compact.effective.json +2556 -0
  30. package/data/training-manifests/v0.9.0-compact.json +9000 -0
  31. package/data/training-manifests/v0.9.1-compact.json +9660 -0
  32. package/data/training-manifests/v0.9.2-compact.effective.json +2670 -0
  33. package/data/training-manifests/v0.9.2-compact.json +9660 -0
  34. package/lib/adapters/geonames/features/adapter.ts +29 -11
  35. package/lib/adapters/overture/adapter.ts +26 -6
  36. package/lib/adapters/street/line.ts +6 -5
  37. package/lib/adapters/street/unit.ts +7 -0
  38. package/lib/adapters/wof/admin/json/adapter.ts +38 -3
  39. package/lib/adapters/wof/json-rows.ts +84 -5
  40. package/lib/adapters/wof/sample.ts +42 -6
  41. package/lib/au/adapters/gnaf/source.ts +12 -0
  42. package/lib/build/code-hash.ts +1 -1
  43. package/lib/cjk/foreign-places.ts +1 -1
  44. package/lib/fr/adapters/ban/adapter.ts +57 -8
  45. package/lib/fr/recipes/admin-split.ts +14 -2
  46. package/lib/fr/recipes/lieudit.ts +1 -1
  47. package/lib/fr/recipes/order.ts +14 -5
  48. package/lib/international/recipes/locale.ts +1 -1
  49. package/lib/kr/adapters/localdata/permit-rows.ts +1 -1
  50. package/lib/parquet/schema.ts +7 -0
  51. package/lib/recipes/po/box/cedex/recipe.ts +1 -1
  52. package/lib/recipes/po/box/cedex/vocabulary.ts +4 -4
  53. package/lib/recipes/trailing-region.ts +147 -17
  54. package/lib/synthesizers/po-box.ts +51 -12
  55. package/lib/test-kit/corpus-recipe.ts +3 -0
  56. package/lib/tools/anthropic/batches.ts +221 -0
  57. package/lib/tools/anthropic/labeling.ts +263 -0
  58. package/lib/tools/compact-v9.ts +890 -0
  59. package/lib/tools/fetch/wikidata/vital-places/entities.ts +20 -2
  60. package/lib/tools/fetch/wikidata/vital-places/qrank.ts +5 -4
  61. package/lib/tools/fragment-assay.run.ts +2 -1
  62. package/lib/tools/name-roles/name-roles.run.ts +296 -0
  63. package/lib/tools/name-roles/prompt.ts +253 -0
  64. package/lib/tools/overlay/deletions.ts +1 -1
  65. package/lib/tools/overlay/draw-weight.ts +275 -0
  66. package/lib/tools/place-twins/place-twins.run.ts +528 -0
  67. package/lib/tools/place-twins/prompt.ts +276 -0
  68. package/lib/tools/prominent-shapes/prominent-shapes.run.ts +420 -0
  69. package/lib/tools/prominent-shapes/prompt.ts +189 -0
  70. package/lib/tools/prominent-shapes/read-seeds.ts +286 -0
  71. package/lib/tools/prominent-shapes/seeds.ts +281 -0
  72. package/lib/tools/prominent-shapes/validate.ts +563 -0
  73. package/lib/tools/source-register/build.ts +1 -0
  74. package/lib/training/config/admission.ts +9 -2
  75. package/lib/training/config/schema.ts +68 -1
  76. package/lib/types.ts +23 -0
  77. package/lib/us/adapters/usgov/usgs-structures/adapter.ts +103 -6
  78. package/lib/utils/split.ts +1 -1
  79. package/out/adapters/geonames/features/adapter.d.ts +2 -2
  80. package/out/adapters/geonames/features/adapter.d.ts.map +1 -1
  81. package/out/adapters/geonames/features/adapter.js +25 -11
  82. package/out/adapters/geonames/features/adapter.js.map +1 -1
  83. package/out/adapters/overture/adapter.d.ts.map +1 -1
  84. package/out/adapters/overture/adapter.js +21 -5
  85. package/out/adapters/overture/adapter.js.map +1 -1
  86. package/out/adapters/street/line.d.ts +4 -4
  87. package/out/adapters/street/line.d.ts.map +1 -1
  88. package/out/adapters/street/line.js +5 -5
  89. package/out/adapters/street/line.js.map +1 -1
  90. package/out/adapters/street/unit.d.ts +4 -0
  91. package/out/adapters/street/unit.d.ts.map +1 -1
  92. package/out/adapters/street/unit.js +3 -0
  93. package/out/adapters/street/unit.js.map +1 -1
  94. package/out/adapters/wof/admin/json/adapter.d.ts +7 -0
  95. package/out/adapters/wof/admin/json/adapter.d.ts.map +1 -1
  96. package/out/adapters/wof/admin/json/adapter.js +28 -3
  97. package/out/adapters/wof/admin/json/adapter.js.map +1 -1
  98. package/out/adapters/wof/json-rows.d.ts +8 -0
  99. package/out/adapters/wof/json-rows.d.ts.map +1 -1
  100. package/out/adapters/wof/json-rows.js +56 -4
  101. package/out/adapters/wof/json-rows.js.map +1 -1
  102. package/out/adapters/wof/sample.d.ts +12 -0
  103. package/out/adapters/wof/sample.d.ts.map +1 -1
  104. package/out/adapters/wof/sample.js +37 -6
  105. package/out/adapters/wof/sample.js.map +1 -1
  106. package/out/au/adapters/gnaf/source.d.ts +9 -0
  107. package/out/au/adapters/gnaf/source.d.ts.map +1 -1
  108. package/out/au/adapters/gnaf/source.js +9 -0
  109. package/out/au/adapters/gnaf/source.js.map +1 -1
  110. package/out/build/code-hash.js +1 -1
  111. package/out/build/code-hash.js.map +1 -1
  112. package/out/cjk/foreign-places.js +1 -1
  113. package/out/cjk/foreign-places.js.map +1 -1
  114. package/out/fr/adapters/ban/adapter.d.ts.map +1 -1
  115. package/out/fr/adapters/ban/adapter.js +49 -7
  116. package/out/fr/adapters/ban/adapter.js.map +1 -1
  117. package/out/fr/recipes/admin-split.d.ts.map +1 -1
  118. package/out/fr/recipes/admin-split.js +15 -2
  119. package/out/fr/recipes/admin-split.js.map +1 -1
  120. package/out/fr/recipes/lieudit.js +1 -1
  121. package/out/fr/recipes/lieudit.js.map +1 -1
  122. package/out/fr/recipes/order.d.ts.map +1 -1
  123. package/out/fr/recipes/order.js +16 -5
  124. package/out/fr/recipes/order.js.map +1 -1
  125. package/out/international/recipes/locale.js +1 -1
  126. package/out/international/recipes/locale.js.map +1 -1
  127. package/out/kr/adapters/localdata/permit-rows.js +1 -1
  128. package/out/kr/adapters/localdata/permit-rows.js.map +1 -1
  129. package/out/parquet/schema.d.ts +6 -0
  130. package/out/parquet/schema.d.ts.map +1 -1
  131. package/out/parquet/schema.js +6 -0
  132. package/out/parquet/schema.js.map +1 -1
  133. package/out/recipes/po/box/cedex/recipe.js +1 -1
  134. package/out/recipes/po/box/cedex/recipe.js.map +1 -1
  135. package/out/recipes/po/box/cedex/vocabulary.d.ts +1 -1
  136. package/out/recipes/po/box/cedex/vocabulary.d.ts.map +1 -1
  137. package/out/recipes/po/box/cedex/vocabulary.js +4 -4
  138. package/out/recipes/po/box/cedex/vocabulary.js.map +1 -1
  139. package/out/recipes/trailing-region.d.ts.map +1 -1
  140. package/out/recipes/trailing-region.js +122 -17
  141. package/out/recipes/trailing-region.js.map +1 -1
  142. package/out/synthesizers/po-box.d.ts +7 -0
  143. package/out/synthesizers/po-box.d.ts.map +1 -1
  144. package/out/synthesizers/po-box.js +36 -12
  145. package/out/synthesizers/po-box.js.map +1 -1
  146. package/out/test-kit/corpus-recipe.d.ts +3 -0
  147. package/out/test-kit/corpus-recipe.d.ts.map +1 -1
  148. package/out/test-kit/corpus-recipe.js.map +1 -1
  149. package/out/tools/anthropic/batches.d.ts +117 -0
  150. package/out/tools/anthropic/batches.d.ts.map +1 -0
  151. package/out/tools/anthropic/batches.js +141 -0
  152. package/out/tools/anthropic/batches.js.map +1 -0
  153. package/out/tools/anthropic/labeling.d.ts +97 -0
  154. package/out/tools/anthropic/labeling.d.ts.map +1 -0
  155. package/out/tools/anthropic/labeling.js +146 -0
  156. package/out/tools/anthropic/labeling.js.map +1 -0
  157. package/out/tools/compact-v9.d.ts +124 -0
  158. package/out/tools/compact-v9.d.ts.map +1 -0
  159. package/out/tools/compact-v9.js +507 -0
  160. package/out/tools/compact-v9.js.map +1 -0
  161. package/out/tools/fetch/wikidata/vital-places/entities.d.ts +3 -0
  162. package/out/tools/fetch/wikidata/vital-places/entities.d.ts.map +1 -1
  163. package/out/tools/fetch/wikidata/vital-places/entities.js +19 -1
  164. package/out/tools/fetch/wikidata/vital-places/entities.js.map +1 -1
  165. package/out/tools/fetch/wikidata/vital-places/qrank.d.ts.map +1 -1
  166. package/out/tools/fetch/wikidata/vital-places/qrank.js +4 -4
  167. package/out/tools/fetch/wikidata/vital-places/qrank.js.map +1 -1
  168. package/out/tools/fragment-assay.run.js +1 -1
  169. package/out/tools/fragment-assay.run.js.map +1 -1
  170. package/out/tools/name-roles/name-roles.run.d.ts +2 -0
  171. package/out/tools/name-roles/name-roles.run.d.ts.map +1 -0
  172. package/out/tools/name-roles/name-roles.run.js +230 -0
  173. package/out/tools/name-roles/name-roles.run.js.map +1 -0
  174. package/out/tools/name-roles/prompt.d.ts +166 -0
  175. package/out/tools/name-roles/prompt.d.ts.map +1 -0
  176. package/out/tools/name-roles/prompt.js +176 -0
  177. package/out/tools/name-roles/prompt.js.map +1 -0
  178. package/out/tools/overlay/deletions.js +1 -1
  179. package/out/tools/overlay/deletions.js.map +1 -1
  180. package/out/tools/overlay/draw-weight.d.ts +86 -0
  181. package/out/tools/overlay/draw-weight.d.ts.map +1 -0
  182. package/out/tools/overlay/draw-weight.js +131 -0
  183. package/out/tools/overlay/draw-weight.js.map +1 -0
  184. package/out/tools/place-twins/place-twins.run.d.ts +2 -0
  185. package/out/tools/place-twins/place-twins.run.d.ts.map +1 -0
  186. package/out/tools/place-twins/place-twins.run.js +385 -0
  187. package/out/tools/place-twins/place-twins.run.js.map +1 -0
  188. package/out/tools/place-twins/prompt.d.ts +169 -0
  189. package/out/tools/place-twins/prompt.d.ts.map +1 -0
  190. package/out/tools/place-twins/prompt.js +183 -0
  191. package/out/tools/place-twins/prompt.js.map +1 -0
  192. package/out/tools/prominent-shapes/prominent-shapes.run.d.ts +2 -0
  193. package/out/tools/prominent-shapes/prominent-shapes.run.d.ts.map +1 -0
  194. package/out/tools/prominent-shapes/prominent-shapes.run.js +302 -0
  195. package/out/tools/prominent-shapes/prominent-shapes.run.js.map +1 -0
  196. package/out/tools/prominent-shapes/prompt.d.ts +74 -0
  197. package/out/tools/prominent-shapes/prompt.d.ts.map +1 -0
  198. package/out/tools/prominent-shapes/prompt.js +156 -0
  199. package/out/tools/prominent-shapes/prompt.js.map +1 -0
  200. package/out/tools/prominent-shapes/read-seeds.d.ts +23 -0
  201. package/out/tools/prominent-shapes/read-seeds.d.ts.map +1 -0
  202. package/out/tools/prominent-shapes/read-seeds.js +219 -0
  203. package/out/tools/prominent-shapes/read-seeds.js.map +1 -0
  204. package/out/tools/prominent-shapes/seeds.d.ts +132 -0
  205. package/out/tools/prominent-shapes/seeds.d.ts.map +1 -0
  206. package/out/tools/prominent-shapes/seeds.js +178 -0
  207. package/out/tools/prominent-shapes/seeds.js.map +1 -0
  208. package/out/tools/prominent-shapes/validate.d.ts +152 -0
  209. package/out/tools/prominent-shapes/validate.d.ts.map +1 -0
  210. package/out/tools/prominent-shapes/validate.js +389 -0
  211. package/out/tools/prominent-shapes/validate.js.map +1 -0
  212. package/out/tools/source-register/build.d.ts.map +1 -1
  213. package/out/tools/source-register/build.js +1 -0
  214. package/out/tools/source-register/build.js.map +1 -1
  215. package/out/training/config/admission.d.ts +2 -1
  216. package/out/training/config/admission.d.ts.map +1 -1
  217. package/out/training/config/admission.js +9 -2
  218. package/out/training/config/admission.js.map +1 -1
  219. package/out/training/config/schema.d.ts +276 -1
  220. package/out/training/config/schema.d.ts.map +1 -1
  221. package/out/training/config/schema.js +64 -1
  222. package/out/training/config/schema.js.map +1 -1
  223. package/out/types.d.ts +21 -0
  224. package/out/types.d.ts.map +1 -1
  225. package/out/types.js +13 -0
  226. package/out/types.js.map +1 -1
  227. package/out/us/adapters/usgov/usgs-structures/adapter.d.ts.map +1 -1
  228. package/out/us/adapters/usgov/usgs-structures/adapter.js +78 -4
  229. package/out/us/adapters/usgov/usgs-structures/adapter.js.map +1 -1
  230. package/out/utils/split.js +1 -1
  231. package/out/utils/split.js.map +1 -1
  232. package/package.json +24 -24
@@ -0,0 +1,183 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+ /**
4
+ * @file The request and response shapes of the place-twin adjudication: whether a place the admin build
5
+ * added from Overture or GeoNames, having matched no WOF record by id or by name key, is nevertheless
6
+ * the same settlement as a WOF record within the match radius under a different spelling or script.
7
+ */
8
+ import { stringifyJSON, tryParsingJSON } from "@mailwoman/core/values/json";
9
+ /**
10
+ * Why the model paired, or declined to pair, an added place with a WOF record.
11
+ */
12
+ export const TwinReason = {
13
+ /**
14
+ * The two names write one name in two scripts or romanizations.
15
+ */
16
+ Transliteration: "transliteration",
17
+ /**
18
+ * The two names are one name in two languages.
19
+ */
20
+ Translation: "translation",
21
+ /**
22
+ * The two names differ by spelling, spacing, an article, an abbreviation or an administrative suffix.
23
+ */
24
+ Spelling: "spelling",
25
+ /**
26
+ * The model recalls that the two names belong to one settlement.
27
+ */
28
+ Known: "known_same",
29
+ /**
30
+ * The names belong to different settlements.
31
+ */
32
+ Different: "different_place",
33
+ /**
34
+ * The evidence decides neither way.
35
+ */
36
+ Unclear: "unclear",
37
+ };
38
+ const MATCH_REASONS = new Set([
39
+ TwinReason.Transliteration,
40
+ TwinReason.Translation,
41
+ TwinReason.Spelling,
42
+ TwinReason.Known,
43
+ ]);
44
+ const CONFIDENCES = ["high", "medium", "low"];
45
+ /**
46
+ * What the romanizer could compare between an added place's names and its candidates' names.
47
+ */
48
+ export const NameComparison = {
49
+ /**
50
+ * At least one pair of names romanizes on both sides, so an edit similarity exists.
51
+ */
52
+ Romanized: "romanized",
53
+ /**
54
+ * No pair romanizes on both sides, and at least one pair romanizes on exactly one:
55
+ * the names are in different scripts.
56
+ */
57
+ CrossScript: "cross_script",
58
+ /**
59
+ * No name on either side romanizes.
60
+ */
61
+ Uncovered: "uncovered",
62
+ };
63
+ /**
64
+ * The system prompt of every place-twin request states the four reasons that pair an
65
+ * added place with a candidate, the two that pair it with none, and the rule that a
66
+ * short distance without a name relation pairs no two places.
67
+ */
68
+ export const PLACE_TWIN_SYSTEM_PROMPT = `You adjudicate duplicate settlements for a gazetteer.
69
+
70
+ The gazetteer holds Who's On First records and adds places from Overture and GeoNames. An added place joins a Who's On First record when the two share an identifier or a normalized name within 5 kilometers. Each item below is an added place that joined none, with the Who's On First settlements within 5 kilometers of it. The names differ, so either the added place is a separate settlement, or it is one of the candidates written in another script, language, romanization or spelling.
71
+
72
+ For each item you receive the added place's names, placetype, country and coordinates, and each candidate's index, names, placetype and distance in kilometers.
73
+
74
+ Decide whether the added place is the same settlement as exactly one candidate:
75
+ - transliteration: the names write one name in two scripts or romanization systems.
76
+ - translation: the names are one name in two languages, including an exonym.
77
+ - spelling: the names differ by spelling, diacritics, spacing, an article, an abbreviation, or an administrative word such as village, commune, town or its local equivalent.
78
+ - known_same: you recall that the two names belong to one settlement, although the strings do not show it.
79
+ - different_place: the names belong to different settlements. Two villages a few kilometers apart with unrelated names are different places, and so are places distinguished by a qualifier such as upper and lower, old and new, north and south, or a number.
80
+ - unclear: the evidence decides neither way.
81
+
82
+ Give "match" as the index of the candidate for the first four reasons, and -1 for different_place and unclear. A neighborhood or hamlet inside a larger candidate is a different place. Distance alone never establishes a match. State your confidence as high, medium or low, and prefer unclear over a guess.
83
+
84
+ Return one label per item, with the item's index.`;
85
+ /**
86
+ * The structured-output schema of one response.
87
+ */
88
+ export const PLACE_TWIN_RESPONSE_SCHEMA = {
89
+ type: "object",
90
+ additionalProperties: false,
91
+ required: ["labels"],
92
+ properties: {
93
+ labels: {
94
+ type: "array",
95
+ items: {
96
+ type: "object",
97
+ additionalProperties: false,
98
+ required: ["i", "match", "reason", "confidence"],
99
+ properties: {
100
+ i: { type: "integer" },
101
+ match: { type: "integer" },
102
+ reason: { type: "string", enum: Object.values(TwinReason) },
103
+ confidence: { type: "string", enum: [...CONFIDENCES] },
104
+ },
105
+ },
106
+ },
107
+ },
108
+ };
109
+ /**
110
+ * Renders the items of one request as the user message the model reads.
111
+ */
112
+ export function renderPlaceTwinItems(items) {
113
+ return items
114
+ .map((item, i) => stringifyJSON({
115
+ i,
116
+ added: { names: item.names, placetype: item.placetype, country: item.country },
117
+ lat: Number(item.latitude.toFixed(3)),
118
+ lon: Number(item.longitude.toFixed(3)),
119
+ candidates: item.candidates.map((candidate, index) => ({
120
+ index,
121
+ names: candidate.names,
122
+ placetype: candidate.placetype,
123
+ km: Number(candidate.km.toFixed(1)),
124
+ })),
125
+ }))
126
+ .join("\n");
127
+ }
128
+ /**
129
+ * Builds the Messages parameters of one request.
130
+ */
131
+ export function placeTwinRequestParams(items, options) {
132
+ return {
133
+ model: options.model,
134
+ max_tokens: 8000,
135
+ system: PLACE_TWIN_SYSTEM_PROMPT,
136
+ output_config: { effort: options.effort, format: { type: "json_schema", schema: PLACE_TWIN_RESPONSE_SCHEMA } },
137
+ messages: [{ role: "user", content: renderPlaceTwinItems(items) }],
138
+ };
139
+ }
140
+ const REASONS = new Set(Object.values(TwinReason));
141
+ const CONFIDENCE_SET = new Set(CONFIDENCES);
142
+ /**
143
+ * Parses one response into a label per item, given the candidate count of each item of the request.
144
+ *
145
+ * @throws When the text fails to parse as the schema's object, an index is outside
146
+ * the request or repeated, an item is unlabeled, a value is outside its enumeration,
147
+ * a match index is outside the item's candidates, or a match and its reason disagree.
148
+ */
149
+ export function parsePlaceTwinResponse(text, candidateCounts) {
150
+ const parsed = tryParsingJSON(text);
151
+ if (!parsed || !Array.isArray(parsed.labels))
152
+ throw new Error("The response holds no `labels` array");
153
+ const labels = candidateCounts.map(() => null);
154
+ for (const entry of parsed.labels) {
155
+ const { i, match, reason, confidence } = entry;
156
+ if (typeof i !== "number" || !Number.isInteger(i) || i < 0 || i >= labels.length) {
157
+ throw new Error(`The response labels index ${String(i)}, and the request held ${labels.length} items`);
158
+ }
159
+ if (labels[i])
160
+ throw new Error(`The response labels index ${i} twice`);
161
+ if (typeof reason !== "string" || !REASONS.has(reason))
162
+ throw new Error(`Index ${i} has the reason ${String(reason)}`);
163
+ if (typeof confidence !== "string" || !CONFIDENCE_SET.has(confidence)) {
164
+ throw new Error(`Index ${i} has the confidence ${String(confidence)}`);
165
+ }
166
+ if (typeof match !== "number" || !Number.isInteger(match) || match < -1 || match >= candidateCounts[i]) {
167
+ throw new Error(`Index ${i} pairs with candidate ${String(match)} of ${candidateCounts[i]}`);
168
+ }
169
+ if (MATCH_REASONS.has(reason) !== match >= 0) {
170
+ throw new Error(`Index ${i} gives the reason ${reason} with the match ${match}`);
171
+ }
172
+ labels[i] = {
173
+ match: match >= 0 ? match : null,
174
+ reason: reason,
175
+ confidence: confidence,
176
+ };
177
+ }
178
+ const missing = labels.findIndex((label) => label == null);
179
+ if (missing !== -1)
180
+ throw new Error(`The response leaves index ${missing} of ${labels.length} unlabeled`);
181
+ return labels;
182
+ }
183
+ //# sourceMappingURL=prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../lib/tools/place-twins/prompt.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAI3E;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB;;OAEG;IACH,eAAe,EAAE,iBAAiB;IAClC;;OAEG;IACH,WAAW,EAAE,aAAa;IAC1B;;OAEG;IACH,QAAQ,EAAE,UAAU;IACpB;;OAEG;IACH,KAAK,EAAE,YAAY;IACnB;;OAEG;IACH,SAAS,EAAE,iBAAiB;IAC5B;;OAEG;IACH,OAAO,EAAE,SAAS;CACT,CAAA;AAIV,MAAM,aAAa,GAAwB,IAAI,GAAG,CAAC;IAClD,UAAU,CAAC,eAAe;IAC1B,UAAU,CAAC,WAAW;IACtB,UAAU,CAAC,QAAQ;IACnB,UAAU,CAAC,KAAK;CAChB,CAAC,CAAA;AAEF,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAU,CAAA;AAmDtD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC7B;;OAEG;IACH,SAAS,EAAE,WAAW;IACtB;;;OAGG;IACH,WAAW,EAAE,cAAc;IAC3B;;OAEG;IACH,SAAS,EAAE,WAAW;CACb,CAAA;AAgBV;;;;GAIG;AACH,MAAM,CAAC,MAAM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a,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,qBAAqB,MAAM,mBAAmB,KAAK,EAAE,CAAC,CAAA;QACjF,CAAC;QAED,MAAM,CAAC,CAAC,CAAC,GAAG;YACX,KAAK,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;YAChC,MAAM,EAAE,MAAoB;YAC5B,UAAU,EAAE,UAA4B;SACxC,CAAA;IACF,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC,CAAA;IAE1D,IAAI,OAAO,KAAK,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,OAAO,OAAO,MAAM,CAAC,MAAM,YAAY,CAAC,CAAA;IAEzG,OAAO,MAAqB,CAAA;AAC7B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=prominent-shapes.run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prominent-shapes.run.d.ts","sourceRoot":"","sources":["../../../lib/tools/prominent-shapes/prominent-shapes.run.ts"],"names":[],"mappings":""}
@@ -0,0 +1,302 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+ /**
4
+ * @file Writes candidate rows of the ordinary query forms of each country's prominent places (#3156).
5
+ *
6
+ * Usage:
7
+ * node --env-file=.env packages/corpus/lib/tools/prominent-shapes/prominent-shapes.run.ts <mode> --out <dir> \
8
+ * [--places <places.parquet>] [--wof-db <path>] [--model <id>] [--effort <level>] [--forms N] \
9
+ * [--places-per-request N] [--max-tokens N] [--max-per-band N] [--budget <dollars>] [--probe-request N] \
10
+ * [--results <results.jsonl>]
11
+ *
12
+ * `seeds` reads the seeds and writes `seeds.jsonl` and their counts.
13
+ * `probe` sends one request outside a batch and writes `probe.json`: its token counts, what the
14
+ * validator kept, and the cost those counts project for every seed at the batch price.
15
+ * `submit` creates the batch, and refuses when the probe's projection exceeds `--budget`.
16
+ * `status` prints the batch's state.
17
+ * `collect` saves the batch's results, validates them, and writes `candidates.jsonl` and `summary.json`.
18
+ * With `--results` it validates that saved results file and sends no request.
19
+ * Its summary lists each request whose every form dropped under one reason.
20
+ *
21
+ * The output is a candidates file for review. No corpus build reads it.
22
+ */
23
+ import { pluckResponseData } from "@mailwoman/core/api";
24
+ import { readLocalJSONFile, readLocalTextFile } from "@mailwoman/core/fs/readers";
25
+ import { makeDirectories, writeLocalJSONFile, writeLocalJSONLFile } from "@mailwoman/core/fs/writers";
26
+ import { parseArguments } from "@mailwoman/core/scripting/arguments";
27
+ import { stringifyJSON } from "@mailwoman/core/values/json";
28
+ import { wofDatabasePath } from "@mailwoman/resolver-wof-sqlite/paths";
29
+ import { resolvePath } from "path-ts";
30
+ import { JSONSpliterator } from "spliterator";
31
+ import { batchCostUSD, createAnthropicClient, createMessageBatch, parseMessageBatchResults, readMessageBatch, readMessageBatchResults, resultText, } from "#tools/anthropic/batches";
32
+ import { renderShapeRequest, shapeRequestID, shapeRequestParams } from "#tools/prominent-shapes/prompt";
33
+ import { readShapeSeeds } from "#tools/prominent-shapes/read-seeds";
34
+ import { chunkSeedsByCountry, limitSeedsPerBand } from "#tools/prominent-shapes/seeds";
35
+ import { validateResponse, wholeResponseDropReason, } from "#tools/prominent-shapes/validate";
36
+ /**
37
+ * The batch price of the default model, in dollars per million tokens.
38
+ */
39
+ const BATCH_PRICE = { input: 2, output: 10 };
40
+ const MESSAGES_URL = "https://api.anthropic.com/v1/messages";
41
+ const { values, positionals } = parseArguments({
42
+ allowPositionals: true,
43
+ options: {
44
+ out: { type: "string" },
45
+ places: { type: "string" },
46
+ "wof-db": { type: "string" },
47
+ model: { type: "string" },
48
+ effort: { type: "string" },
49
+ forms: { type: "string" },
50
+ "places-per-request": { type: "string" },
51
+ "max-tokens": { type: "string" },
52
+ "max-per-band": { type: "string" },
53
+ budget: { type: "string" },
54
+ "probe-request": { type: "string" },
55
+ results: { type: "string" },
56
+ },
57
+ });
58
+ const [mode] = positionals;
59
+ if (!values.out)
60
+ throw new Error("--out <dir> names the run directory");
61
+ const out = resolvePath(values.out).toString();
62
+ const outFile = (name) => resolvePath(out, name).toString();
63
+ const settings = {
64
+ model: values.model ?? "claude-opus-5-5",
65
+ effort: values.effort ?? "low",
66
+ formsPerPlace: Number(values.forms ?? 12),
67
+ maxTokens: Number(values["max-tokens"] ?? 4000),
68
+ };
69
+ const placesPerRequest = Number(values["places-per-request"] ?? 10);
70
+ const budget = Number(values.budget ?? 60);
71
+ function count(items, key) {
72
+ const counts = {};
73
+ for (const item of items) {
74
+ counts[key(item)] = (counts[key(item)] ?? 0) + 1;
75
+ }
76
+ return Object.fromEntries(Object.entries(counts).toSorted(([a], [b]) => a.localeCompare(b)));
77
+ }
78
+ async function readSeedFile() {
79
+ const seeds = [];
80
+ for await (const seed of JSONSpliterator.fromAsync(outFile("seeds.jsonl"))) {
81
+ seeds.push(seed);
82
+ }
83
+ if (!seeds.length)
84
+ throw new Error(`${outFile("seeds.jsonl")} holds no seed; run the seeds mode first`);
85
+ return seeds;
86
+ }
87
+ await makeDirectories(out);
88
+ if (mode === "seeds") {
89
+ const read = await readShapeSeeds({
90
+ placesParquet: resolvePath(values.places ?? "/mnt/mw/audits/v0822-build/prominent-census-2/places.parquet").toString(),
91
+ wofDatabase: (values["wof-db"] ?? wofDatabasePath("admin-global-priority.db")).toString(),
92
+ });
93
+ const seeds = values["max-per-band"] ? limitSeedsPerBand(read.seeds, Number(values["max-per-band"])) : read.seeds;
94
+ await writeLocalJSONLFile(seeds, outFile("seeds.jsonl"));
95
+ const record = {
96
+ selected: read.selected,
97
+ skipped: read.skipped,
98
+ seeds_read: read.seeds.length,
99
+ seeds: seeds.length,
100
+ by_band: count(seeds, (seed) => seed.band),
101
+ by_place_tag: count(seeds, (seed) => `${seed.place_tag}${seed.parent_tag ? `+${seed.parent_tag}` : ""}`),
102
+ countries: new Set(seeds.map((seed) => seed.country)).size,
103
+ countries_by_band: count([...new Set(seeds.map((seed) => `${seed.band}\u0000${seed.country}`))], (key) => key.split("\u0000")[0]),
104
+ by_country: count(seeds, (seed) => seed.country),
105
+ requests: chunkSeedsByCountry(seeds, placesPerRequest).length,
106
+ };
107
+ await writeLocalJSONFile(record, outFile("seeds-summary.json"));
108
+ console.log(stringifyJSON(record));
109
+ }
110
+ else if (mode === "probe") {
111
+ const seeds = await readSeedFile();
112
+ const chunks = chunkSeedsByCountry(seeds, placesPerRequest);
113
+ const full = chunks.map((chunk, index) => ({ chunk, index })).filter(({ chunk }) => chunk.length === placesPerRequest);
114
+ const index = values["probe-request"] ? Number(values["probe-request"]) : full[Math.floor(full.length / 2)].index;
115
+ const chunk = chunks[index];
116
+ if (!chunk)
117
+ throw new Error(`--probe-request ${index} is outside the ${chunks.length} requests`);
118
+ console.error(renderShapeRequest(chunk, settings.formsPerPlace));
119
+ const message = (await createAnthropicClient()
120
+ .fetch({
121
+ url: MESSAGES_URL,
122
+ method: "post",
123
+ timeout: 600_000,
124
+ data: shapeRequestParams(chunk, settings),
125
+ cache: false,
126
+ })
127
+ .then(pluckResponseData));
128
+ const text = message.content.find((block) => block.type === "text")?.text ?? "";
129
+ console.error(text);
130
+ const validated = validateResponse(text, chunk);
131
+ if (!validated)
132
+ throw new Error(`The probe response isn't the schema's shape (stop reason ${message.stop_reason})`);
133
+ // Tokens per place from this request, applied to every seed at the batch price.
134
+ const scale = seeds.length / chunk.length;
135
+ const record = {
136
+ model: settings.model,
137
+ forms_per_place: settings.formsPerPlace,
138
+ places: chunk.length,
139
+ usage: message.usage,
140
+ stop_reason: message.stop_reason,
141
+ forms_returned: validated.returned,
142
+ forms_kept: validated.kept.length,
143
+ drops: validated.drops,
144
+ seeds: seeds.length,
145
+ requests: chunks.length,
146
+ projected_batch_cost_usd: (message.usage.input_tokens * scale * BATCH_PRICE.input +
147
+ message.usage.output_tokens * scale * BATCH_PRICE.output) /
148
+ 1_000_000,
149
+ };
150
+ await writeLocalJSONFile(record, outFile("probe.json"));
151
+ await writeLocalJSONLFile(validated.kept, outFile("probe-kept.jsonl"));
152
+ console.log(stringifyJSON(record));
153
+ }
154
+ else if (mode === "submit") {
155
+ const seeds = await readSeedFile();
156
+ const probe = await readLocalJSONFile(outFile("probe.json"));
157
+ if (probe.seeds !== seeds.length ||
158
+ probe.forms_per_place !== settings.formsPerPlace ||
159
+ probe.model !== settings.model) {
160
+ throw new Error("probe.json measures other seeds, forms or model than this submit; run the probe mode again");
161
+ }
162
+ if (!(probe.projected_batch_cost_usd <= budget)) {
163
+ throw new Error(`The probe projects $${probe.projected_batch_cost_usd.toFixed(2)}, over the $${budget} budget`);
164
+ }
165
+ const chunks = chunkSeedsByCountry(seeds, placesPerRequest);
166
+ const requests = chunks.map((chunk, index) => ({
167
+ custom_id: shapeRequestID(index),
168
+ params: shapeRequestParams(chunk, settings),
169
+ }));
170
+ const batch = await createMessageBatch(createAnthropicClient(), requests);
171
+ const record = {
172
+ batch_id: batch.id,
173
+ model: settings.model,
174
+ effort: settings.effort,
175
+ forms_per_place: settings.formsPerPlace,
176
+ requests: chunks.map((chunk, index) => ({
177
+ custom_id: shapeRequestID(index),
178
+ wof_ids: chunk.map((seed) => seed.wof_id),
179
+ })),
180
+ };
181
+ await writeLocalJSONFile(record, outFile("batch.json"));
182
+ console.log(stringifyJSON({ batch_id: batch.id, requests: requests.length, status: batch.processing_status }));
183
+ }
184
+ else if (mode === "status") {
185
+ const record = await readLocalJSONFile(outFile("batch.json"));
186
+ console.log(stringifyJSON(await readMessageBatch(createAnthropicClient(), record.batch_id)));
187
+ }
188
+ else if (mode === "collect") {
189
+ const record = await readLocalJSONFile(outFile("batch.json"));
190
+ const seeds = await readSeedFile();
191
+ const seedByID = new Map(seeds.map((seed) => [seed.wof_id, seed]));
192
+ const savedResults = values.results ? resolvePath(values.results).toString() : null;
193
+ let results;
194
+ if (savedResults) {
195
+ // A saved file is validated again without a request to the API, and is left as it is.
196
+ results = parseMessageBatchResults(await readLocalTextFile(savedResults), savedResults);
197
+ }
198
+ else {
199
+ results = await readMessageBatchResults(createAnthropicClient(), record.batch_id);
200
+ // The paid responses are saved before anything reads them.
201
+ await writeLocalJSONLFile(results, outFile("results.jsonl"));
202
+ }
203
+ const wholeDrops = [];
204
+ const resultByID = new Map(results.map((result) => [result.custom_id, result]));
205
+ const outcomes = {};
206
+ const drops = {};
207
+ const candidates = [];
208
+ const answered = new Set();
209
+ let formsReturned = 0;
210
+ const tally = (outcome) => {
211
+ outcomes[outcome] = (outcomes[outcome] ?? 0) + 1;
212
+ };
213
+ for (const request of record.requests) {
214
+ const result = resultByID.get(request.custom_id);
215
+ if (!result) {
216
+ tally("missing");
217
+ continue;
218
+ }
219
+ if (result.result.type !== "succeeded") {
220
+ tally(result.result.type);
221
+ continue;
222
+ }
223
+ const text = resultText(result);
224
+ if (text == null) {
225
+ tally(`succeeded_stop_${result.result.message?.stop_reason ?? "unknown"}`);
226
+ continue;
227
+ }
228
+ const requestSeeds = request.wof_ids.map((id) => {
229
+ const seed = seedByID.get(id);
230
+ if (!seed)
231
+ throw new Error(`batch.json names place ${id}, which seeds.jsonl doesn't hold`);
232
+ return seed;
233
+ });
234
+ const validated = validateResponse(text, requestSeeds);
235
+ if (!validated) {
236
+ tally("succeeded_unreadable");
237
+ continue;
238
+ }
239
+ tally("succeeded");
240
+ formsReturned += validated.returned;
241
+ const wholeDrop = wholeResponseDropReason(validated);
242
+ if (wholeDrop != null) {
243
+ wholeDrops.push({
244
+ custom_id: request.custom_id,
245
+ country: requestSeeds[0]?.country ?? "",
246
+ places: requestSeeds.length,
247
+ forms: validated.returned,
248
+ reason: wholeDrop,
249
+ });
250
+ }
251
+ for (const id of validated.answered) {
252
+ answered.add(id);
253
+ }
254
+ for (const [reason, n] of Object.entries(validated.drops)) {
255
+ drops[reason] = (drops[reason] ?? 0) + (n ?? 0);
256
+ }
257
+ for (const form of validated.kept) {
258
+ candidates.push({ ...form, model: record.model, batch_id: record.batch_id, custom_id: request.custom_id });
259
+ }
260
+ }
261
+ await writeLocalJSONLFile(candidates, outFile("candidates.jsonl"));
262
+ const keptPlaces = new Set(candidates.map((candidate) => candidate.wof_id));
263
+ const keptCountries = new Set(candidates.map((candidate) => candidate.country));
264
+ const summary = {
265
+ batch_id: record.batch_id,
266
+ model: record.model,
267
+ effort: record.effort,
268
+ forms_per_place: record.forms_per_place,
269
+ seeds: seeds.length,
270
+ seeds_by_band: count(seeds, (seed) => seed.band),
271
+ requests: record.requests.length,
272
+ results: results.length,
273
+ results_by_outcome: outcomes,
274
+ places_answered: answered.size,
275
+ forms_returned: formsReturned,
276
+ candidates_kept: candidates.length,
277
+ candidates_with_keys_from_letters: candidates.filter((candidate) => candidate.keys_from_letters).length,
278
+ drops_by_reason: Object.fromEntries(Object.entries(drops).toSorted(([a], [b]) => a.localeCompare(b))),
279
+ requests_dropped_whole_for_one_reason: wholeDrops,
280
+ requests_dropped_whole_by_reason: count(wholeDrops, (drop) => drop.reason),
281
+ places_without_a_candidate: seeds.length - keptPlaces.size,
282
+ results_read_from: savedResults ?? "the batch's results endpoint",
283
+ kept_by_shape: count(candidates, (candidate) => candidate.shape),
284
+ kept_by_band: count(candidates, (candidate) => candidate.band),
285
+ kept_by_band_and_shape: count(candidates, (candidate) => `${candidate.band}:${candidate.shape}`),
286
+ places_with_a_candidate: keptPlaces.size,
287
+ places_with_a_candidate_by_band: count(seeds.filter((seed) => keptPlaces.has(seed.wof_id)), (seed) => seed.band),
288
+ countries_with_a_candidate: keptCountries.size,
289
+ countries_with_zero_candidates: [...new Set(seeds.map((seed) => seed.country))]
290
+ .filter((country) => !keptCountries.has(country))
291
+ .toSorted(),
292
+ span_offsets: "UTF-16 code units, end exclusive",
293
+ price_usd_per_million_tokens: BATCH_PRICE,
294
+ measured_cost_usd: batchCostUSD(results, BATCH_PRICE),
295
+ };
296
+ await writeLocalJSONFile(summary, outFile("summary.json"));
297
+ console.log(stringifyJSON(summary));
298
+ }
299
+ else {
300
+ throw new Error("expected one of seeds, probe, submit, status, collect");
301
+ }
302
+ //# sourceMappingURL=prominent-shapes.run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prominent-shapes.run.js","sourceRoot":"","sources":["../../../lib/tools/prominent-shapes/prominent-shapes.run.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,kEAAkE;AAElE;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AACjF,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AACrG,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,EACN,YAAY,EACZ,qBAAqB,EACrB,kBAAkB,EAIlB,wBAAwB,EACxB,gBAAgB,EAChB,uBAAuB,EACvB,UAAU,GAEV,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACvG,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AACnE,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAkB,MAAM,+BAA+B,CAAA;AACtG,OAAO,EAGN,gBAAgB,EAChB,uBAAuB,GACvB,MAAM,kCAAkC,CAAA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KACrD,CAAA;IAED,MAAM,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAA;IAE1D,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;AACpC,CAAC;KAAM,CAAC;IACP,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAA;AACzE,CAAC"}
@@ -0,0 +1,74 @@
1
+ import type { MessageBatchRequest } from "#tools/anthropic/batches";
2
+ import { type ShapeSeed } from "#tools/prominent-shapes/seeds";
3
+ /**
4
+ * The instructions every request shares.
5
+ */
6
+ export declare const SHAPE_SYSTEM_PROMPT: string;
7
+ /**
8
+ * The structured-output schema of a response.
9
+ */
10
+ export declare const SHAPE_RESPONSE_SCHEMA: {
11
+ readonly type: "object";
12
+ readonly additionalProperties: false;
13
+ readonly required: readonly ["places"];
14
+ readonly properties: {
15
+ readonly places: {
16
+ readonly type: "array";
17
+ readonly items: {
18
+ readonly type: "object";
19
+ readonly additionalProperties: false;
20
+ readonly required: readonly ["id", "forms"];
21
+ readonly properties: {
22
+ readonly id: {
23
+ readonly type: "string";
24
+ };
25
+ readonly forms: {
26
+ readonly type: "array";
27
+ readonly items: {
28
+ readonly type: "object";
29
+ readonly additionalProperties: false;
30
+ readonly required: readonly ["raw", "uses"];
31
+ readonly properties: {
32
+ readonly raw: {
33
+ readonly type: "string";
34
+ };
35
+ readonly uses: {
36
+ readonly type: "array";
37
+ readonly items: {
38
+ readonly type: "string";
39
+ };
40
+ };
41
+ };
42
+ };
43
+ };
44
+ };
45
+ };
46
+ };
47
+ };
48
+ };
49
+ /**
50
+ * Renders the places of one request as the user message.
51
+ *
52
+ * Every seed is of one country, and that country's surfaces are listed once from the first seed.
53
+ *
54
+ * @throws When the seeds are empty or of more than one country.
55
+ */
56
+ export declare function renderShapeRequest(seeds: readonly ShapeSeed[], formsPerPlace: number): string;
57
+ /**
58
+ * The settings of a run's requests.
59
+ */
60
+ export interface ShapeRequestOptions {
61
+ model: string;
62
+ effort: string;
63
+ formsPerPlace: number;
64
+ maxTokens: number;
65
+ }
66
+ /**
67
+ * Builds the Messages parameters of one request.
68
+ */
69
+ export declare function shapeRequestParams(seeds: readonly ShapeSeed[], options: ShapeRequestOptions): MessageBatchRequest["params"];
70
+ /**
71
+ * The batch id of the request at `index`.
72
+ */
73
+ export declare function shapeRequestID(index: number): string;
74
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../lib/tools/prominent-shapes/prompt.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AACnE,OAAO,EAAoB,KAAK,SAAS,EAAe,MAAM,+BAA+B,CAAA;AAW7F;;GAEG;AACH,eAAO,MAAM,mBAAmB,QA8BpB,CAAA;AAEZ;;GAEG;AACH,eAAO,MAAM,qBAAqB;aACjC,IAAI,EAAE,QAAQ;aACd,oBAAoB;aACpB,QAAQ,YAAG,QAAQ;aACnB,UAAU;iBACT,MAAM;qBACL,IAAI,EAAE,OAAO;qBACb,KAAK;yBACJ,IAAI,EAAE,QAAQ;yBACd,oBAAoB;yBACpB,QAAQ,YAAG,IAAI,EAAE,OAAO;yBACxB,UAAU;6BACT,EAAE;iCAAI,IAAI,EAAE,QAAQ;;6BACpB,KAAK;iCACJ,IAAI,EAAE,OAAO;iCACb,KAAK;qCACJ,IAAI,EAAE,QAAQ;qCACd,oBAAoB;qCACpB,QAAQ,YAAG,KAAK,EAAE,MAAM;qCACxB,UAAU;yCACT,GAAG;6CAAI,IAAI,EAAE,QAAQ;;yCACrB,IAAI;6CAAI,IAAI,EAAE,OAAO;6CAAE,KAAK;iDAAI,IAAI,EAAE,QAAQ;;;;;;;;;;CAQ5C,CAAA;AA2BV;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,aAAa,EAAE,MAAM,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