-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Using generated Azure HttpPipeline for the openai-java SDK
#47659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9f00da0
Fixed exception mapping for agents
jpalvarezl b22b9af
Ported classes over for http pipeline adapter
jpalvarezl 34a8685
PR feedback and style checks
jpalvarezl 3aea0f2
Merge branch 'main' into feature/unified_http_pipeline_aiprojects
jpalvarezl f2426a9
Added timeout tests, header exclusions, and clean up to match other p…
jpalvarezl e1ad861
Added tests for httpclient helpers
jpalvarezl 8415945
Formatter
jpalvarezl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
63 changes: 63 additions & 0 deletions
63
...cts/src/main/java/com/azure/ai/projects/implementation/http/AzureHttpResponseAdapter.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.ai.projects.implementation.http; | ||
|
|
||
| import com.azure.core.http.HttpHeader; | ||
| import com.azure.core.http.HttpHeaders; | ||
| import com.azure.core.util.logging.ClientLogger; | ||
| import com.openai.core.http.Headers; | ||
| import com.openai.core.http.HttpResponse; | ||
|
|
||
| import java.io.InputStream; | ||
|
|
||
| /** | ||
| * Adapter that exposes an Azure {@link com.azure.core.http.HttpResponse} as an OpenAI {@link HttpResponse}. This keeps | ||
| * the translation logic encapsulated so response handling elsewhere can remain framework agnostic. | ||
| */ | ||
| final class AzureHttpResponseAdapter implements HttpResponse { | ||
|
|
||
| private static final ClientLogger LOGGER = new ClientLogger(AzureHttpResponseAdapter.class); | ||
|
|
||
| private final com.azure.core.http.HttpResponse azureResponse; | ||
|
|
||
| /** | ||
| * Creates a new adapter instance for the provided Azure response. | ||
| * | ||
| * @param azureResponse Response returned by the Azure pipeline. | ||
| */ | ||
| AzureHttpResponseAdapter(com.azure.core.http.HttpResponse azureResponse) { | ||
| this.azureResponse = azureResponse; | ||
| } | ||
|
|
||
| @Override | ||
| public int statusCode() { | ||
| return azureResponse.getStatusCode(); | ||
| } | ||
|
|
||
| @Override | ||
| public Headers headers() { | ||
| return toOpenAiHeaders(azureResponse.getHeaders()); | ||
| } | ||
|
|
||
| @Override | ||
| public InputStream body() { | ||
| return azureResponse.getBodyAsBinaryData().toStream(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| azureResponse.close(); | ||
| } | ||
|
|
||
| /** | ||
| * Copies headers from the Azure response into the immutable OpenAI {@link Headers} collection. | ||
| */ | ||
| private static Headers toOpenAiHeaders(HttpHeaders httpHeaders) { | ||
| Headers.Builder builder = Headers.builder(); | ||
| for (HttpHeader header : httpHeaders) { | ||
| builder.put(header.getName(), header.getValuesList()); | ||
| } | ||
| return builder.build(); | ||
| } | ||
| } | ||
jpalvarezl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.