From 705ad09de77a299f83eaaf91572f71fe8ae77765 Mon Sep 17 00:00:00 2001 From: Jeremy Howard Date: Sun, 27 Oct 2024 18:51:06 +1000 Subject: [PATCH] fixes #16 --- 00_xml.ipynb | 90 +++++++++++++++++--------------------------------- toolslm/xml.py | 6 ++-- 2 files changed, 33 insertions(+), 63 deletions(-) diff --git a/00_xml.ipynb b/00_xml.ipynb index c049b0e..065b433 100644 --- a/00_xml.ipynb +++ b/00_xml.ipynb @@ -225,7 +225,7 @@ { "data": { "text/plain": [ - "doctype(source='\\nb8898fab\\n', content='\\nThis is a sample\\n')" + "doctype(source='\\n47e19350\\n', content='\\nThis is a \"sample\"\\n')" ] }, "execution_count": null, @@ -234,7 +234,7 @@ } ], "source": [ - "doc = 'This is a sample'\n", + "doc = 'This is a \"sample\"'\n", "mk_doctype(doc)" ] }, @@ -253,8 +253,8 @@ " ) -> tuple:\n", " \"Create an `ft` format tuple for a single doc in Anthropic's recommended format\"\n", " dt = mk_doctype(content, source)\n", - " content = Document_content(dt.content)\n", - " source = Source(dt.source)\n", + " content = Document_content(NotStr(dt.content))\n", + " source = Source(NotStr(dt.source))\n", " return Document(source, content, index=index, **kwargs)" ] }, @@ -276,19 +276,15 @@ "data": { "text/markdown": [ "```html\n", - "\n", - " \n", - "b8898fab\n", - "\n", - " \n", - "This is a sample\n", - "\n", - "\n", - "\n", + "\n", + "47e19350\n", + "\n", + "This is a \"sample\"\n", + "\n", "```" ], "text/plain": [ - "document((source(('\\nb8898fab\\n',),{}), document-content(('\\nThis is a sample\\n',),{})),{'index': 1, 'title': 'test'})" + "document((source(('\\n47e19350\\n',),{}), document-content(('\\nThis is a \"sample\"\\n',),{})),{'index': 1, 'title': 'test'})" ] }, "execution_count": null, @@ -341,25 +337,15 @@ "text": [ "Here are some documents for you to reference for your task:\n", "\n", - "\n", - " \n", - " \n", - "b8898fab\n", - "\n", - " \n", - "This is a sample\n", - "\n", - " \n", - " \n", - " \n", + "\n", + "47e19350\n", + "\n", + "This is a \"sample\"\n", + "\n", "doc.txt\n", - "\n", - " \n", + "\n", "And another one\n", - "\n", - " \n", - "\n", - "\n" + "\n" ] } ], @@ -430,29 +416,19 @@ "```xml\n", "Here are some documents for you to reference for your task:\n", "\n", - "\n", - " \n", - " \n", + "\n", "samples/sample_core.py\n", - "\n", - " \n", + "\n", "import inspect\n", "empty = inspect.Parameter.empty\n", - "models = 'claude-3-opus-20240229','claude-3-sonnet-20240229','claude-3-haiku-20240307'\n", - "\n", - " \n", - " \n", - " \n", + "models = 'claude-3-opus-20240229','claude-3-sonnet-20240229','claude-3-haiku-20240307'\n", + "\n", "samples/sample_styles.css\n", - "\n", - " \n", + "\n", ".cell { margin-bottom: 1rem; }\n", - ".cell > .sourceCode { margin-bottom: 0; }\n", - ".cell-output > pre { margin-bottom: 0; }\n", - "\n", - " \n", - "\n", - "\n", + ".cell > .sourceCode { margin-bottom: 0; }\n", + ".cell-output > pre { margin-bottom: 0; }\n", + "\n", "```" ], "text/plain": [ @@ -505,19 +481,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n", - " \n", - " \n", + "\n", "samples/sample_core.py\n", - "\n", - " \n", + "\n", "import inspect\n", "empty = inspect.Parameter.empty\n", - "models = 'claude-3-opus-20240229','claude-3-sonnet-20240229','claude-3-haiku-20240307'\n", - "\n", - " \n", - "\n", - "\n" + "models = 'claude-3-opus-20240229','claude-3-sonnet-20240229','claude-3-haiku-20240307'\n", + "\n" ] } ], @@ -540,7 +510,7 @@ " folder:str, # Folder name containing files to add to context\n", " **kwargs # Passed to `folder2ctx`\n", ")->str: # XML for Claude context\n", - " return folder2ctx(folder, **kwargs)" + " print(folder2ctx(folder, **kwargs))" ] }, { diff --git a/toolslm/xml.py b/toolslm/xml.py index fff881f..4e6e8b7 100644 --- a/toolslm/xml.py +++ b/toolslm/xml.py @@ -58,8 +58,8 @@ def mk_doc(index:int, # The document index ) -> tuple: "Create an `ft` format tuple for a single doc in Anthropic's recommended format" dt = mk_doctype(content, source) - content = Document_content(dt.content) - source = Source(dt.source) + content = Document_content(NotStr(dt.content)) + source = Source(NotStr(dt.source)) return Document(source, content, index=index, **kwargs) # %% ../00_xml.ipynb 19 @@ -101,4 +101,4 @@ def folder2ctx_cli( folder:str, # Folder name containing files to add to context **kwargs # Passed to `folder2ctx` )->str: # XML for Claude context - return folder2ctx(folder, **kwargs) + print(folder2ctx(folder, **kwargs))