See Ash Code logo See Ash Code

My converter’s model name became configuration

Ashlynn Antrobus
• • 2 min read

My converter’s OCR request used to contain the model name directly in the Python call. On October 9, I moved the name into configuration. The request now uses a module-level MODEL value instead of the previous "gpt-4o-mini" string.

Then I gave the setting two different names: the sample environment file says MODEL_NAME, but the code reads OPENAI_MODEL. Copying the sample alone won’t supply the variable the code expects.

A dragon selects a card for a book-scanning machine from a drawer of differently shaped cards.

Where the value comes from

The OCR module loads dotenv configuration and then reads the environment:

load_dotenv()
api_key: str = os.environ["OPENAI_API_KEY"]
MODEL: str = os.environ["OPENAI_MODEL"]

The request uses:

model=MODEL

I can change the model without editing the call, provided the configured model supports the OCR request.

The environment is read when the module loads

This code assigns MODEL at module import. It doesn’t read the environment again for every conversion.

Changing the environment after the module has loaded won’t change the existing MODEL value.

The bracket access matters too. A missing OPENAI_MODEL raises KeyError at this point. The API key changed from os.getenv with an empty fallback to bracket access in the same commit. These settings are now required by the module’s initialization path.

The example file has to agree

The sample and the code need to agree on the setting name.

Using dummy values, the model setting required by this revision would look like:

OPENAI_MODEL=example-vision-model

That is an example name, not a recommendation or a claim that such a model is available. A working configuration also needs the API key already required by the OCR client.

Before trying another model, I need to fix the sample name. Otherwise, copying the sample alone leaves initialization without the required model setting.

AA

Written by Ashlynn Antrobus

Software developer, author, and builder. Sharing technical lessons learned from building tools like Ebook2Text, IndexedDict, and rag-mcp, and navigating life as a programmer with dyslexia.