Skip to content

Commit

Permalink
feat(client): add various convenience setters to models (#91)
Browse files Browse the repository at this point in the history
feat(client): allow setting arbitrary JSON for top-level body params
feat(client): expose getters for `JsonField` of body params
fix(client): consistently throw on omitting required fields
fix(client): convert `JsonField` containing list type to mutable in builder
style(internal): simplify existing convenience setters on params
style(internal): move headers and query params setters below others
style(internal): explicitly add some method return types
  • Loading branch information
stainless-app[bot] committed Jan 8, 2025
1 parent 261249a commit 983b97a
Show file tree
Hide file tree
Showing 152 changed files with 13,670 additions and 4,839 deletions.
48 changes: 24 additions & 24 deletions openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,30 @@ private constructor(

fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl }

fun responseValidation(responseValidation: Boolean) = apply {
this.responseValidation = responseValidation
}

fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries }

fun apiKey(apiKey: String) = apply {
this.credential = BearerTokenCredential.create(apiKey)
}

fun credential(credential: Credential) = apply { this.credential = credential }

fun azureServiceVersion(azureServiceVersion: AzureOpenAIServiceVersion) = apply {
this.azureServiceVersion = azureServiceVersion
}

fun organization(organization: String?) = apply { this.organization = organization }

fun organization(organization: Optional<String>) = organization(organization.orElse(null))

fun project(project: String?) = apply { this.project = project }

fun project(project: Optional<String>) = project(project.orElse(null))

fun headers(headers: Headers) = apply {
this.headers.clear()
putAllHeaders(headers)
Expand Down Expand Up @@ -172,30 +196,6 @@ private constructor(

fun removeAllQueryParams(keys: Set<String>) = apply { queryParams.removeAll(keys) }

fun responseValidation(responseValidation: Boolean) = apply {
this.responseValidation = responseValidation
}

fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries }

fun apiKey(apiKey: String) = apply {
this.credential = BearerTokenCredential.create(apiKey)
}

fun credential(credential: Credential) = apply { this.credential = credential }

fun azureServiceVersion(azureServiceVersion: AzureOpenAIServiceVersion) = apply {
this.azureServiceVersion = azureServiceVersion
}

fun organization(organization: String?) = apply { this.organization = organization }

fun organization(organization: Optional<String>) = organization(organization.orElse(null))

fun project(project: String?) = apply { this.project = project }

fun project(project: Optional<String>) = project(project.orElse(null))

fun fromEnv() = apply {
val openAIKey = System.getenv("OPENAI_API_KEY")
val openAIOrgId = System.getenv("OPENAI_ORG_ID")
Expand Down
287 changes: 228 additions & 59 deletions openai-java-core/src/main/kotlin/com/openai/models/Assistant.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ private constructor(

fun object_(): Object = object_.getRequired("object")

@JsonProperty("id") @ExcludeMissing fun _id() = id
@JsonProperty("id") @ExcludeMissing fun _id(): JsonField<String> = id

@JsonProperty("deleted") @ExcludeMissing fun _deleted() = deleted
@JsonProperty("deleted") @ExcludeMissing fun _deleted(): JsonField<Boolean> = deleted

@JsonProperty("object") @ExcludeMissing fun _object_() = object_
@JsonProperty("object") @ExcludeMissing fun _object_(): JsonField<Object> = object_

@JsonAnyGetter
@ExcludeMissing
Expand All @@ -67,9 +67,9 @@ private constructor(

class Builder {

private var id: JsonField<String> = JsonMissing.of()
private var deleted: JsonField<Boolean> = JsonMissing.of()
private var object_: JsonField<Object> = JsonMissing.of()
private var id: JsonField<String>? = null
private var deleted: JsonField<Boolean>? = null
private var object_: JsonField<Object>? = null
private var additionalProperties: MutableMap<String, JsonValue> = mutableMapOf()

@JvmSynthetic
Expand Down Expand Up @@ -113,9 +113,9 @@ private constructor(

fun build(): AssistantDeleted =
AssistantDeleted(
id,
deleted,
object_,
checkNotNull(id) { "`id` is required but was not set" },
checkNotNull(deleted) { "`deleted` is required but was not set" },
checkNotNull(object_) { "`object_` is required but was not set" },
additionalProperties.toImmutable(),
)
}
Expand Down
Loading

0 comments on commit 983b97a

Please sign in to comment.