-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(azure): Add HttpRequest.Builder extension methods (#9)
* Added HttpRequest.Builder extension methods * remove unused imports --------- Co-authored-by: Robert Craigie <robert@craigie.dev>
- Loading branch information
1 parent
d9f6033
commit 5b774cd
Showing
9 changed files
with
59 additions
and
30 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
openai-java-core/src/main/kotlin/com/openai/azure/HttpRequestBuilderExtensions.kt
This file contains 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,27 @@ | ||
package com.openai.azure | ||
|
||
import com.openai.core.ClientOptions | ||
import com.openai.core.http.HttpRequest | ||
import com.openai.core.isAzureEndpoint | ||
import com.openai.credential.BearerTokenCredential | ||
|
||
@JvmSynthetic | ||
internal fun HttpRequest.Builder.addPathSegmentsForAzure( | ||
clientOptions: ClientOptions, | ||
deploymentModel: String | ||
): HttpRequest.Builder = apply { | ||
if (isAzureEndpoint(clientOptions.baseUrl)) { | ||
addPathSegments("openai", "deployments", deploymentModel) | ||
} | ||
} | ||
|
||
@JvmSynthetic | ||
internal fun HttpRequest.Builder.replaceBearerTokenForAzure( | ||
clientOptions: ClientOptions | ||
): HttpRequest.Builder = apply { | ||
if ( | ||
isAzureEndpoint(clientOptions.baseUrl) && clientOptions.credential is BearerTokenCredential | ||
) { | ||
replaceHeaders("Authorization", "Bearer ${clientOptions.credential.token()}") | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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