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
-
my_passwordwas a ProxyField toBase_viewWizardFieldLibrary. That field library belongs toerp5_configurator, which is not a dependency of this business template. The field also showed the API key in clear text. The field is now aPasswordField, aserp5_web_servicedoes for the FTP Connector. -
my_timeoutwas a rawIntegerField. Every other field of the form is a ProxyField. The field is now a ProxyField toBase_viewFieldLibrary. -
self.getTimeout(180)raisesAttributeError: getTimeouton an instance whose portal type does not hold theSocketClientproperty sheet. The Wölfel instance is such an instance.portal_property_sheetsthere does not holdSocketClientat all._getTimeout()now answers the module constantDEFAULT_TIMEOUTwhen 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