How arcifylabs/llmtk-py works
Project Overview
• llmtk is a Python library designed to eliminate the manual work of maintaining JSON schemas. It leverages Python’s type annotations to dynamically generate schemas used by AI systems such as OpenAI’s ChatGPT models.
• The toolkit’s main functionality is encapsulated in its function registration and schema generation processes, which allow users to decorate their Python functions so that the library can automatically create corresponding function schemas.
Key Components
a. Core Module (llmtk/core.py):
• This file is likely where the key logic resides, handling the registration of functions (via the decorator @register_function), the collection of metadata, and the schema generation based on Python types.
b. Initialization Module (llmtk/__init__.py):
• It exposes the public API that users interact with. Functions like register_function, get_openai_tools, and call_function are made available here.
c. Tests:
• The tests directory shows unit tests (e.g., tests/test_core.py) to verify core functionalities.
d. Setup and Packaging:
• setup.py indicates a standard Python package structure which could be integrated with continuous integration (as seen in the .github/workflows for publishing).
• User Code (Application Code):
• Represents sample usage where developers decorate their functions (e.g., get_weather, calculate_price).
• Function Registration Component:
• The area where @register_function is applied. This component collects function metadata including name, description, and type hints.
• Schema Generation Component:
• The part where get_openai_tools is used to convert registered functions into OpenAI-compatible schemas.
• Execution/Validation Component:
• This includes call_function which ensures that the arguments passed by OpenAI or other clients are validated prior to actual function execution.
• Testing Component:
• Indicates that tests/test_core.py is verifying the proper working of these components.
• Packaging & CI/CD:
• Annotations showing that the project is packaged with setup.py, along with automated workflows (e.g., publish.yml in the GitHub workflows) for continuous integration and deployment.
Architectural Patterns and Design Principles
• A separation of concerns: one part is dedicated to function registration and schema generation, and another part handles safe function execution.
• The use of decorators for minimal boilerplate and automatic type conversion is a central design principle.
• How the design leverages Python’s introspection capabilities to automatically extract type annotations, thus reducing manual schema maintenance.
Inclusion of Technologies and Frameworks
• Mention integration with Pydantic models and Python’s built-in types, which are extensively used to support “Rich Types.”
• That the library is designed for leveragability with external AI systems like OpenAI’s ChatGPT by showing an External Service component.