Skip to content

Commit da94cd0

Browse files
authored
Initial implementation of PydanticPrompt library
This PR establishes the foundation for the PydanticPrompt library, providing a clean, simple way to document Pydantic models for LLM interactions using standard Python docstrings. Key accomplishments: - Implemented the `@prompt_schema` decorator for Pydantic models - Created docstring extraction system using Python's introspection capabilities - Added type annotation handling with support for nested and complex types - Implemented validation rule documentation via Pydantic's JSON schema - Added warnings for undocumented fields - Set up comprehensive tests with 100% functionality coverage - Established CI workflow using GitHub Actions - Added linting and type checking with Ruff and mypy - Created detailed documentation with examples The library requires Python 3.11+ and Pydantic 2.0+, focusing on modern Python practices and type safety. This implementation allows users to document their Pydantic models once and seamlessly include that documentation in LLM prompts, improving consistency between code and AI interactions.
2 parents 7b41d85 + 396b87f commit da94cd0

File tree

10 files changed

+1313
-1
lines changed

10 files changed

+1313
-1
lines changed

.github/workflows/ci.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.11", "3.12"]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -e ".[dev]"
29+
pip install pytest-cov
30+
31+
- name: Run linting and type checking
32+
run: |
33+
chmod +x ./lint.sh
34+
./lint.sh
35+
36+
- name: Test with pytest
37+
run: |
38+
pytest --cov=pydantic_prompt --cov-report=xml
39+
40+
- name: Upload coverage to Codecov
41+
uses: codecov/codecov-action@v3
42+
with:
43+
file: ./coverage.xml
44+
fail_ci_if_error: false
45+
46+
publish:
47+
needs: test
48+
if: startsWith(github.ref, 'refs/tags/')
49+
runs-on: ubuntu-latest
50+
51+
steps:
52+
- uses: actions/checkout@v4
53+
54+
- name: Set up Python
55+
uses: actions/setup-python@v5
56+
with:
57+
python-version: "3.10"
58+
59+
- name: Install build dependencies
60+
run: |
61+
python -m pip install --upgrade pip
62+
pip install build twine
63+
64+
- name: Build and check package
65+
run: |
66+
python -m build
67+
twine check dist/*
68+
69+
- name: Publish to PyPI
70+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
71+
uses: pypa/gh-action-pypi-publish@release/v1
72+
with:
73+
password: ${{ secrets.PYPI_API_TOKEN }}

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 MLDSAI Inc., Richard Abrich, and contributors.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)