-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(internal): extract request preparation logic
- Loading branch information
1 parent
3f6dedd
commit b5f0576
Showing
138 changed files
with
1,450 additions
and
1,652 deletions.
There are no files selected for viewing
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
16 changes: 16 additions & 0 deletions
16
openai-java-core/src/main/kotlin/com/openai/core/Params.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,16 @@ | ||
package com.openai.core | ||
|
||
import com.openai.core.http.Headers | ||
import com.openai.core.http.QueryParams | ||
|
||
/** An interface representing parameters passed to a service method. */ | ||
interface Params { | ||
/** The full set of headers in the parameters, including both fixed and additional headers. */ | ||
fun _headers(): Headers | ||
|
||
/** | ||
* The full set of query params in the parameters, including both fixed and additional query | ||
* params. | ||
*/ | ||
fun _queryParams(): QueryParams | ||
} |
36 changes: 36 additions & 0 deletions
36
openai-java-core/src/main/kotlin/com/openai/core/PrepareRequest.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,36 @@ | ||
@file:JvmName("PrepareRequest") | ||
|
||
package com.openai.core | ||
|
||
import com.openai.azure.addPathSegmentsForAzure | ||
import com.openai.azure.replaceBearerTokenForAzure | ||
import com.openai.core.http.HttpRequest | ||
import java.util.concurrent.CompletableFuture | ||
|
||
@JvmSynthetic | ||
internal fun HttpRequest.prepare( | ||
clientOptions: ClientOptions, | ||
params: Params, | ||
deploymentModel: String? | ||
): HttpRequest = | ||
toBuilder() | ||
// Clear the path segments and add them back below after the Azure path segments. | ||
.pathSegments(listOf()) | ||
.addPathSegmentsForAzure(clientOptions, deploymentModel) | ||
.addPathSegments(*pathSegments.toTypedArray()) | ||
.putAllQueryParams(clientOptions.queryParams) | ||
.replaceAllQueryParams(params._queryParams()) | ||
.putAllHeaders(clientOptions.headers) | ||
.replaceBearerTokenForAzure(clientOptions) | ||
.replaceAllHeaders(params._headers()) | ||
.build() | ||
|
||
@JvmSynthetic | ||
internal fun HttpRequest.prepareAsync( | ||
clientOptions: ClientOptions, | ||
params: Params, | ||
deploymentModel: String? | ||
): CompletableFuture<HttpRequest> = | ||
// This async version exists to make it easier to add async specific preparation logic in the | ||
// future. | ||
CompletableFuture.completedFuture(prepare(clientOptions, params, deploymentModel)) |
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
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
Oops, something went wrong.