Python: feat: Add ModelsLab chat completion connector#13559
Open
adhikjoshi wants to merge 1 commit intomicrosoft:mainfrom
Open
Python: feat: Add ModelsLab chat completion connector#13559adhikjoshi wants to merge 1 commit intomicrosoft:mainfrom
adhikjoshi wants to merge 1 commit intomicrosoft:mainfrom
Conversation
|
@adhikjoshi 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”),
|
Author
|
I agree to the CLA. @microsoft-github-policy-service agree |
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.
feat: Add ModelsLab chat completion connector
Summary
Adds
ModelsLabChatCompletion— a new connector insemantic_kernel/connectors/ai/modelslab/that makesModelsLab's uncensored Llama models available to
any Semantic Kernel kernel.
Zero new dependencies. ModelsLab exposes an OpenAI-compatible chat
endpoint, so
ModelsLabChatCompletionsimply subclasses the existingOpenAIChatCompletionservice and wires a pre-configuredAsyncOpenAIclient to the ModelsLab base URL — exactly the same pattern used internally
for other OpenAI-compatible providers.
What this PR adds
semantic_kernel/connectors/ai/modelslab/__init__.pysemantic_kernel/connectors/ai/modelslab/modelslab_chat_completion.pyModelsLabChatCompletionservice (main implementation)semantic_kernel/connectors/ai/modelslab/modelslab_settings.pytests/unit/connectors/ai/modelslab/test_modelslab_chat_completion.pyUsage
Streaming, function calling, prompt templates, planners, and multi-service
kernels all work without any changes —
ModelsLabChatCompletioninheritsthem from
OpenAIChatCompletion.Design rationale
Why subclass
OpenAIChatCompletion?ModelsLab's
/uncensored-chat/v1/chat/completionsendpoint is 100%OpenAI Chat Completions compatible. Subclassing lets us:
retry handling — nothing duplicated.
OpenAIChatCompletionautomatically.This is consistent with how other providers expose OpenAI-compatible
endpoints in the SK ecosystem.
Supported models
llama-3.1-8b-uncensored(default)llama-3.1-70b-uncensoredConfiguration
api_keyMODELSLAB_API_KEYai_model_idMODELSLAB_CHAT_MODEL_IDllama-3.1-8b-uncensoredbase_urlMODELSLAB_CHAT_BASE_URLhttps://modelslab.com/api/uncensored-chat/v1Get an API key at modelslab.com/api-keys.
Testing
pip install pytest pytest-asyncio pytest-mock pytest tests/unit/connectors/ai/modelslab/ -v # 17 tests — all passChecklist
from_dictfactory implemented (required by SK serialization)from_dict, client wiring, and constants__all__defined in__init__.pyAbout ModelsLab
ModelsLab is an AI API platform providing access to
Llama, Flux, SDXL, video generation, voice synthesis, and many other models.
Documentation: docs.modelslab.com