# llmtk (LLM Toolkit)
> Stop writing JSON schemas for your AI functions. Let Python types do it for you. ⚡️
[](https://opensource.org/licenses/MIT)
[](https://www.python.org/downloads/)
## Features
- 🎯 **Zero Schema Maintenance**: Your Python types become your OpenAI schemas
- ✨ **Type Safety**: Catch invalid AI responses before they break your code
- 📝 **Rich Types**: Support for Pydantic models, lists, and custom types
- 🚀 **Quick Setup**: One decorator is all you need
## Without llmtk, you write this:
```python
# Define your function
def get_weather(city: str) -> str:
return f"Weather in {city}: Sunny"
# Manually maintain OpenAI function schema
weather_schema = {
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather information for a city",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "Name of the city"
}
},
"required": ["city"]
}
}
}
# Hope the schema stays in sync with your function
tools = [weather_schema]
```
## With llmtk, just write this:
```python
from llmtk import register_function, get_openai_tools
@register_function
def get_weather(city: str) -> str:
"""Get weather information for a city"""
return f"Weather in {city}: Sunny"
# Schema automatically generated from your Python types
tools = get_openai_tools()
```
## Quick Start
```bash
pip install llmtk
```
```python
from llmtk import register_function, call_function, get_openai_tools
@register_function
def calculate_price(quantity: int, unit_price: float) -> float:
"""Calculate total price for items"""
return quantity * unit_price
# Get schema for OpenAI
tools = get_openai_tools()
# Use with OpenAI
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Calculate price for 5 items at $10 each"}],
tools=tools,
tool_choice="auto"
)
# Safe function execution with validation
result = call_function(
response.choices[0].message.tool_calls[0].function.name,
response.choices[0].message.tool_calls[0].function.arguments
)
if isinstance(result, tuple):
print(f"Validation error: {result[0]}")
else:
print(f"Total: ${result:.2f}") # Total: $50.00
```
## License
MIT License - feel free to use in your projects!
Raw data
{
"_id": null,
"home_page": "https://github.com/arcifylabs/llmtk",
"name": "llmtk",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "llm, openai, function-calling, type-safety, validation, pydantic",
"author": "Ritik Sahni",
"author_email": "ritik@arcifylabs.com",
"download_url": "https://files.pythonhosted.org/packages/6f/34/d93d5a08f287dc85f346b453849ac7b22fce415554e81c0be101497dbdc8/llmtk-0.1.0.tar.gz",
"platform": null,
"description": "# llmtk (LLM Toolkit)\n\n> Stop writing JSON schemas for your AI functions. Let Python types do it for you. \u26a1\ufe0f\n\n[](https://opensource.org/licenses/MIT)\n[](https://www.python.org/downloads/)\n\n## Features\n\n- \ud83c\udfaf **Zero Schema Maintenance**: Your Python types become your OpenAI schemas\n- \u2728 **Type Safety**: Catch invalid AI responses before they break your code\n- \ud83d\udcdd **Rich Types**: Support for Pydantic models, lists, and custom types\n- \ud83d\ude80 **Quick Setup**: One decorator is all you need\n\n## Without llmtk, you write this:\n\n\n```python\n# Define your function\ndef get_weather(city: str) -> str:\n return f\"Weather in {city}: Sunny\"\n\n# Manually maintain OpenAI function schema\nweather_schema = {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"get_weather\",\n \"description\": \"Get weather information for a city\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"city\": {\n \"type\": \"string\",\n \"description\": \"Name of the city\"\n }\n },\n \"required\": [\"city\"]\n }\n }\n}\n\n# Hope the schema stays in sync with your function\ntools = [weather_schema]\n```\n\n## With llmtk, just write this:\n\n```python\nfrom llmtk import register_function, get_openai_tools\n\n@register_function\ndef get_weather(city: str) -> str:\n \"\"\"Get weather information for a city\"\"\"\n return f\"Weather in {city}: Sunny\"\n\n# Schema automatically generated from your Python types\ntools = get_openai_tools()\n```\n\n## Quick Start\n\n```bash\npip install llmtk\n```\n\n```python\nfrom llmtk import register_function, call_function, get_openai_tools\n\n@register_function\ndef calculate_price(quantity: int, unit_price: float) -> float:\n \"\"\"Calculate total price for items\"\"\"\n return quantity * unit_price\n\n# Get schema for OpenAI\ntools = get_openai_tools()\n\n# Use with OpenAI\nresponse = client.chat.completions.create(\n model=\"gpt-4\",\n messages=[{\"role\": \"user\", \"content\": \"Calculate price for 5 items at $10 each\"}],\n tools=tools,\n tool_choice=\"auto\"\n)\n\n# Safe function execution with validation\nresult = call_function(\n response.choices[0].message.tool_calls[0].function.name,\n response.choices[0].message.tool_calls[0].function.arguments\n)\n\nif isinstance(result, tuple):\n print(f\"Validation error: {result[0]}\")\nelse:\n print(f\"Total: ${result:.2f}\") # Total: $50.00\n```\n## License\n\nMIT License - feel free to use in your projects!\n",
"bugtrack_url": null,
"license": null,
"summary": "Type-safe function registration and validation for LLM function calls",
"version": "0.1.0",
"project_urls": {
"Bug Tracker": "https://github.com/arcifylabs/llmtk/issues",
"Documentation": "https://github.com/arcifylabs/llmtk#readme",
"Homepage": "https://github.com/arcifylabs/llmtk",
"Source Code": "https://github.com/arcifylabs/llmtk"
},
"split_keywords": [
"llm",
" openai",
" function-calling",
" type-safety",
" validation",
" pydantic"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "1f08e7213a179989f79f6385a2c9a9c7f1a07bcb17b9f9d25a96b634da225e4d",
"md5": "26281540a64ab8195e37cf292106f7b2",
"sha256": "6e6409984f0d22b0e3c22a02159853ebdc04c8b387626c658dbcc07466fca36a"
},
"downloads": -1,
"filename": "llmtk-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "26281540a64ab8195e37cf292106f7b2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 5804,
"upload_time": "2025-02-11T13:49:23",
"upload_time_iso_8601": "2025-02-11T13:49:23.478898Z",
"url": "https://files.pythonhosted.org/packages/1f/08/e7213a179989f79f6385a2c9a9c7f1a07bcb17b9f9d25a96b634da225e4d/llmtk-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "6f34d93d5a08f287dc85f346b453849ac7b22fce415554e81c0be101497dbdc8",
"md5": "8cd08f70a93eb2dbf2225060e9aa8917",
"sha256": "9bd0d476a9c8bc77a793afb59f61a7d4d424350277abe17d7e31f0e8cefa5a0e"
},
"downloads": -1,
"filename": "llmtk-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "8cd08f70a93eb2dbf2225060e9aa8917",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 6625,
"upload_time": "2025-02-11T13:49:25",
"upload_time_iso_8601": "2025-02-11T13:49:25.534000Z",
"url": "https://files.pythonhosted.org/packages/6f/34/d93d5a08f287dc85f346b453849ac7b22fce415554e81c0be101497dbdc8/llmtk-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-11 13:49:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "arcifylabs",
"github_project": "llmtk",
"github_not_found": true,
"lcname": "llmtk"
}