Skip to content

Commit 2e0602a

Browse files
feat(api): api update
1 parent e884ada commit 2e0602a

8 files changed

Lines changed: 238 additions & 39 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 100
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/langsmith%2Flangsmith-api-6cef4b7de5da7f659688522ec26b9660629f8593c1f5583cd935e3a4dfcf3ed5.yml
3-
openapi_spec_hash: 0f1ebe87b02c21658125aefb830dd9dd
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/langsmith%2Flangsmith-api-e2d42982642f5a5c97156df578c281ed5e1a7ab8381557ed0fbfa85748a77f16.yml
3+
openapi_spec_hash: 53489245092e86bf20ecc49235c452c3
44
config_hash: d847cdf0b10e3d2ae194df8fed4ae22a

langsmith-java-core/src/main/kotlin/com/langchain/smith/models/feedback/FeedbackListParams.kt

Lines changed: 166 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.langchain.smith.models.feedback
44

55
import com.langchain.smith.core.Params
6+
import com.langchain.smith.core.getOrThrow
67
import com.langchain.smith.core.http.Headers
78
import com.langchain.smith.core.http.QueryParams
89
import com.langchain.smith.core.toImmutable
@@ -25,8 +26,8 @@ private constructor(
2526
private val maxCreatedAt: OffsetDateTime?,
2627
private val minCreatedAt: OffsetDateTime?,
2728
private val offset: Long?,
28-
private val run: List<String>?,
29-
private val session: List<String>?,
29+
private val run: Run?,
30+
private val session: Session?,
3031
private val source: List<SourceType>?,
3132
private val user: List<String>?,
3233
private val additionalHeaders: Headers,
@@ -54,9 +55,9 @@ private constructor(
5455

5556
fun offset(): Optional<Long> = Optional.ofNullable(offset)
5657

57-
fun run(): Optional<List<String>> = Optional.ofNullable(run)
58+
fun run(): Optional<Run> = Optional.ofNullable(run)
5859

59-
fun session(): Optional<List<String>> = Optional.ofNullable(session)
60+
fun session(): Optional<Session> = Optional.ofNullable(session)
6061

6162
fun source(): Optional<List<SourceType>> = Optional.ofNullable(source)
6263

@@ -91,8 +92,8 @@ private constructor(
9192
private var maxCreatedAt: OffsetDateTime? = null
9293
private var minCreatedAt: OffsetDateTime? = null
9394
private var offset: Long? = null
94-
private var run: MutableList<String>? = null
95-
private var session: MutableList<String>? = null
95+
private var run: Run? = null
96+
private var session: Session? = null
9697
private var source: MutableList<SourceType>? = null
9798
private var user: MutableList<String>? = null
9899
private var additionalHeaders: Headers.Builder = Headers.builder()
@@ -110,8 +111,8 @@ private constructor(
110111
maxCreatedAt = feedbackListParams.maxCreatedAt
111112
minCreatedAt = feedbackListParams.minCreatedAt
112113
offset = feedbackListParams.offset
113-
run = feedbackListParams.run?.toMutableList()
114-
session = feedbackListParams.session?.toMutableList()
114+
run = feedbackListParams.run
115+
session = feedbackListParams.session
115116
source = feedbackListParams.source?.toMutableList()
116117
user = feedbackListParams.user?.toMutableList()
117118
additionalHeaders = feedbackListParams.additionalHeaders.toBuilder()
@@ -225,33 +226,27 @@ private constructor(
225226
/** Alias for calling [Builder.offset] with `offset.orElse(null)`. */
226227
fun offset(offset: Optional<Long>) = offset(offset.getOrNull())
227228

228-
fun run(run: List<String>?) = apply { this.run = run?.toMutableList() }
229+
fun run(run: Run?) = apply { this.run = run }
229230

230231
/** Alias for calling [Builder.run] with `run.orElse(null)`. */
231-
fun run(run: Optional<List<String>>) = run(run.getOrNull())
232+
fun run(run: Optional<Run>) = run(run.getOrNull())
232233

233-
/**
234-
* Adds a single [String] to [Builder.run].
235-
*
236-
* @throws IllegalStateException if the field was previously set to a non-list.
237-
*/
238-
fun addRun(run: String) = apply {
239-
this.run = (this.run ?: mutableListOf()).apply { add(run) }
240-
}
234+
/** Alias for calling [run] with `Run.ofStrings(strings)`. */
235+
fun runOfStrings(strings: List<String>) = run(Run.ofStrings(strings))
236+
237+
/** Alias for calling [run] with `Run.ofString(string)`. */
238+
fun run(string: String) = run(Run.ofString(string))
241239

242-
fun session(session: List<String>?) = apply { this.session = session?.toMutableList() }
240+
fun session(session: Session?) = apply { this.session = session }
243241

244242
/** Alias for calling [Builder.session] with `session.orElse(null)`. */
245-
fun session(session: Optional<List<String>>) = session(session.getOrNull())
243+
fun session(session: Optional<Session>) = session(session.getOrNull())
246244

247-
/**
248-
* Adds a single [String] to [Builder.session].
249-
*
250-
* @throws IllegalStateException if the field was previously set to a non-list.
251-
*/
252-
fun addSession(session: String) = apply {
253-
this.session = (this.session ?: mutableListOf()).apply { add(session) }
254-
}
245+
/** Alias for calling [session] with `Session.ofStrings(strings)`. */
246+
fun sessionOfStrings(strings: List<String>) = session(Session.ofStrings(strings))
247+
248+
/** Alias for calling [session] with `Session.ofString(string)`. */
249+
fun session(string: String) = session(Session.ofString(string))
255250

256251
fun source(source: List<SourceType>?) = apply { this.source = source?.toMutableList() }
257252

@@ -396,8 +391,8 @@ private constructor(
396391
maxCreatedAt,
397392
minCreatedAt,
398393
offset,
399-
run?.toImmutable(),
400-
session?.toImmutable(),
394+
run,
395+
session,
401396
source?.toImmutable(),
402397
user?.toImmutable(),
403398
additionalHeaders.build(),
@@ -424,14 +419,153 @@ private constructor(
424419
put("min_created_at", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(it))
425420
}
426421
offset?.let { put("offset", it.toString()) }
427-
run?.let { put("run", it.joinToString(",")) }
428-
session?.let { put("session", it.joinToString(",")) }
422+
run?.accept(
423+
object : Run.Visitor<Unit> {
424+
override fun visitStrings(strings: List<String>) {
425+
put("run", strings.joinToString(","))
426+
}
427+
428+
override fun visitString(string: String) {
429+
put("run", string)
430+
}
431+
}
432+
)
433+
session?.accept(
434+
object : Session.Visitor<Unit> {
435+
override fun visitStrings(strings: List<String>) {
436+
put("session", strings.joinToString(","))
437+
}
438+
439+
override fun visitString(string: String) {
440+
put("session", string)
441+
}
442+
}
443+
)
429444
source?.let { put("source", it.joinToString(",") { it.toString() }) }
430445
user?.let { put("user", it.joinToString(",")) }
431446
putAll(additionalQueryParams)
432447
}
433448
.build()
434449

450+
class Run
451+
private constructor(
452+
private val strings: List<String>? = null,
453+
private val string: String? = null,
454+
) {
455+
456+
fun strings(): Optional<List<String>> = Optional.ofNullable(strings)
457+
458+
fun string(): Optional<String> = Optional.ofNullable(string)
459+
460+
fun isStrings(): Boolean = strings != null
461+
462+
fun isString(): Boolean = string != null
463+
464+
fun asStrings(): List<String> = strings.getOrThrow("strings")
465+
466+
fun asString(): String = string.getOrThrow("string")
467+
468+
fun <T> accept(visitor: Visitor<T>): T =
469+
when {
470+
strings != null -> visitor.visitStrings(strings)
471+
string != null -> visitor.visitString(string)
472+
else -> throw IllegalStateException("Invalid Run")
473+
}
474+
475+
override fun equals(other: Any?): Boolean {
476+
if (this === other) {
477+
return true
478+
}
479+
480+
return other is Run && strings == other.strings && string == other.string
481+
}
482+
483+
override fun hashCode(): Int = Objects.hash(strings, string)
484+
485+
override fun toString(): String =
486+
when {
487+
strings != null -> "Run{strings=$strings}"
488+
string != null -> "Run{string=$string}"
489+
else -> throw IllegalStateException("Invalid Run")
490+
}
491+
492+
companion object {
493+
494+
@JvmStatic fun ofStrings(strings: List<String>) = Run(strings = strings.toImmutable())
495+
496+
@JvmStatic fun ofString(string: String) = Run(string = string)
497+
}
498+
499+
/** An interface that defines how to map each variant of [Run] to a value of type [T]. */
500+
interface Visitor<out T> {
501+
502+
fun visitStrings(strings: List<String>): T
503+
504+
fun visitString(string: String): T
505+
}
506+
}
507+
508+
class Session
509+
private constructor(
510+
private val strings: List<String>? = null,
511+
private val string: String? = null,
512+
) {
513+
514+
fun strings(): Optional<List<String>> = Optional.ofNullable(strings)
515+
516+
fun string(): Optional<String> = Optional.ofNullable(string)
517+
518+
fun isStrings(): Boolean = strings != null
519+
520+
fun isString(): Boolean = string != null
521+
522+
fun asStrings(): List<String> = strings.getOrThrow("strings")
523+
524+
fun asString(): String = string.getOrThrow("string")
525+
526+
fun <T> accept(visitor: Visitor<T>): T =
527+
when {
528+
strings != null -> visitor.visitStrings(strings)
529+
string != null -> visitor.visitString(string)
530+
else -> throw IllegalStateException("Invalid Session")
531+
}
532+
533+
override fun equals(other: Any?): Boolean {
534+
if (this === other) {
535+
return true
536+
}
537+
538+
return other is Session && strings == other.strings && string == other.string
539+
}
540+
541+
override fun hashCode(): Int = Objects.hash(strings, string)
542+
543+
override fun toString(): String =
544+
when {
545+
strings != null -> "Session{strings=$strings}"
546+
string != null -> "Session{string=$string}"
547+
else -> throw IllegalStateException("Invalid Session")
548+
}
549+
550+
companion object {
551+
552+
@JvmStatic
553+
fun ofStrings(strings: List<String>) = Session(strings = strings.toImmutable())
554+
555+
@JvmStatic fun ofString(string: String) = Session(string = string)
556+
}
557+
558+
/**
559+
* An interface that defines how to map each variant of [Session] to a value of type [T].
560+
*/
561+
interface Visitor<out T> {
562+
563+
fun visitStrings(strings: List<String>): T
564+
565+
fun visitString(string: String): T
566+
}
567+
}
568+
435569
override fun equals(other: Any?): Boolean {
436570
if (this === other) {
437571
return true

0 commit comments

Comments
 (0)