tdfs4ds.utils.llm_provider¶
tdfs4ds.utils.llm_provider
¶
Which way does an LLM call travel, and does it need an API key?
One module answers those two questions so that no call site re-derives them.
Before it existed the answer lived in ~100 scattered provider == 'bedrock'
comparisons and three inline not INSTRUCT_MODEL_API_KEY gates, which is why
a role-based AWS setup (no key, by design) could not be expressed.
Routes. llm_route(provider, url) returns the provider unchanged for
everything that existed before, except Bedrock, which has two doors:
'bedrock-converse'--ChatBedrockConverse(the Converse API, boto3 credential chain). This is whatbedrockhas always meant. The URL, if any, is ignored, exactly as before.'bedrock-openai'-- Bedrock's OpenAI-compatible endpoint,https://bedrock-runtime.<region>.amazonaws.com/openai/v1, spoken to with the OpenAI wire protocol. Chosen only when the URL ends in/openai/v1, so a configuration without such a URL is untouched.
aws is accepted as a spelling of bedrock.
Auth on the OpenAI door. A key is sent as the bearer token (the Bedrock API
key). With *_CLIENT_MODE=ambient, or with no key at all, every request is
SigV4-signed with the ambient AWS credential chain (instance/task role, SSO,
environment, profile) -- no secret is held by tdfs4ds.
Nothing here runs at import time and nothing needs boto3/httpx until a
signed client is actually built.
_BEDROCK_HOST
module-attribute
¶
canonical_provider
¶
Lower-case provider with its aliases resolved (aws -> bedrock).
bedrock_openai_url
¶
True when url is Bedrock's OpenAI-compatible endpoint (.../openai/v1).
effective_provider
¶
Provider name as the OpenAI-family code paths understand it.
The Bedrock OpenAI door is an OpenAI-compatible server, so every
OpenAI-family decision (structured-output mechanism, probes) treats it as
openai-compatible. Any other input is returned canonicalised only.
key_required
¶
Is an API key mandatory for this provider/route?
False where the credential comes from the environment: Bedrock (both
doors -- a key or an ambient role) and Vertex. True for every provider
that existed before and was never keyless.
client_mode
¶
'ambient' or None. An unknown value is reported and ignored.
region_for
¶
AWS region: from a bedrock-runtime.<region>.amazonaws.com host, else
the explicit setting, else the standard environment variables.
sigv4_auth
¶
An httpx.Auth that SigV4-signs requests for url's region.
bedrock_openai_credentials
¶
(api_key, httpx_auth_or_None) for the Bedrock OpenAI door.
A key without ambient mode is the bearer token and nothing is signed.
Otherwise the SDK gets the placeholder key and the signer does the work.
describe_auth
¶
How this configuration authenticates -- words only, never a value.
build_bedrock_openai_chat
¶
build_bedrock_openai_chat(*, model, url, temperature=0.0, timeout=60, max_retries=3, max_tokens=None, callbacks=None)
ChatOpenAI aimed at Bedrock's OpenAI-compatible endpoint.
Goes through embedding._build_http_client like every OpenAI-family
client, so the proxy and TLS settings compose with the signer. No seed:
it is an OpenAI-only parameter that other OpenAI-compatible servers reject.
list_bedrock_openai_models
¶
Model ids from <url>/models on the Bedrock OpenAI door.
Raises on any failure; the caller decides the fallback (boto3 listing, then typing the name).