feat(azure): Support Responses API alongside Completions API (#1337)#1442
Open
zjl4616 wants to merge 1 commit into
Open
feat(azure): Support Responses API alongside Completions API (#1337)#1442zjl4616 wants to merge 1 commit into
zjl4616 wants to merge 1 commit into
Conversation
Add support for the OpenAI Responses API to the Azure backend,
following the same dual-backend dispatch pattern used by GitHub
Copilot (gptel-gh.el).
Changes:
- Define gptel--azure struct inheriting from gptel-openai with a
responses-backend field
- Add 11 cl-defmethod dispatchers that check for responses-api
model capability and delegate to the embedded responses backend
- Modify gptel-make-azure to create an embedded
gptel-openai-responses backend instance and use dynamic URL
selection based on model capability
- Enhance docstring with model capability documentation
- Fix typo: 'retuns' -> 'returns'
Models with the responses-api capability will automatically use the
Responses API endpoint (/openai/deployments/{deployment}/responses)
while models without it continue using the Completions API endpoint
(/openai/deployments/{deployment}/chat/completions).
Closes karthink#1337
Owner
|
Thanks for the PR @zjl4616! Please move all the azure-specific code to gptel-openai-extras.el. (If we need even more azure-specific code in the future, we can move it to a dedicated gptel-azure.el feature.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds transparent dual-backend support to
gptel-make-azure, enabling it to use the OpenAI Responses API for OpenAI models (GPT-4o, GPT-5, etc.) while falling back to the Completions API for non-OpenAI models — identical to howgptel-gh(GitHub Copilot) handles this.Closes #1337.
Motivation
Azure OpenAI now serves OpenAI models that expect the Responses API, but also hosts non-OpenAI models (Llama, Mistral, etc.) that only support the Completions API. The current
gptel-make-azureonly supports Completions, causing errors with newer OpenAI models.Implementation
Follows the exact pattern established by
gptel-gh.el:New struct
gptel--azure— inherits fromgptel-openai, adds aresponses-backendfield storing an embeddedgptel-openai-responsesinstance.11
cl-defmethoddispatchers — each checks(gptel--model-capable-p 'responses-api gptel-model)and routes to either the responses backend or falls through to the parent completions method:gptel-curl--parse-streamgptel--parse-responsegptel--request-datagptel--parse-schemagptel--parse-toolsgptel--inject-tool-callgptel--parse-tool-resultsgptel--inject-promptgptel--parse-listgptel--parse-buffergptel--inject-mediaModified
gptel-make-azure— uses the new struct, creates an embedded responses backend, dynamically selects endpoint URL based on model capability.Usage
Users mark models with
responses-apicapability:gpt-5→ automatically uses Responses API (/openai/deployments/gpt-5/responses?api-version=...)gpt-4o→ falls back to Completions API (existing behavior)Backward Compatibility
✅ Fully backward compatible. Existing Azure configurations work unchanged. Models without
responses-apicapability continue using the Completions API exactly as before.Changes
gptel-openai.el: +124/-16 lines (single file change)gptel--azurestruct definitiongptel-make-azureconstructor