Skip to content

Commit 63e0bdc

Browse files
authored
feat: Rework wrapOpenAI (#114)
* Update wrapOpenAI * Remove * Fixes * nits * Feedback * Cache * Remove comment * Fix
1 parent 07c7604 commit 63e0bdc

18 files changed

Lines changed: 1183 additions & 2514 deletions

File tree

langsmith-java-core/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ dependencies {
5252
api("io.opentelemetry:opentelemetry-exporter-otlp:1.32.0")
5353
api("io.opentelemetry.semconv:opentelemetry-semconv:1.23.1-alpha")
5454

55-
// OpenAI SDK (for OpenTelemetry wrappers)
56-
api("com.openai:openai-java:4.6.1")
55+
// OpenAI SDK (for wrapOpenAI tracing wrapper)
56+
api("com.openai:openai-java:4.30.0")
5757

5858
// Mustache template engine (for prompt template formatting)
5959
implementation("com.samskivert:jmustache:1.16")

langsmith-java-core/src/main/kotlin/com/langchain/smith/tracing/TraceProcessIO.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ import java.util.function.Function
88
* Typed processors for transforming inputs and outputs before they are recorded on a traced run.
99
*
1010
* The type parameters describe what the processors receive:
11-
* - [PI] — the type passed to [inputs]. For 1-arg traced functions this is the raw input type; for
12-
* 0/2/3-arg functions this is `Map<String, Any?>` (the packed representation).
13-
* - [PO] — the type passed to [outputs]. This is always the raw output type of the traced function.
11+
* - [PI] — the type passed to `processInputs`. Depends on the arity of the traced function:
12+
* - **1-arg** ([traceFunction]): the raw input type (e.g. `String`)
13+
* - **0-arg** ([traceSupplier]): `Map<String, Any?>` (empty map)
14+
* - **2-arg** ([traceBiFunction]): `Pair<I1, I2>`
15+
* - **3-arg** ([traceTriFunction]): `Triple<I1, I2, I3>`
16+
* - [PO] — the type passed to `processOutputs`. This is always the raw output type of the traced
17+
* function.
1418
*
1519
* When [inputs] is set, it replaces the default input serialization entirely. Same for [outputs].
1620
*

langsmith-java-core/src/main/kotlin/com/langchain/smith/tracing/Traceable.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,9 @@ fun <I, O> traceable(block: Function<I, O>, config: TraceConfig): Function<I, O>
464464
fun <I1, I2, O> traceable(block: (I1, I2) -> O, config: TraceConfig): (I1, I2) -> O {
465465
val resolvedConfig = resolveConfig(config, block)
466466
return { i1, i2 ->
467-
val packed = mapOf<String, Any?>("args" to listOf(i1, i2))
468-
val serializedInputs = applyProcessInputs(resolvedConfig, packed) ?: packed
467+
val rawArgs = Pair(i1, i2)
468+
val serializedInputs =
469+
applyProcessInputs(resolvedConfig, rawArgs) ?: mapOf("args" to listOf(i1, i2))
469470
executeTraced(resolvedConfig, serializedInputs) { block(i1, i2) }
470471
}
471472
}
@@ -484,8 +485,9 @@ fun <I1, I2, O> traceable(
484485
fun <I1, I2, I3, O> traceable(block: (I1, I2, I3) -> O, config: TraceConfig): (I1, I2, I3) -> O {
485486
val resolvedConfig = resolveConfig(config, block)
486487
return { i1, i2, i3 ->
487-
val packed = mapOf<String, Any?>("args" to listOf(i1, i2, i3))
488-
val serializedInputs = applyProcessInputs(resolvedConfig, packed) ?: packed
488+
val rawArgs = Triple(i1, i2, i3)
489+
val serializedInputs =
490+
applyProcessInputs(resolvedConfig, rawArgs) ?: mapOf("args" to listOf(i1, i2, i3))
489491
executeTraced(resolvedConfig, serializedInputs) { block(i1, i2, i3) }
490492
}
491493
}

langsmith-java-core/src/main/kotlin/com/langchain/smith/wrappers/openai/ExperimentContext.kt

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)