oc_chat
Loading...
Searching...
No Matches
__init__.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
# providers/openai_compat/__init__.py
4
5
"""
6
Generic OpenAI-compatible provider bundle — many lanes, one implementation.
7
8
Purpose
9
-------
10
Importing this package validates the lane catalogue and registers ONE
11
provider instance per catalogue row into
12
``option_c_agent_contracts.registry``. After ``import
13
providers.openai_compat`` the registry holds the seven lane names
14
(``groq``, ``cerebras``, ``nvidia_nim``, ``openrouter``, ``bitdeer``,
15
``vercel``, ``cheaperinference``) alongside whatever else is registered,
16
and any of them can be selected with ``OC_CHAT_PROVIDER=<lane>``.
17
18
The lanes are the OpenAI-dialect subset of the set the OCON benchmark
19
harness proved end to end. DeepSeek keeps its own richer bundle; the
20
Anthropic and Gemini dialects are out of scope for this bundle.
21
22
Responsibilities
23
----------------
24
- Validate and self-register every catalogue row on import.
25
- Re-export the bundle's public surface.
26
27
Diagnostics
28
-----------
29
Domain: OC_CHAT.CLIENT
30
Levels:
31
L2 — lifecycle events
32
L3 — semantic details
33
L4 — deep tracing
34
35
Contracts
36
---------
37
- Side effect on import: :func:`register_all` runs once. Repeated
38
imports are idempotent (Python caches the module; the registry also
39
treats a same-class same-name re-registration as a no-op).
40
- A catalogue row that fails validation raises :exc:`CatalogueError` HERE,
41
at import, naming the row — the bundle never registers a partial set of
42
lanes and never silently drops one (plan 215 P5).
43
- The bundle reads no API key and holds no credential; the catalogue
44
carries env-var NAMES only (plan 215 P6).
45
46
Dependencies
47
------------
48
- oc_diagnostics (structured debug logging via _dbg)
49
- providers.openai_compat.catalogue (lane catalogue types, LANES and validation, re-exported)
50
- providers.openai_compat.client (OpenAICompatClient, re-exported)
51
- providers.openai_compat.provider (register_all run on import, and the re-exported provider surface)
52
- providers.openai_compat.usage (normalise_usage, re-exported)
53
"""
54
from
oc_diagnostics
import
_dbg
55
56
from
.catalogue
import
LANES, CatalogueError, Lane, LaneModel, lane_by_name, validate_catalogue
57
from
.client
import
OpenAICompatClient
58
from
.provider
import
OpenAICompatProvider, register_all, registered_lanes
59
from
.usage
import
normalise_usage
60
61
# Self-register every lane on import (the Phase C.1c bundle contract).
62
register_all()
63
64
_dbg(
"OC_CHAT.CLIENT"
,
"module"
,
"loaded"
, 4)
65
66
__all__ = [
67
"CatalogueError"
,
68
"LANES"
,
69
"Lane"
,
70
"LaneModel"
,
71
"OpenAICompatClient"
,
72
"OpenAICompatProvider"
,
73
"lane_by_name"
,
74
"normalise_usage"
,
75
"register_all"
,
76
"registered_lanes"
,
77
"validate_catalogue"
,
78
]
providers
openai_compat
__init__.py
Generated by
1.15.0