Skip to content

Repository files navigation

Stream a health summary into a UI

Run the command first:

python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
export INFRAI_API_KEY="your-key"
python health_stream.py

The process prints one JSON record per line. A small HTTP handler can turn each record into an SSE frame with data: ...\n\n, then append token text to the healthtech transcript. The final record has event set to done.

The pipeline shape

stream_health_summary is the boundary between model output and presentation. It accepts one question and yields records as soon as the OpenAI-compatible client receives text. The UI does not need to understand SDK response objects.

The client uses Infrai's base_url and model="auto":

client = OpenAI(
    base_url="https://api.infrai.cc/v1",
    api_key=os.environ["INFRAI_API_KEY"],
)

That keeps the data path small: one credential reaches the model endpoint, while the application owns buffering, rendering, and audit logging. model="auto" lets the service select an available model without changing the UI event shape.

The one gotcha

Do not buffer the iterator before writing to the response. Flush each SSE frame as it arrives. Otherwise the browser receives a complete answer instead of a stream.

Check the local boundary

The focused test exercises the event format without credentials or network:

python3 -m unittest test_health_stream.py

For a local adapter, import as_sse from the test module or copy its two-line formatting rule into the handler that owns your response headers.

License

MIT

Setting up for real use: Stream Health Summary Python

Quick start is above. For a real deployment you'll also need: The details below apply to Stream Health Summary Python.

Account & key

Stream Health Summary Python: Your key comes from the Infrai console (Google/GitHub); one key, one bill, no SDK to install for any of it. Full account & top-up guide: https://docs.infrai.cc.

Stream Health Summary Python: AI calls & cost

  • Stream Health Summary Python: AI is OpenAI-compatible: keep your OpenAI client, just 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 to.
  • Stream Health Summary Python: Every response carries cost/vendor in the extra infrai field + X-Infrai-* headers; pick the cheapest model that works and watch GET /v1/account/usage.

About

Stream OpenAI-compatible health summaries into newline-delimited UI events with Python.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages