llmfuncs
llmfuncs is a Python package for documenting, managing, and validating Python functions based on their signature and docstrings. It automatically generates JSON Schema for functions, and provides a way to validate function arguments against the schema.
Features
- Automatic generation of JSON Schema from Python function signature and docstrings.
- Support for Python built-in types and many typing module types.
- Use and validate functions with JSON arguments against their schema.
- Management of multiple functions through a ToolCollection object.
- Bulk addition of functions from a module, a package, or a glob pattern.
- Simple and intuitive API.
Installation
Install llmfuncs using pip:
pip install llmfuncs
Usage
Tool
The Tool class encapsulates a function and its associated schema.
from llmfuncs.tool import Tool
def greet(name: str) -> str:
"""Greet someone.
Args:
name: Name of the person to greet.
Returns:
A greeting message.
"""
return f"Hello, {name}!"
tool = Tool(greet)
print(tool.name()) # "greet"
print(tool.schema())
ToolCollection
The ToolCollection class is a container for multiple Tool objects. It provides methods to add tools and use them.
from llmfuncs.tool import Tool, ToolCollection
tool_collection = ToolCollection()
tool_collection.add_tool(tool)
print(len(tool_collection)) # 1
You can also add tools in bulk from a module, a package, or a glob pattern.
tool_collection.add_tools_from_module('some_module')
tool_collection.add_tools_from_package('some_package')
tool_collection.add_tools_from_glob('*.py')
And here's how to use a tool:
json_args = '{"name": "World"}'
result = tool_collection.use_tool("greet", json_args)
print(result) # "Hello, World!"
For more detailed usage and examples, please check the API documentation and the example scripts in the examples folder.
Creating New Tools
If you have an existing module that you want to work with llmfuncs, you can try passing it through an LLM
to generate the type hints and docstrings for any functions missing them. For example:
Please update this module to add type hints to all function parameters and Google style docstrings to each function.
Contribute
We welcome contributions to llmfuncs!
License
This project is licensed under the terms of the MIT license. For more details, see the LICENSE file.
Metadata
Release files for llmfuncs 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| llmfuncs-0.2.3.tar.gz | 7.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llmfuncs-0.2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.2 kB
Release files / llmfuncs-0.2.3.tar.gz
| Download URL | llmfuncs-0.2.3.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9abcf56e526ef0c3cf42cd4e93b971c89436cc6d7ee29509bea34741a30c865a
|
|
BLAKE2b-256 checksum How to use checksums |
c767480e53299646f02379e49380df88b450964ebed266bb5fef8b69683ca4e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Release files / llmfuncs-0.2.3-py3-none-any.whl
| Download URL | llmfuncs-0.2.3-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9e869240cfd54d97fffa500d3b56f473f42dc7cee92be0cc3530119fa39ff7f0
|
|
BLAKE2b-256 checksum How to use checksums |
80d2a56d50af5bb71ec13f77f17d2c127e0aeacda8c31dbcb0775b057e5437a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Security for llmfuncs 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.