toolslm


Nametoolslm JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/AnswerDotAI/toolslm
SummaryTools to make language models a bit easier to use
upload_time2024-05-05 23:30:47
maintainerNone
docs_urlNone
authorJeremy Howard
requires_python>=3.9
licenseApache Software License 2.0
keywords nbdev jupyter notebook python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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/7f/e6/106e554ae143f399d2588e5d1718441a1d22c722aceffcb6e6f70310b7eb/toolslm-0.0.3.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.3",
    "project_urls": {
        "Homepage": "https://github.com/AnswerDotAI/toolslm"
    },
    "split_keywords": [
        "nbdev",
        "jupyter",
        "notebook",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9321b7106fb5ea685b978b57ead2d96c01c8f2b41b67e017d1dcfd66654e19aa",
                "md5": "7c7ef232a535da544d0e3065b5a83261",
                "sha256": "912760afeedaa7ad32499f3187387c9f024734efa519be7ddf8c308924886796"
            },
            "downloads": -1,
            "filename": "toolslm-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7c7ef232a535da544d0e3065b5a83261",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 12410,
            "upload_time": "2024-05-05T23:30:45",
            "upload_time_iso_8601": "2024-05-05T23:30:45.655843Z",
            "url": "https://files.pythonhosted.org/packages/93/21/b7106fb5ea685b978b57ead2d96c01c8f2b41b67e017d1dcfd66654e19aa/toolslm-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7fe6106e554ae143f399d2588e5d1718441a1d22c722aceffcb6e6f70310b7eb",
                "md5": "b7223941c872f8b56554af0a088a4eea",
                "sha256": "b47ce1fb18a7dca628da4e412d72d9dcf728e6b95a5b41591f399f2613df6024"
            },
            "downloads": -1,
            "filename": "toolslm-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "b7223941c872f8b56554af0a088a4eea",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 13744,
            "upload_time": "2024-05-05T23:30:47",
            "upload_time_iso_8601": "2024-05-05T23:30:47.368507Z",
            "url": "https://files.pythonhosted.org/packages/7f/e6/106e554ae143f399d2588e5d1718441a1d22c722aceffcb6e6f70310b7eb/toolslm-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-05 23:30:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AnswerDotAI",
    "github_project": "toolslm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "toolslm"
}
        
Elapsed time: 0.25765s