mirror of https://github.com/microsoft/autogen.git
Filter invalid parameters in Ollama client requests (#5983)
Remove unrecognized parameters in Ollama API calls. --------- Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
This commit is contained in:
parent
c4e07e86d8
commit
09d8d344a2
|
@ -82,14 +82,22 @@ ollama_chat_request_fields: dict[str, Any] = [m for m in inspect.getmembers(Chat
|
||||||
1
|
1
|
||||||
]
|
]
|
||||||
OLLAMA_VALID_CREATE_KWARGS_KEYS = set(ollama_chat_request_fields.keys()) | set(
|
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]:
|
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}
|
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]
|
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
|
return create_args
|
||||||
# create_args = {k: v for k, v in config.items() if k in create_kwargs}
|
# 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_args
|
# Copy the create args and overwrite anything in extra_create_args
|
||||||
create_args = self._create_args.copy()
|
create_args = self._create_args.copy()
|
||||||
create_args.update(extra_create_args)
|
create_args.update(extra_create_args)
|
||||||
|
create_args = _create_args_from_config(create_args)
|
||||||
|
|
||||||
response_format_value: JsonSchemaValue | Literal["json"] | None = None
|
response_format_value: JsonSchemaValue | Literal["json"] | None = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue