feat(model): add generic OpenAI-compatible LLM backend#115
Conversation
|
@microsoft-github-policy-service agree |
|
Thanks — a generic OpenAI-compatible backend is a meaningful usability improvement, and we would like to land it through this original PR so the contribution remains attributed to you. The PR now conflicts with newer backend registry/configuration changes. Could you please rebase onto the latest Acceptance points:
We tested a local union resolution with 47 model-focused tests plus the full suite passing. Please add or retain focused routing/config/token tests when rebasing, then ping us for a prompt re-review. We prefer merging this PR rather than replacing it, to preserve your authorship and PR history. |
Co-Authored-By: Claude <noreply@anthropic.com>
7012ab7 to
45ff88a
Compare
|
Rebased onto the latest Changes made:
Validation:
Let me know if you’d like any adjustments before re-review. |
|
The branch is already rebased on the latest Union resolution — All existing paths preserved:
Test results:
Ready for re-review. |
Summary
Adds a generic
openai_compatiblemodel backend(
skillopt/model/openai_compatible_backend.py) so SkillOpt can talk to anyservice that exposes an OpenAI-compatible
/chat/completionsendpoint usingnothing more than a
base_urland anapi_key.A single backend therefore unlocks a large family of providers, including:
https://api.deepseek.com/v1)https://api.groq.com/openai/v1)https://api.together.xyz/v1)http://localhost:11434/v1)http://localhost:4000)What's included
openaiSDK, mirroring thecallable surface of the existing chat backends (
qwen_backend,minimax_backend):chat_optimizer,chat_target,chat_optimizer_messages,chat_target_messages, plus token tracking,configure_openai_compatible(...), and the standard setter functions.configure_openai_compatible(...)or environment variables (
OPENAI_COMPATIBLE_BASE_URL,OPENAI_COMPATIBLE_API_KEY,OPENAI_COMPATIBLE_MODEL, plus_TEMPERATURE/_MAX_TOKENS/_TIMEOUT_SECONDS, withOPTIMIZER_*/TARGET_*overrides). The API key is optional so keyless local servers (Ollama, vLLM)
work out of the box.
count_tokens()usingtiktokenwhen available, with a character-basedestimate as a fallback for non-OpenAI models.
*_messages(..., tools=...)entry points, returning the shared
CompatAssistantMessageobjects.TokenTracker.Registry / routing wiring
common.py— registeredopenai_compatiblein_BACKEND_DEFAULT_MODELSand_BACKEND_ALIASES(aliases:openai_compatible,openai_compatible_chat,openai-compatible,compat).backend_config.py— accepted as a valid optimizer/target chat backend.model/__init__.py— routed throughchat_optimizer/chat_targetand their_messagesvariants, added to token-summary aggregation and thereset/setter helpers, exposed
configure_openai_compatible, and wired intothe legacy
set_backend("openai_compatible")shorthand.Usage
or purely via env vars:
Docs
docs/guide/new-backend.mdnow opens with a section describing this built-inbackend so contributors reach for it before writing a bespoke one.
Testing
python -m py_compileon all touched modules.skillopt.modeland backend selection(
set_backend/get_backend_name/get_optimizer_backend).configured
model/max_tokensare sent,CompatAssistantMessagereturnvalues, token-summary aggregation, and
count_tokens()on both the tiktokenand character-fallback paths.