8000 chore: update api endpoints and add CI (#4) · langfuse/langfuse-java@e071986 · GitHub
[go: up one dir, main page]

Skip to content

Commit e071986

Browse files
authored
chore: update api endpoints and add CI (#4)
1 parent 74a6e04 commit e071986

File tree

9 files changed

+699
-1
lines changed

9 files changed

+699
-1
lines changed

.github/workflows/build.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Java
15+
uses: actions/setup-java@v4
16+
with:
17+
java-version: '23'
18+
distribution: 'temurin'
19+
20+
- name: Build with Maven
21+
run: mvn clean package

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.120");}});
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.169");}});
3131
this.headerSuppliers = headerSuppliers;
3232
this.httpClient = httpClient;
3333
this.timeout = timeout;

src/main/java/com/langfuse/client/resources/datasetitems/DatasetItemsClient.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.langfuse.client.resources.commons.types.DatasetItem;
3131
import com.langfuse.client.resources.datasetitems.requests.GetDatasetItemsRequest;
3232
import com.langfuse.client.resources.datasetitems.types.CreateDatasetItemRequest;
33+
import com.langfuse.client.resources.datasetitems.types.DeleteDatasetItemResponse;
3334
import com.langfuse.client.resources.datasetitems.types.PaginatedDatasetItems;
3435

3536
public class DatasetItemsClient {
@@ -219,4 +220,56 @@ public PaginatedDatasetItems list(GetDatasetItemsRequest request, RequestOptions
219220
throw new LangfuseClientException("Network error executing HTTP request", e);
220221
}
221222
}
223+
224+
/**
225+
* Delete a dataset item and all its run items. This action is irreversible.
226+
*/
227+
public DeleteDatasetItemResponse delete(String id) {
228+
return delete(id,null);
229+
}
230+
231+
/**
232+
* Delete a dataset item and all its run items. This action is irreversible.
233+
*/
234+
public DeleteDatasetItemResponse delete(String id, RequestOptions requestOptions) {
235+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder()
236+
.addPathSegments("api/public")
237+
.addPathSegments("dataset-items")
238+
.addPathSegment(id)
239+
.build();
240+
Request okhttpRequest = new Request.Builder()
241+
.url(httpUrl)
242+
.method("DELETE", null)
243+
.headers(Headers.of(clientOptions.headers(requestOptions)))
244+
.addHeader("Content-Type", "application/json")
245+
.addHeader("Accept", "application/json")
246+
.build();
247+
OkHttpClient client = clientOptions.httpClient();
248+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
249+
client = clientOptions.httpClientWithTimeout(requestOptions);
250+
}
251+
try (Response response = client.newCall(okhttpRequest).execute()) {
252+
ResponseBody responseBody = response.body();
253+
if (response.isSuccessful()) {
254+
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteDatasetItemResponse.class);
255+
}
256+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
257+
try {
258+
switch (response.code()) {
259+
case 400:throw new Error(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
260+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
261+
case 403:throw new AccessDeniedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
262+
case 404:throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
263+
case 405:throw new MethodNotAllowedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
264+
}
265+
}
266+
catch (JsonProcessingException ignored) {
267+
// unable to map error response, throwing generic error
268+
}
269+
throw new LangfuseClientApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
270+
}
271+
catch (IOException e) {
272+
throw new LangfuseClientException("Network error executing HTTP request", e);
273+
}
274+
}
222275
}
Lines changed: 117 additions & 0 deletions
< 10000 td data-grid-cell-id="diff-1a996d3f72d6c1c4a0d266ebac14c0b19bf64d1d9bd26a890a92c517ff07008b-empty-17-2" data-line-anchor="diff-1a996d3f72d6c1c4a0d266ebac14c0b19bf64d1d9bd26a890a92c517ff07008bR17" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionLine-bgColor, var(--diffBlob-addition-bgColor-line));padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">+
import java.util.HashMap;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
package com.langfuse.client.resources.datasetitems.types;
6+
7+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
8+
import com.fasterxml.jackson.annotation.JsonAnySetter;
9+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
10+
import com.fasterxml.jackson.annotation.JsonInclude;
11+
import com.fasterxml.jackson.annotation.JsonProperty;
12+
import com.fasterxml.jackson.annotation.JsonSetter;
13+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
14+
import com.langfuse.client.core.ObjectMappers;
15+
import java.lang.Object;
16+
import java.lang.String;
17
18+
import java.util.Map;
19+
import java.util.Objects;
20+
import org.jetbrains.annotations.NotNull;
21+
22+
@JsonInclude(JsonInclude.Include.NON_ABSENT)
23+
@JsonDeserialize(
24+
builder = DeleteDatasetItemResponse.Builder.class
25+
)
26+
public final class DeleteDatasetItemResponse {
27+
private final String message;
28+
29+
private final Map<String, Object> additionalProperties;
30+
31+
private DeleteDatasetItemResponse(String message, Map<String, Object> additionalProperties) {
32+
this.message = message;
33+
this.additionalProperties = additionalProperties;
34+
}
35+
36+
/**
37+
* @return Success message after deletion
38+
*/
39+
@JsonProperty("message")
40+
public String getMessage() {
41+
return message;
42+
}
43+
44+
@java.lang.Override
45+
public boolean equals(Object other) {
46+
if (this == other) return true;
47+
return other instanceof DeleteDatasetItemResponse && equalTo((DeleteDatasetItemResponse) other);
48+
}
49+
50+
@JsonAnyGetter
51+
public Map<String, Object> getAdditionalProperties() {
52+
return this.additionalProperties;
53+
}
54+
55+
private boolean equalTo(DeleteDatasetItemResponse other) {
56+
return message.equals(other.message);
57+
}
58+
59+
@java.lang.Override
60+
public int hashCode() {
61+
return Objects.hash(this.message);
62+
}
63+
64+
@java.lang.Override
65+
public String toString() {
66+
return ObjectMappers.stringify(this);
67+
}
68+
69+
public static MessageStage builder() {
70+
return new Builder();
71+
}
72+
73+
public interface MessageStage {
74+
_FinalStage message(@NotNull String message);
75+
76+
Builder from(DeleteDatasetItemResponse other);
77+
}
78+
79+
public interface _FinalStage {
80+
DeleteDatasetItemResponse build();
81+
}
82+
83+
@JsonIgnoreProperties(
84+
ignoreUnknown = true
85+
)
86+
public static final class Builder implements MessageStage, _FinalStage {
87+
private String message;
88+
89+
@JsonAnySetter
90+
private Map<String, Object> additionalProperties = new HashMap<>();
91+
92+
private Builder() {
93+
}
94+
95+
@java.lang.Override
96+
public Builder from(DeleteDatasetItemResponse other) {
97+
message(other.getMessage());
98+
return this;
99+
}
100+
101+
/**
102+
* <p>Success message after deletion</p>
103+
* @return Reference to {@code this} so that method calls can be chained together.
104+
*/
105+
@java.lang.Override
106+
@JsonSetter("message")
107+
public _FinalStage message(@NotNull String message) {
108+
this.message = Objects.requireNonNull(message, "message must not be null");
109+
return this;
110+
}
111+
112+
@java.lang.Override
113+
public DeleteDatasetItemResponse build() {
114+
return new DeleteDatasetItemResponse(message, additionalProperties);
115+
}
116+
}
117+
}

src/main/java/com/langfuse/client/resources/datasets/DatasetsClient.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.langfuse.client.resources.datasets.requests.GetDatasetRunsRequest;
3333
import com.langfuse.client.resources.datasets.requests.GetDatasetsRequest;
3434
import com.langfuse.client.resources.datasets.types.CreateDatasetRequest;
35+
import com.langfuse.client.resources.datasets.types.DeleteDatasetRunResponse;
3536
import com.langfuse.client.resources.datasets.types.PaginatedDatasetRuns;
3637
import com.langfuse.client.resources.datasets.types.PaginatedDatasets;
3738

@@ -269,6 +270,61 @@ public DatasetRunWithItems getRun(String datasetName, String runName,
269270
}
270271
}
271272

273+
/**
274+
* Delete a dataset run and all its run items. This action is irreversible.
275+
*/
276+
public DeleteDatasetRunResponse deleteRun(String datasetName, String runName) {
277+
return deleteRun(datasetName,runName,null);
278+
}
279+
280+
/**
281+
* Delete a dataset run and all its run items. This action is irreversible.
282+
*/
283+
public DeleteDatasetRunResponse deleteRun(String datasetName, String runName,
284+
RequestOptions requestOptions) {
285+
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder()
286+
.addPathSegments("api/public")
287+
.addPathSegments("datasets")
288+
.addPathSegment(datasetName)
289+
.addPathSegments("runs")
290+
.addPathSegment(runName)
291+
.build();
292+
Request okhttpRequest = new Request.Builder()
293+
.url(httpUrl)
294+
.method("DELETE", null)
295+
.headers(Headers.of(clientOptions.headers(requestOptions)))
296+
.addHeader("Content-Type", "application/json")
297+
.addHeader("Accept", "application/json")
298+
.build();
299+
OkHttpClient client = clientOptions.httpClient();
300+
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
301+
client = clientOptions.httpClientWithTimeout(requestOptions);
302+
}
303+
try (Response response = client.newCall(okhttpRequest).execute()) {
304+
ResponseBody responseBody = response.body();
305+
if (response.isSuccessful()) {
306+
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteDatasetRunResponse.class);
307+
}
308+
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
309+
try {
310+
switch (response.code()) {
311+
case 400:throw new Error(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
312+
case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
313+
case 403:throw new AccessDeniedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
314+
case 404:throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
315+
case 405:throw new MethodNotAllowedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
316+
}
317+
}
318+
catch (JsonProcessingException ignored) {
319+
// unable to map error response, throwing generic error
320+
}
321+
throw new LangfuseClientApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
322+
}
323+
catch (IOException e) {
324+
throw new LangfuseClientException("Network error executing HTTP request", e);
325+
}
326+
}
327+
272328
/**
273329
* Get dataset runs
274330
*/
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
package com.langfuse.client.resources.datasets.types;
6+
7+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
8+
import com.fasterxml.jackson.annotation.JsonAnySetter;
9+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
10+
import com.fasterxml.jackson.annotation.JsonInclude;
11+
import com.fasterxml.jackson.annotation.JsonProperty;
12+
import com.fasterxml.jackson.annotation.JsonSetter;
13+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
14+
import com.langfuse.client.core.ObjectMappers;
15+
import java.lang.Object;
16+
import java.lang.String;
17+
import java.util.HashMap;
18+
import java.util.Map;
19+
import java.util.Objects;
20+
import org.jetbrains.annotations.NotNull;
21+
22+
@JsonInclude(JsonInclude.Include.NON_ABSENT)
23+
@JsonDeserialize(
24+
builder = DeleteDatasetRunResponse.Builder.class
25+
)
26+
public final class DeleteDatasetRunResponse {
27+
private final String message;
28+
29+
private final Map<String, Object> additionalProperties;
30+
31+
private DeleteDatasetRunResponse(String message, Map<String, Object> additionalProperties) {
32+
this.message = message;
33+
this.additionalProperties = additionalProperties;
34+
}
35+
36+
@JsonProperty("message")
37+
public String getMessage() {
38+
return message;
39+
}
40+
41+
@java.lang.Override
42+
public boolean equals(Object other) {
43+
if (this == other) return true;
44+
return other instanceof DeleteDatasetRunResponse && equalTo((DeleteDatasetRunResponse) other);
45+
}
46+
47+
@JsonAnyGetter
48+
public Map<String, Object> getAdditionalProperties() {
49+
return this.additionalProperties;
50+
}
51+
52+
private boolean equalTo(DeleteDatasetRunResponse other) {
53+
return message.equals(other.message);
54+
}
55+
56+
@java.lang.Override
57+
public int hashCode() {
58+
return Objects.hash(this.message);
59+
}
60+
61+
@java.lang.Override
62+
public String toString() {
63+
return ObjectMappers.stringify(this);
64+
}
65+
66+
public static MessageStage builder() {
67+
return new Builder();
68+
}
69+
70+
public interface MessageStage {
71+
_FinalStage message(@NotNull String message);
72+
73+
Builder from(DeleteDatasetRunResponse other);
74+
}
75+
76+
public interface _FinalStage {
77+
DeleteDatasetRunResponse build();
78+
}
79+
80+
@JsonIgnoreProperties(
81+
ignoreUnknown = true
82+
)
83+
public static final class Builder implements MessageStage, _FinalStage {
84+
private String message;
85+
86+
@JsonAnySetter
87+
private Map<String, Object> additionalProperties = new HashMap<>();
88+
89+
private Builder() {
90+
}
91+
92+
@java.lang.Override
93+
public Builder from(DeleteDatasetRunResponse other) {
94+
message(other.getMessage());
95+
return this;
96+
}
97+
98+
@java.lang.Override
99+
@JsonSetter("message")
100+
public _FinalStage message(@NotNull String message) {
101+
this.message = Objects.requireNonNull(message, "message must not be null");
102+
return this;
103+
}
104+
105+
@java.lang.Override
106+
public DeleteDatasetRunResponse build() {
107+
return new DeleteDatasetRunResponse(message, additionalProperties);
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)
0