feat(model): add generic OpenAI-compatible LLM backend#115
Open
nankingjing wants to merge 5 commits into
Open
Conversation
Contributor
|
@nankingjing please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.