Skip to content

Commit 0979737

Browse files
committed
minor cleanup
1 parent 61f8eca commit 0979737

File tree

2 files changed

+97
-33
lines changed

2 files changed

+97
-33
lines changed

00_xml.ipynb

Lines changed: 96 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
{
2222
"cell_type": "markdown",
2323
"id": "ff6f6471-8061-4fdd-85a1-25fdc27c5cf3",
24-
"metadata": {},
24+
"metadata": {
25+
"heading_collapsed": true
26+
},
2527
"source": [
2628
"## Setup"
2729
]
@@ -30,7 +32,9 @@
3032
"cell_type": "code",
3133
"execution_count": null,
3234
"id": "033c76fd",
33-
"metadata": {},
35+
"metadata": {
36+
"hidden": true
37+
},
3438
"outputs": [],
3539
"source": [
3640
"#| export\n",
@@ -50,7 +54,9 @@
5054
"cell_type": "code",
5155
"execution_count": null,
5256
"id": "2795f9fc",
53-
"metadata": {},
57+
"metadata": {
58+
"hidden": true
59+
},
5460
"outputs": [],
5561
"source": [
5662
"#| exports\n",
@@ -73,7 +79,9 @@
7379
{
7480
"cell_type": "markdown",
7581
"id": "140a35a2",
76-
"metadata": {},
82+
"metadata": {
83+
"hidden": true
84+
},
7785
"source": [
7886
"JSON doesn't map as nicely to XML as the data structure used in `fastcore.xml`, but for simple XML trees it can be convenient -- for example:"
7987
]
@@ -82,7 +90,9 @@
8290
"cell_type": "code",
8391
"execution_count": null,
8492
"id": "005a5be4",
85-
"metadata": {},
93+
"metadata": {
94+
"hidden": true
95+
},
8696
"outputs": [
8797
{
8898
"data": {
@@ -119,15 +129,19 @@
119129
{
120130
"cell_type": "markdown",
121131
"id": "7788c48c",
122-
"metadata": {},
132+
"metadata": {
133+
"heading_collapsed": true
134+
},
123135
"source": [
124136
"## Including documents"
125137
]
126138
},
127139
{
128140
"cell_type": "markdown",
129141
"id": "479be4c9",
130-
"metadata": {},
142+
"metadata": {
143+
"hidden": true
144+
},
131145
"source": [
132146
"According [to Anthropic](https://docs.anthropic.com/claude/docs/long-context-window-tips), \"*it's essential to structure your prompts in a way that clearly separates the input data from the instructions*\". They recommend using the following format:\n",
133147
"\n",
@@ -153,7 +167,9 @@
153167
"cell_type": "code",
154168
"execution_count": null,
155169
"id": "a01dc320",
156-
"metadata": {},
170+
"metadata": {
171+
"hidden": true
172+
},
157173
"outputs": [],
158174
"source": [
159175
"#| exports\n",
@@ -163,7 +179,9 @@
163179
{
164180
"cell_type": "markdown",
165181
"id": "6620a123",
166-
"metadata": {},
182+
"metadata": {
183+
"hidden": true
184+
},
167185
"source": [
168186
"We'll use `doctype` to store our pairs."
169187
]
@@ -172,7 +190,9 @@
172190
"cell_type": "code",
173191
"execution_count": null,
174192
"id": "ce853491",
175-
"metadata": {},
193+
"metadata": {
194+
"hidden": true
195+
},
176196
"outputs": [],
177197
"source": [
178198
"#| exports\n",
@@ -186,7 +206,9 @@
186206
{
187207
"cell_type": "markdown",
188208
"id": "026d3b06",
189-
"metadata": {},
209+
"metadata": {
210+
"hidden": true
211+
},
190212
"source": [
191213
"Since Anthropic's example shows newlines before and after each tag, we'll do the same."
192214
]
@@ -195,7 +217,9 @@
195217
"cell_type": "code",
196218
"execution_count": null,
197219
"id": "932e8858",
198-
"metadata": {},
220+
"metadata": {
221+
"hidden": true
222+
},
199223
"outputs": [],
200224
"source": [
201225
"#| exports\n",
@@ -210,7 +234,9 @@
210234
{
211235
"cell_type": "markdown",
212236
"id": "8800921b",
213-
"metadata": {},
237+
"metadata": {
238+
"hidden": true
239+
},
214240
"source": [
215241
"This is a convenience wrapper to ensure that a `doctype` has the needed information in the right format."
216242
]
@@ -219,7 +245,9 @@
219245
"cell_type": "code",
220246
"execution_count": null,
221247
"id": "14f9e185",
222-
"metadata": {},
248+
"metadata": {
249+
"hidden": true
250+
},
223251
"outputs": [
224252
{
225253
"data": {
@@ -241,7 +269,9 @@
241269
"cell_type": "code",
242270
"execution_count": null,
243271
"id": "d8913bd3",
244-
"metadata": {},
272+
"metadata": {
273+
"hidden": true
274+
},
245275
"outputs": [],
246276
"source": [
247277
"from fastcore.xml import xt"
@@ -251,7 +281,9 @@
251281
"cell_type": "code",
252282
"execution_count": null,
253283
"id": "3b8e6f87",
254-
"metadata": {},
284+
"metadata": {
285+
"hidden": true
286+
},
255287
"outputs": [],
256288
"source": [
257289
"#| exports\n",
@@ -270,7 +302,9 @@
270302
"cell_type": "code",
271303
"execution_count": null,
272304
"id": "15e454db",
273-
"metadata": {},
305+
"metadata": {
306+
"hidden": true
307+
},
274308
"outputs": [],
275309
"source": [
276310
"#| exports\n",
@@ -288,7 +322,9 @@
288322
{
289323
"cell_type": "markdown",
290324
"id": "a8b6ac26",
291-
"metadata": {},
325+
"metadata": {
326+
"hidden": true
327+
},
292328
"source": [
293329
"We can now generate XML for one document in the suggested format:"
294330
]
@@ -297,7 +333,9 @@
297333
"cell_type": "code",
298334
"execution_count": null,
299335
"id": "5782369d",
300-
"metadata": {},
336+
"metadata": {
337+
"hidden": true
338+
},
301339
"outputs": [],
302340
"source": [
303341
"dt = mk_doctype(doc)"
@@ -307,7 +345,9 @@
307345
"cell_type": "code",
308346
"execution_count": null,
309347
"id": "e7ed5a9a",
310-
"metadata": {},
348+
"metadata": {
349+
"hidden": true
350+
},
311351
"outputs": [
312352
{
313353
"name": "stdout",
@@ -333,7 +373,9 @@
333373
"cell_type": "code",
334374
"execution_count": null,
335375
"id": "ba5ebfab",
336-
"metadata": {},
376+
"metadata": {
377+
"hidden": true
378+
},
337379
"outputs": [],
338380
"source": [
339381
"#| exports\n",
@@ -351,7 +393,9 @@
351393
{
352394
"cell_type": "markdown",
353395
"id": "85004124",
354-
"metadata": {},
396+
"metadata": {
397+
"hidden": true
398+
},
355399
"source": [
356400
"Putting it all together, we have our final XML format:"
357401
]
@@ -360,7 +404,9 @@
360404
"cell_type": "code",
361405
"execution_count": null,
362406
"id": "1dac60f6",
363-
"metadata": {},
407+
"metadata": {
408+
"hidden": true
409+
},
364410
"outputs": [
365411
{
366412
"name": "stdout",
@@ -415,15 +461,19 @@
415461
{
416462
"cell_type": "markdown",
417463
"id": "65317fc6",
418-
"metadata": {},
464+
"metadata": {
465+
"heading_collapsed": true
466+
},
419467
"source": [
420468
"### File list to context"
421469
]
422470
},
423471
{
424472
"cell_type": "markdown",
425473
"id": "3778e8ed",
426-
"metadata": {},
474+
"metadata": {
475+
"hidden": true
476+
},
427477
"source": [
428478
"For generating XML context from files, we'll just read them as text and use the file names as `source`."
429479
]
@@ -432,7 +482,9 @@
432482
"cell_type": "code",
433483
"execution_count": null,
434484
"id": "0a168636",
435-
"metadata": {},
485+
"metadata": {
486+
"hidden": true
487+
},
436488
"outputs": [],
437489
"source": [
438490
"#| exports\n",
@@ -449,7 +501,9 @@
449501
"cell_type": "code",
450502
"execution_count": null,
451503
"id": "1bf73d36",
452-
"metadata": {},
504+
"metadata": {
505+
"hidden": true
506+
},
453507
"outputs": [
454508
{
455509
"data": {
@@ -565,10 +619,9 @@
565619
"@delegates(folder2ctx)\n",
566620
"def folder2ctx_cli(\n",
567621
" folder:str, # Folder name containing files to add to context\n",
568-
" prefix:bool=True, # Include Anthropic's suggested prose intro?\n",
569622
" **kwargs # Passed to `folder2ctx`\n",
570623
")->str: # XML for Claude context\n",
571-
" return folder2ctx(folder, prefix, **kwargs)"
624+
" return folder2ctx(folder, **kwargs)"
572625
]
573626
},
574627
{
@@ -596,7 +649,7 @@
596649
},
597650
{
598651
"cell_type": "code",
599-
"execution_count": null,
652+
"execution_count": 28,
600653
"id": "1e9ee5c1",
601654
"metadata": {},
602655
"outputs": [],
@@ -618,9 +671,21 @@
618671
],
619672
"metadata": {
620673
"kernelspec": {
621-
"display_name": "python3",
674+
"display_name": "Python 3 (ipykernel)",
622675
"language": "python",
623676
"name": "python3"
677+
},
678+
"language_info": {
679+
"codemirror_mode": {
680+
"name": "ipython",
681+
"version": 3
682+
},
683+
"file_extension": ".py",
684+
"mimetype": "text/x-python",
685+
"name": "python",
686+
"nbconvert_exporter": "python",
687+
"pygments_lexer": "ipython3",
688+
"version": "3.11.8"
624689
}
625690
},
626691
"nbformat": 4,

toolslm/xml.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def folder2ctx(
106106
@delegates(folder2ctx)
107107
def folder2ctx_cli(
108108
folder:str, # Folder name containing files to add to context
109-
prefix:bool=True, # Include Anthropic's suggested prose intro?
110109
**kwargs # Passed to `folder2ctx`
111110
)->str: # XML for Claude context
112-
return folder2ctx(folder, prefix, **kwargs)
111+
return folder2ctx(folder, **kwargs)

0 commit comments

Comments
 (0)