Skip to content
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

feat(client): add various convenience setters to models #91

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions openai-java-core/src/main/kotlin/com/openai/core/ClientOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ 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.apiKey = apiKey }

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 @@ -166,22 +182,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.apiKey = apiKey }

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 {
System.getenv("OPENAI_API_KEY")?.let { apiKey(it) }
System.getenv("OPENAI_ORG_ID")?.let { organization(it) }
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