Skip to content

Commit 0c1cd60

Browse files
committed
feat: update client to 3.143.0 compatibility
1 parent 574cfa0 commit 0c1cd60

File tree

21 files changed

+1628
-30
lines changed

21 files changed

+1628
-30
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,5 @@ To publish to Maven Central, you need to configure the following secrets in your
7979
3. Generate the new client code using `npx fern-api generate --api server`.
8080
4. Manually set the `package` across all files to `com.langfuse.client`.
8181
5. Overwrite `this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + encodedToken);` to `Basic` in LangfuseClientBuilder.java.
82-
6. Commit the changes in langfuse-java and push them to the repository.
82+
6. Adjust Javadoc strings with HTML properties as the apidocs package does not support them.
83+
7. Commit the changes in langfuse-java and push them to the repository.

src/main/java/com/langfuse/client/LangfuseClient.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import com.langfuse.client.resources.llmconnections.LlmConnectionsClient;
1919
import com.langfuse.client.resources.media.MediaClient;
2020
import com.langfuse.client.resources.metrics.MetricsClient;
21+
import com.langfuse.client.resources.metricsv2.MetricsV2Client;
2122
import com.langfuse.client.resources.models.ModelsClient;
2223
import com.langfuse.client.resources.observations.ObservationsClient;
24+
import com.langfuse.client.resources.observationsv2.ObservationsV2Client;
2325
import com.langfuse.client.resources.opentelemetry.OpentelemetryClient;
2426
import com.langfuse.client.resources.organizations.OrganizationsClient;
2527
import com.langfuse.client.resources.projects.ProjectsClient;
@@ -55,10 +57,14 @@ public class LangfuseClient {
5557

5658
protected final Supplier<MediaClient> mediaClient;
5759

60+
protected final Supplier<MetricsV2Client> metricsV2Client;
61+
5862
protected final Supplier<MetricsClient> metricsClient;
5963

6064
protected final Supplier<ModelsClient> modelsClient;
6165

66+
protected final Supplier<ObservationsV2Client> observationsV2Client;
67+
6268
protected final Supplier<ObservationsClient> observationsClient;
6369

6470
protected final Supplier<OpentelemetryClient> opentelemetryClient;
@@ -95,8 +101,10 @@ public LangfuseClient(ClientOptions clientOptions) {
95101
this.ingestionClient = Suppliers.memoize(() -> new IngestionClient(clientOptions));
96102
this.llmConnectionsClient = Suppliers.memoize(() -> new LlmConnectionsClient(clientOptions));
97103
this.mediaClient = Suppliers.memoize(() -> new MediaClient(clientOptions));
104+
this.metricsV2Client = Suppliers.memoize(() -> new MetricsV2Client(clientOptions));
98105
this.metricsClient = Suppliers.memoize(() -> new MetricsClient(clientOptions));
99106
this.modelsClient = Suppliers.memoize(() -> new ModelsClient(clientOptions));
107+
this.observationsV2Client = Suppliers.memoize(() -> new ObservationsV2Client(clientOptions));
100108
this.observationsClient = Suppliers.memoize(() -> new ObservationsClient(clientOptions));
101109
this.opentelemetryClient = Suppliers.memoize(() -> new OpentelemetryClient(clientOptions));
102110
this.organizationsClient = Suppliers.memoize(() -> new OrganizationsClient(clientOptions));
@@ -151,6 +159,10 @@ public MediaClient media() {
151159
return this.mediaClient.get();
152160
}
153161

162+
public MetricsV2Client metricsV2() {
163+
return this.metricsV2Client.get();
164+
}
165+
154166
public MetricsClient metrics() {
155167
return this.metricsClient.get();
156168
}
@@ -159,6 +171,10 @@ public ModelsClient models() {
159171
return this.modelsClient.get();
160172
}
161173

174+
public ObservationsV2Client observationsV2() {
175+
return this.observationsV2Client.get();
176+
}
177+
162178
public ObservationsClient observations() {
163179
return this.observationsClient.get();
164180
}

src/main/java/com/langfuse/client/core/ClientOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private ClientOptions(Environment environment, Map<String, String> headers,
2727
this.environment = environment;
2828
this.headers = new HashMap<>();
2929
this.headers.putAll(headers);
30-
this.headers.putAll(new HashMap<String,String>() {{put("X-Fern-Language", "JAVA");put("X-Fern-SDK-Name", "com.langfuse.fern:langfuse-sdk");put("X-Fern-SDK-Version", "0.0.2565");}});
30+
this.headers.putAll(new HashMap<String,String>() {{put("X-Fern-Language", "JAVA");put("X-Fern-SDK-Name", "com.langfuse.fern:langfuse-sdk");put("X-Fern-SDK-Version", "0.0.2841");}});
3131
this.headerSuppliers = headerSuppliers;
3232
this.httpClient = httpClient;
3333
this.timeout = timeout;

src/main/java/com/langfuse/client/resources/commons/types/ScoreConfig.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public final class ScoreConfig {
3939

4040
private final String projectId;
4141

42-
private final ScoreDataType dataType;
42+
private final ScoreConfigDataType dataType;
4343

4444
private final boolean isArchived;
4545

@@ -54,7 +54,7 @@ public final class ScoreConfig {
5454
private final Map<String, Object> additionalProperties;
5555

5656
private ScoreConfig(String id, String name, OffsetDateTime createdAt, OffsetDateTime updatedAt,
57-
String projectId, ScoreDataType dataType, boolean isArchived, Optional<Double> minValue,
57+
String projectId, ScoreConfigDataType dataType, boolean isArchived, Optional<Double> minValue,
5858
Optional<Double> maxValue, Optional<List<ConfigCategory>> categories,
5959
Optional<String> description, Map<String, Object> additionalProperties) {
6060
this.id = id;
@@ -97,7 +97,7 @@ public String getProjectId() {
9797
}
9898

9999
@JsonProperty("dataType")
100-
public ScoreDataType getDataType() {
100+
public ScoreConfigDataType getDataType() {
101101
return dataType;
102102
}
103103

@@ -190,7 +190,7 @@ public interface ProjectIdStage {
190190
}
191191

192192
public interface DataTypeStage {
193-
IsArchivedStage dataType(@NotNull ScoreDataType dataType);
193+
IsArchivedStage dataType(@NotNull ScoreConfigDataType dataType);
194194
}
195195

196196
public interface IsArchivedStage {
@@ -231,7 +231,7 @@ public static final class Builder implements IdStage, NameStage, CreatedAtStage,
231231

232232
private String projectId;
233233

234-
private ScoreDataType dataType;
234+
private ScoreConfigDataType dataType;
235235

236236
private boolean isArchived;
237237

@@ -302,7 +302,7 @@ public DataTypeStage projectId(@NotNull String projectId) {
302302

303303
@java.lang.Override
304304
@JsonSetter("dataType")
305-
public IsArchivedStage dataType(@NotNull ScoreDataType dataType) {
305+
public IsArchivedStage dataType(@NotNull ScoreConfigDataType dataType) {
306306
this.dataType = Objects.requireNonNull(dataType, "dataType must not be null");
307307
return this;
308308
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
package com.langfuse.client.resources.commons.types;
6+
7+
import com.fasterxml.jackson.annotation.JsonValue;
8+
import java.lang.String;
9+
10+
public enum ScoreConfigDataType {
11+
NUMERIC("NUMERIC"),
12+
13+
BOOLEAN("BOOLEAN"),
14+
15+
CATEGORICAL("CATEGORICAL");
16+
17+
private final String value;
18+
19+
ScoreConfigDataType(String value) {
20+
this.value = value;
21+
}
22+
23+
@JsonValue
24+
@java.lang.Override
25+
public String toString() {
26+
return this.value;
27+
}
28+
}

src/main/java/com/langfuse/client/resources/commons/types/ScoreDataType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ public enum ScoreDataType {
1212

1313
BOOLEAN("BOOLEAN"),
1414

15-
CATEGORICAL("CATEGORICAL");
15+
CATEGORICAL("CATEGORICAL"),
16+
17+
CORRECTION("CORRECTION");
1618

1719
private final String value;
1820

src/main/java/com/langfuse/client/resources/ingestion/types/ScoreBody.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public Optional<String> getDatasetRunId() {
102102
return datasetRunId;
103103
}
104104

105+
/**
106+
* @return The name of the score. Always overrides &quot;output&quot; for correction scores.
107+
*/
105108
@JsonProperty("name")
106109
public String getName() {
107110
return name;
@@ -295,6 +298,10 @@ public Builder from(ScoreBody other) {
295298
return this;
296299
}
297300

301+
/**
302+
* <p>The name of the score. Always overrides &quot;output&quot; for correction scores.</p>
303+
* @return Reference to {@code this} so that method calls can be chained together.
304+
*/
298305
@java.lang.Override
299306
@JsonSetter("name")
300307
public ValueStage name(@NotNull String name) {

src/main/java/com/langfuse/client/resources/metrics/MetricsClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public MetricsClient(ClientOptions clientOptions) {
3737

3838
/**
3939
* Get metrics from the Langfuse project using a query object.
40+
* <p>Consider using the <a href="/api-reference#tag/metricsv2/GET/api/public/v2/metrics">v2 metrics endpoint</a> for better performance.</p>
4041
* <p>For more details, see the <a href="https://langfuse.com/docs/metrics/features/metrics-api">Metrics API documentation</a>.</p>
4142
*/
4243
public MetricsResponse metrics(GetMetricsRequest request) {
@@ -45,6 +46,7 @@ public MetricsResponse metrics(GetMetricsRequest request) {
4546

4647
/**
4748
* Get metrics from the Langfuse project using a query object.
49+
* <p>Consider using the <a href="/api-reference#tag/metricsv2/GET/api/public/v2/metrics">v2 metrics endpoint</a> for better performance.</p>
4850
* <p>For more details, see the <a href="https://langfuse.com/docs/metrics/features/metrics-api">Metrics API documentation</a>.</p>
4951
*/
5052
public MetricsResponse metrics(GetMetricsRequest request, RequestOptions requestOptions) {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
package com.langfuse.client.resources.metricsv2;
6+
7+
import com.fasterxml.jackson.core.JsonProcessingException;
8+
import com.langfuse.client.core.ClientOptions;
9+
import com.langfuse.client.core.LangfuseClientApiException;
10+
import com.langfuse.client.core.LangfuseClientException;
11+
import com.langfuse.client.core.ObjectMappers;
12+
import com.langfuse.client.core.QueryStringMapper;
13+
import com.langfuse.client.core.RequestOptions;
14+
import java.io.IOException;
15+
import java.lang.Object;
16+
import java.lang.String;
17+
import okhttp3.Headers;
18+
import okhttp3.HttpUrl;
19+
import okhttp3.OkHttpClient;
20+
import okhttp3.Request;
21+
import okhttp3.Response;
22+
import okhttp3.ResponseBody;
23+
import com.langfuse.client.resources.commons.errors.AccessDeniedError;
24+
import com.langfuse.client.resources.commons.errors.Error;
25+
import com.langfuse.client.resources.commons.errors.MethodNotAllowedError;
26+
import com.langfuse.client.resources.commons.errors.NotFoundError;
27+
import com.langfuse.client.resources.commons.errors.UnauthorizedError;
28+
import com.langfuse.client.resources.metricsv2.requests.GetMetricsV2Request;
29+
import com.langfuse.client.resources.metricsv2.types.MetricsV2Response;
30+
31+
public class MetricsV2Client {
32+
protected final ClientOptions clientOptions;
33+
34+
public MetricsV2Client(ClientOptions clientOptions) {
35+
this.clientOptions = clientOptions;
36+
}
37+
38+
/**
39+
* Get metrics from the Langfuse project using a query object. V2 endpoint with optimized performance.
40+
*/
41+
public MetricsV2Response metrics(GetMetricsV2Request request) {
42+
return metrics(request,null);
43+
}
44+
45+
/**
46+
* Get metrics from the Langfuse project using a query object. V2 endpoint with optimized performance.
47+
*/
48+
public MetricsV2Response metrics(GetMetricsV2Request request, RequestOptions requestOptions) {
49+
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder()
50+
.addPathSegments("api/public")
51+
.addPathSegments("v2/metrics");QueryStringMapper.addQueryParameter(httpUrl, "query", request.getQuery(), false);
52+
Request.Builder _requestBuilder = new Request.Builder()
53+
.url(httpUrl.build())
54+
.method("GET", null)
55+
.headers(Headers.of(clientOptions.headers(requestOptions)))
56+
.addHeader("Content-Type", "application/json")
57+
.addHeader("Accept", "application/json");
58+
Request okhttpRequest = _requestBuilder.build();
59+
OkHttpClient client = clientOptions.httpClient();
60+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
61+
client = clientOptions.httpClientWithTimeout(requestOptions);
62+
}
63+
try (Response response = client.newCall(okhttpRequest).execute()) {
64+
ResponseBody responseBody = response.body();
65+
if (response.isSuccessful()) {
66+
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), MetricsV2Response.class);
67+
}
68+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
69+
try {
70+
switch (response.code()) {
71+
case 400:throw new Error(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
72+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
73+
case 403:throw new AccessDeniedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
74+
case 404:throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
75+
case 405:throw new MethodNotAllowedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
76+
}
77+
}
78+
catch (JsonProcessingException ignored) {
79+
// unable to map error response, throwing generic error
80+
}
81+
throw new LangfuseClientApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
82+
}
83+
catch (IOException e) {
84+
throw new LangfuseClientException("Network error executing HTTP request", e);
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)