Spaces:
Runtime error
pydantic models for the PRC API schema
You can use these models in your Python code, both to generate valid data, and to parse incoming data.
Using the models ensures that your data has been at least somewhat validated. If the schema changes and your code needs an update, you're more likely to be able to tell right away.
Parsing a request
With FastAPI
If you're using fastapi, you can use the models right in your server:
from models.request import RankingRequest
from models.response import RankingResponse
@app.post("/rank")
def rank(ranking_request: RankingRequest) -> RankingResponse:
...
# You can return a RankingResponse here, or a dict with the correct keys and
# pydantic will figure it out.
If you specify RankingResponse
as your reeturn type, you will get validation of your response for free.
For a complete example, check out ../fastapi_nltk/
Otherwise
If you'd like to parse a request directly, here is how:
from models.request import RankingRequest
loaded_request = RankingRequest.model_validate_json(json_data)
Generating fake data
There is a fake data generator in fake.py
. If you run it directly it'll print some. You can also import it and run fake_request()
or fake_response()
. Take a look at the test for a usage example.