Fix OllamaChatCompletionClient load_component() error by adding to WELL_KNOWN_PROVIDERS #7030
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.
The
ChatCompletionClient.load_component()method was failing withValueError("Invalid")when trying to loadOllamaChatCompletionClientusing provider configuration. This prevented users from using the same configuration-based loading approach available for other chat completion clients.Problem
The following code would fail with a
ValueError: Invaliderror:While the direct instantiation approach worked fine:
Root Cause
The issue occurred because
OllamaChatCompletionClientwas missing from theWELL_KNOWN_PROVIDERSdictionary in_component_config.py. Whenload_component()couldn't find the provider in the known providers list, it attempted to use "OllamaChatCompletionClient" directly as a module path. Since this string contains no dots, the parsing logicprovider.rsplit(".", maxsplit=1)would return a single-element list, causing the validationlen(output) != 2to fail and raiseValueError("Invalid").Solution
Added the missing entry to
WELL_KNOWN_PROVIDERS:Changes
OllamaChatCompletionClientmapping toWELL_KNOWN_PROVIDERSin_component_config.pytest_ollama_in_well_known_providers()to validate the provider mappingtest_ollama_load_component()andtest_ollama_load_component_via_class()to test the load_component functionalityImpact
OllamaChatCompletionClientcan be loaded using the same configuration approach as other clientsFixes #6994.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.