You can deploy an API by providing a project directory. Cortex will save the project directory and make it available during API initialization.
project/├── model.py├── util.py├── predictor.py├── requirements.txt└── ...
You can define your Predictor class in a separate python file and import code from your project.
# predictor.pyfrom model import MyModelclass PythonPredictor:def __init__(self, config):model = MyModel()def predict(payload):return model(payload)
import cortexapi_spec = {"name": "text-generator","kind": "RealtimeAPI","predictor": {"type": "python","path": "predictor.py"}}cx = cortex.client("aws")cx.create_api(api_spec, project_dir=".")
# api.yaml- name: text-generatorkind: RealtimeAPIpredictor:type: pythonpath: predictor.py
$ cortex deploy api.yaml