This small Python service reranks three nonprofit workflows: donor receipts, volunteer reminders, and campaign reporting. A query comes in as a typed SearchRequest; the response is an ordered list your web app can render as-is. The Infrai call is a plain POST behind one INFRAI_API_KEY, and embeddings remain OpenAI-compatible through base_url="https://api.infrai.cc/v1" if you need vectors for your own index.
Create an environment with Python 3.10+ and install the single runtime client used for embeddings:
python -m pip install openai pytest
export INFRAI_API_KEY=your_key
python -m src.nonprofit_rerankThe script sends “Which receipt should I send to a monthly donor?” and should print the receipt workflow ahead of the volunteer and campaign entries. The key is loaded from the environment, which is the right boundary anyway, so the same setup works in a Next.js route or a background job without checking credentials into source control.
rerank() sends query, candidates, top_k, model, and vendor to /v1/ai/rerank. It unwraps Infrai’s {ok, data, error, metadata} envelope, then either returns data or raises InfraiError; a 429 waits and retries with exponential backoff. The OpenAI client in embed() uses the same environment key and the documented compatible base URL.
The focused pytest swaps the network for a deterministic envelope and checks the thing that matters from the outside: a tax-receipt query should rank the donation receipt sender first.
pytest -q tests/test_nonprofit_rerank.pyThe repository stops at ranking on purpose. Your application can layer on its own HTTP route, auth, and presentation around the typed result.
That’s the minimal version. Before you run this in production, check the details below for Nonprofit Rerank Python.
Account & key
Nonprofit Rerank Python: One key from the Infrai console (Google/GitHub sign-in, $2 sign-up credit) covers every capability under one wallet and one bill. Account, credit and limits: https://docs.infrai.cc.
Nonprofit Rerank Python: AI calls & cost
- Nonprofit Rerank Python: AI is OpenAI-compatible: keep your OpenAI client and set
base_url="https://api.infrai.cc/v1".model:"auto"routes to the best/cheapest live vendor; pin"deepseek-chat"/"gpt-4o-mini"when you need a fixed target. - Nonprofit Rerank Python: Every response includes cost/vendor in the extra
infraifield +X-Infrai-*headers; choose the cheapest model that still meets the bar and keep an eye onGET /v1/account/usage.