A programming framework for agentic AI
Filter invalid parameters in Ollama client requests (#5983)
Federico Villa09d8d344a28d
diff --git a/python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py b/python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.pyindex 9e14f310e..5bf9a263c 100644--- a/python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py+++ b/python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py@@ -82,14 +82,22 @@ ollama_chat_request_fields: dict[str, Any] = [m for m in inspect.getmembers(Chat1]OLLAMA_VALID_CREATE_KWARGS_KEYS = set(ollama_chat_request_fields.keys()) | set(- ("model", "messages", "tools", "stream", "format", "options", "keep_alive")+ ("model", "messages", "tools", "stream", "format", "options", "keep_alive", "response_format"))+# NOTE: "response_format" is a special case that we handle for backwards compatibility.+# It is going to be deprecated in the future.def _create_args_from_config(config: Mapping[str, Any]) -> Dict[str, Any]:+ if "response_format" in config:+ warnings.warn(+ "Using response_format will be deprecated. Use json_output instead.",+ DeprecationWarning,+ stacklevel=2,+ )create_args = {k.lower(): v for k, v in config.items() if k.lower() in OLLAMA_VALID_CREATE_KWARGS_KEYS}dropped_keys = [k for k in config.keys() if k.lower() not in OLLAMA_VALID_CREATE_KWARGS_KEYS]- logger.info(f"Dropped the following unrecognized keys from create_args: {dropped_keys}")+ trace_logger.info(f"Dropped the following unrecognized keys from create_args: {dropped_keys}")return create_args# create_args = {k: v for k, v in config.items() if k in create_kwargs}@@ -411,6 +419,7 @@ class BaseOllamaChatCompletionClient(ChatCompletionClient):# Copy the create args and overwrite anything in extra_create_argscreate_args = self._create_args.copy()create_args.update(extra_create_args)+ create_args = _create_args_from_config(create_args)response_format_value: JsonSchemaValue | Literal["json"] | None = None