ofa_client¶
ofa Python client — call ofa –serve from user code.
Zero external dependencies. Pure Python stdlib. Copy this file into any
Python environment on Kestrel (or symlink from $OFA_ROOT/src/ofa_client.py)
and use:
from ofa_client import ask, Session
# One-shot, stateless
text = ask("summarise this plot", image="output/step_0100.png")
# Multi-turn, client-side history
sess = Session(model="ofa-code")
sess.ask("what turbulence model for cavity flow at Re=1e4?")
sess.ask("show me a controlDict for that") # sees the previous turn
Auto-detects the running ofa –serve via, in order:
Explicit
url=/token=kwargs.
$OFA_BYOK_URL/$OFA_BYOK_TOKENenvironment variables.
$OFA_SCRATCH/.ofa_serve_portand$OFA_SCRATCH/.ofa_api_key.
/scratch/$USER/.ofa_serve_portand/scratch/$USER/.ofa_api_key.
Raises RuntimeError with a clear message if no server can be located. Import works in any Python 3.8+ interpreter regardless of what other packages are installed — the client’s only imports are stdlib.
Functions
|
Send a one-shot prompt (with optional images and file/text context) to |
Classes
|
Multi-turn chat session with client-side history. |
- ofa_client.ask(prompt, *, image=None, images=None, context=None, file=None, files=None, model='ofa-code', url=None, token=None, timeout=120.0, full_file=False)[source]¶
Send a one-shot prompt (with optional images and file/text context) to
ofa --serveand return the reply text. Stateless — each call is a fresh session.- Parameters:
prompt (str) – The main question (required).
images (list | None) – Path (or list of paths) to local image files to attach.
context (str | None) – Inline text context to include verbatim in the user message.
files (list | None) – Path (or list of paths) to local text files whose contents get inlined (fenced with the filename). Only the last 32 KB of each file is included by default; pass
full_file=Trueto override.model (str) – One of
MODEL_IDS. Default"ofa-code".timeout (float) – Overrides for auto-detection (see module docstring).
full_file (bool) – If True, read entire
file=/files=contents instead of only the last 32 KB.images
files
url (str | None)
token (str | None)
timeout
- Return type:
- class ofa_client.Session(*, model='ofa-code', url=None, token=None, timeout=120.0, full_file=False)[source]¶
Bases:
objectMulti-turn chat session with client-side history.
Each
.ask()call appends to the internalmessageslist and sends the whole thing on the next request, so the model sees prior context:sess = Session(model="ofa-code") sess.ask("what turbulence model for cavity flow?") sess.ask("show me a controlDict for that") # sees turn 1
Server-side state is deliberately NOT used: keeping the history client-side means it survives
ofa --serverestarts, has no server memory footprint, and matches the OpenAI protocol shape.