# toolslm
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
This is a work in progress…
## Install
``` sh
pip install toolslm
```
## How to use
### Context creation
toolslm has some helpers to make it easier to generate XML context from
files, for instance `folder2ctx`:
``` python
print(folder2ctx('samples', prefix=False, file_glob='*.py'))
```
<documents>
<document index="1">
<source>
samples/sample_core.py
</source>
<document_content>
import inspect
empty = inspect.Parameter.empty
models = 'claude-3-opus-20240229','claude-3-sonnet-20240229','claude-3-haiku-20240307'
</document_content>
</document>
</documents>
### XML helpers
Many language models work well with XML inputs, but XML can be a bit
clunky to work with manually. Therefore, toolslm includes a couple of
more streamlined approaches for XML generation.
An XML node contains a tag, optional children, and optional attributes.
`xt` creates a tuple of these three things, which we will use to general
XML shortly. Attributes are passed as kwargs; since these might conflict
with reserved words in Python, you can optionally add a `_` prefix and
it’ll be stripped off.
``` python
xt('x-custom', ['hi'], _class='bar')
```
('x-custom', ['hi'], {'class': 'bar'})
Claudette has functions defined for some common HTML elements to create
`xt` tuples more easily, including these:
``` python
from toolslm.xml import div,img,h1,h2,p,hr,html
```
``` python
a = html([
p('This is a paragraph'),
hr(),
img(src='http://example.prg'),
div([
h1('This is a header'),
h2('This is a sub-header', style='k:v'),
], _class='foo')
])
a
```
('html',
[('p', 'This is a paragraph', {}),
('hr', None, {}),
('img', None, {'src': 'http://example.prg'}),
('div',
[('h1', 'This is a header', {}),
('h2', 'This is a sub-header', {'style': 'k:v'})],
{'class': 'foo'})],
{})
To convert a tuple data structure created with `xt` and friends into
XML, use `to_xml`, adding the `hl` parameter to optionally add syntax
highlighting:
``` python
to_xml(a, hl=True)
```
``` xml
<html>
<p>This is a paragraph</p>
<hr />
<img src="http://example.prg" />
<div class="foo">
<h1>This is a header</h1>
<h2 style="k:v">This is a sub-header</h2>
</div>
</html>
```
JSON doesn’t map as nicely to XML as the `xt` data structure, but for
simple XML trees it can be convenient. The `json_to_xml` function
handles that conversion:
``` python
a = dict(surname='Howard', firstnames=['Jeremy','Peter'],
address=dict(state='Queensland',country='Australia'))
print(json_to_xml(a, 'person'))
```
<person>
<surname>Howard</surname>
<firstnames>
<item>Jeremy</item>
<item>Peter</item>
</firstnames>
<address>
<state>Queensland</state>
<country>Australia</country>
</address>
</person>
See the `xml source` section for a walkthru of XML and document context
generation functionality.
Raw data
{
"_id": null,
"home_page": "https://github.com/AnswerDotAI/toolslm",
"name": "toolslm",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "nbdev jupyter notebook python",
"author": "Jeremy Howard",
"author_email": "j@fast.ai",
"download_url": "https://files.pythonhosted.org/packages/57/d6/8d71bcb2e42a81c90cebcda49cde3f13bd16b80be2d3bfd36f838ad13039/toolslm-0.0.7.tar.gz",
"platform": null,
"description": "# toolslm\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\nThis is a work in progress\u2026\n\n## Install\n\n``` sh\npip install toolslm\n```\n\n## How to use\n\n### Context creation\n\ntoolslm has some helpers to make it easier to generate XML context from\nfiles, for instance `folder2ctx`:\n\n``` python\nprint(folder2ctx('samples', prefix=False, file_glob='*.py'))\n```\n\n <documents>\n <document index=\"1\">\n <source>\n samples/sample_core.py\n </source>\n <document_content>\n import inspect\n empty = inspect.Parameter.empty\n models = 'claude-3-opus-20240229','claude-3-sonnet-20240229','claude-3-haiku-20240307'\n </document_content>\n </document>\n </documents>\n\n### XML helpers\n\nMany language models work well with XML inputs, but XML can be a bit\nclunky to work with manually. Therefore, toolslm includes a couple of\nmore streamlined approaches for XML generation.\n\nAn XML node contains a tag, optional children, and optional attributes.\n`xt` creates a tuple of these three things, which we will use to general\nXML shortly. Attributes are passed as kwargs; since these might conflict\nwith reserved words in Python, you can optionally add a `_` prefix and\nit\u2019ll be stripped off.\n\n``` python\nxt('x-custom', ['hi'], _class='bar')\n```\n\n ('x-custom', ['hi'], {'class': 'bar'})\n\nClaudette has functions defined for some common HTML elements to create\n`xt` tuples more easily, including these:\n\n``` python\nfrom toolslm.xml import div,img,h1,h2,p,hr,html\n```\n\n``` python\na = html([\n p('This is a paragraph'),\n hr(),\n img(src='http://example.prg'),\n div([\n h1('This is a header'),\n h2('This is a sub-header', style='k:v'),\n ], _class='foo')\n])\na\n```\n\n ('html',\n [('p', 'This is a paragraph', {}),\n ('hr', None, {}),\n ('img', None, {'src': 'http://example.prg'}),\n ('div',\n [('h1', 'This is a header', {}),\n ('h2', 'This is a sub-header', {'style': 'k:v'})],\n {'class': 'foo'})],\n {})\n\nTo convert a tuple data structure created with `xt` and friends into\nXML, use `to_xml`, adding the `hl` parameter to optionally add syntax\nhighlighting:\n\n``` python\nto_xml(a, hl=True)\n```\n\n``` xml\n<html>\n <p>This is a paragraph</p>\n <hr />\n <img src=\"http://example.prg\" />\n <div class=\"foo\">\n <h1>This is a header</h1>\n <h2 style=\"k:v\">This is a sub-header</h2>\n </div>\n</html>\n```\n\nJSON doesn\u2019t map as nicely to XML as the `xt` data structure, but for\nsimple XML trees it can be convenient. The `json_to_xml` function\nhandles that conversion:\n\n``` python\na = dict(surname='Howard', firstnames=['Jeremy','Peter'],\n address=dict(state='Queensland',country='Australia'))\nprint(json_to_xml(a, 'person'))\n```\n\n <person>\n <surname>Howard</surname>\n <firstnames>\n <item>Jeremy</item>\n <item>Peter</item>\n </firstnames>\n <address>\n <state>Queensland</state>\n <country>Australia</country>\n </address>\n </person>\n\nSee the `xml source` section for a walkthru of XML and document context\ngeneration functionality.\n",
"bugtrack_url": null,
"license": "Apache Software License 2.0",
"summary": "Tools to make language models a bit easier to use",
"version": "0.0.7",
"project_urls": {
"Homepage": "https://github.com/AnswerDotAI/toolslm"
},
"split_keywords": [
"nbdev",
"jupyter",
"notebook",
"python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c7bcc46f03b62880791d34f8cc6d801217d3b808fb315b9d3ec88c75fe3eb06d",
"md5": "8f867ce574e6c12eff79bc9e6871a931",
"sha256": "cc22bf7ac41d45b9a250e6d322a0dfe662ec82a12a7c8eac22397ba0f8ec2d26"
},
"downloads": -1,
"filename": "toolslm-0.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8f867ce574e6c12eff79bc9e6871a931",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 16437,
"upload_time": "2024-10-23T02:02:43",
"upload_time_iso_8601": "2024-10-23T02:02:43.978989Z",
"url": "https://files.pythonhosted.org/packages/c7/bc/c46f03b62880791d34f8cc6d801217d3b808fb315b9d3ec88c75fe3eb06d/toolslm-0.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "57d68d71bcb2e42a81c90cebcda49cde3f13bd16b80be2d3bfd36f838ad13039",
"md5": "634a979b8a4d948e7b7931745b86ff59",
"sha256": "674200c368caed88a55306ef557639726f3b8445c0c708b30a128c85cef352b4"
},
"downloads": -1,
"filename": "toolslm-0.0.7.tar.gz",
"has_sig": false,
"md5_digest": "634a979b8a4d948e7b7931745b86ff59",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 17447,
"upload_time": "2024-10-23T02:02:45",
"upload_time_iso_8601": "2024-10-23T02:02:45.581419Z",
"url": "https://files.pythonhosted.org/packages/57/d6/8d71bcb2e42a81c90cebcda49cde3f13bd16b80be2d3bfd36f838ad13039/toolslm-0.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-23 02:02:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "AnswerDotAI",
"github_project": "toolslm",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "toolslm"
}