refactor: change from standar backend api to python library

This commit is contained in:
AlanSilvaaa
2026-05-28 15:02:42 -04:00
parent 8d3a18ec39
commit da59c4e64d
23 changed files with 331 additions and 833 deletions

View File

@@ -1,6 +1,6 @@
# math-problems-structure
This repository provides functions for generating all types of math problems, ranging from graphical exercises to text-based ones.
This repository provides a Python library for generating structured math problems, ranging from graphical exercises to text-based ones.
## Installation
@@ -12,45 +12,28 @@ uv sync
## Usage
Run the backend server using the following command:
Import and call the problem generator functions directly:
```bash
uv run uvicorn main:app --reload
```python
from math_problems_structure.grade_1 import join_pictures_with_quantity
problem = join_pictures_with_quantity(
available_pictures=[
{"id": f"picture-{index}", "name": f"Picture {index}", "image_path": f"/images/{index}.png"}
for index in range(10)
],
seed=1,
)
```
This will start the server, and you can access the API documentation at `http://localhost:8000/docs` to explore the available endpoints for generating math problems.
You can also run the included example script:
```bash
uv run python test.py
```
Each grade has its `images_for_reference` folder, which contains the images that were used to create the structure of the problems.
### API Endpoints
The API is organized by grade level and problem type. For example, to generate a grade 1 problem that involves joining pictures with quantities, you can send a POST request to the following endpoint:
```bash
curl -X POST "http://127.0.0.1:8000/math/grade_1/join_pictures_with_quantity" \
-H "Content-Type: application/json" \
-d '{
"available_pictures": [
{"id": "picture-1", "name": "Apple", "image_path": "/images/apple.png"},
{"id": "picture-2", "name": "Banana", "image_path": "/images/banana.png"},
{"id": "picture-3", "name": "Car", "image_path": "/images/car.png"},
{"id": "picture-4", "name": "Dog", "image_path": "/images/dog.png"},
{"id": "picture-5", "name": "Elephant", "image_path": "/images/elephant.png"},
{"id": "picture-6", "name": "Fish", "image_path": "/images/fish.png"},
{"id": "picture-7", "name": "Grape", "image_path": "/images/grape.png"},
{"id": "picture-8", "name": "Hat", "image_path": "/images/hat.png"},
{"id": "picture-9", "name": "Ice Cream", "image_path": "/images/ice-cream.png"},
{"id": "picture-10", "name": "Juice", "image_path": "/images/juice.png"}
],
"container_count_per_side": 5,
"min_quantity": 1,
"max_quantity": 10,
"seed": 1
}'
```
To see more examples, look at [this](./ENDPOINTS-EXAMPLE.md) file.
## Test
To run the tests, use the following command: