Skip to content

bug(backends): OpenAIBackend intrinsic path raises TypeError when user passes extra_body in model_options #1241

@planetf1

Description

@planetf1

Summary

OpenAIBackend._generate_from_intrinsic() raises TypeError: got multiple values for keyword argument 'extra_body' if a caller passes extra_body in model_options.

Root cause

The intrinsic call site passes extra_body as an explicit keyword argument alongside **api_params:

# openai.py ~line 712
chat_response = self._async_client.chat.completions.create(
    model=self._model_id,
    messages=messages_dicts,
    tools=formatted_tools if use_tools else None,
    extra_body=extra_body,   # explicit kwarg
    **api_params,            # may also contain extra_body if user passed it
)

_make_backend_specific_and_remove() treats extra_body as a valid Completions.create parameter and passes it through into api_params. When both the explicit kwarg and **api_params contain extra_body, Python raises TypeError at call time.

Standard path fix (reference)

PR #1204 fixed the identical bug in _generate_from_chat_context_standard() by popping extra_body out of backend_specific before spreading, then deep-merging it into extra_params["extra_body"] (preserving chat_template_kwargs separately). The intrinsic path needs the same treatment.

Reproduction

from mellea.backends.openai import OpenAIBackend
from mellea.stdlib.components import Intrinsic

await mfuncs.aact(
    Intrinsic("answerability"),
    ctx,
    backend,
    model_options={"extra_body": {"guided_json": {"type": "string"}}},
)
# → TypeError: got multiple values for keyword argument 'extra_body'

Fix shape

Mirror the standard-path fix from PR #1204: pop extra_body from the result of _make_backend_specific_and_remove() before api_params.update(...), then merge it into the existing extra_body dict (deep-merging chat_template_kwargs as the only nested key either side writes).

Flagged by @ajbozarth in the PR #1204 review. Part of #1201.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions