Skip to content

erp5_interface_openai: add the Responses API, correct the view form and protect the methods

Hello Xiaowu,

This merge request targets your branch feature/openai_connector, not master. It completes the connector of !2341 with the version that runs on the Wölfel instance. Merge it into your branch, then !2341 carries the full connector.

The document component of !2341 is our connector of 3 August 2026. Your four improvements are kept. This merge request adds the work of the last two months.

The Responses endpoint

A request that holds function tools and names a reasoning model (gpt-5, o1, o3, o4) goes to /v1/responses. Every other request goes to /v1/chat/completions. A model such as gpt-5.6-luna refuses function tools on /v1/chat/completions. An HTTP 400 answer that names /v1/responses causes one retry on /v1/responses. The caller always sees the Chat Completions answer shape, so no caller needs a change. api_style forces one endpoint.

Prompt cache and reasoning

prompt_cache_key names the prompt-prefix family of a request. The request body is always the same bytes for the same payload, so the cache of the provider matches more often. usage answers cached_tokens for both endpoints. reasoning_effort is forwarded to both endpoints.

Three corrections to the packaging

  1. my_password was a ProxyField to Base_viewWizardFieldLibrary. That field library belongs to erp5_configurator, which is not a dependency of this business template. The field also showed the API key in clear text. The field is now a PasswordField, as erp5_web_service does for the FTP Connector.
  2. my_timeout was a raw IntegerField. Every other field of the form is a ProxyField. The field is now a ProxyField to Base_viewFieldLibrary.
  3. self.getTimeout(180) raises AttributeError: getTimeout on an instance whose portal type does not hold the SocketClient property sheet. The Wölfel instance is such an instance. portal_property_sheets there does not hold SocketClient at all. _getTimeout() now answers the module constant DEFAULT_TIMEOUT when the accessor is absent.

Security

getModelList and getResponseWithUsage are no longer public. Both use declareProtected with AccessContentsInformation, as the FTP Connector does. This answers the question of Romain. A Python Script still reaches both methods. Neither method holds a docstring, so Zope publishes neither method on a URL.

Tests

Your 6 tests are kept. 8 tests are added: the endpoint selection with tools and without tools, the retry, the translation of the Responses answer, the two reasoning_effort shapes, prompt_cache_key, cached_tokens from both usage shapes, and the default timeout. Two of your tests compare the whole usage dictionary. Those two now expect cached_tokens. beforeTearDown calls self.abort().

The tests did not run under the ERP5 test runner. They pass in an offline harness that loads the real source of the component. Please run the suite on a test node.

Live proof on the Wölfel development instance

The merged source is deployed and validated there. getModelList answers 129 models. A request with tools and gpt-5.6-luna answers the forced tool call, with usage 49/18/67.

Still open, from the review of Romain

Not in this merge request: one _callOpenAIAPI for every requests call, the cap of the timeout with getTimeLeft, the name of getResponseWithUsage, and the asynchronous Background API.

Regards

🤖 Generated with Claude Code

https://claude.ai/code/session_01N7XfrJJ9UeBMjQjF9pZFbQ

Merge request reports