|
25 | 25 | import com.langfuse.client.resources.annotationqueues.requests.GetAnnotationQueueItemsRequest; |
26 | 26 | import com.langfuse.client.resources.annotationqueues.requests.GetAnnotationQueuesRequest; |
27 | 27 | import com.langfuse.client.resources.annotationqueues.types.AnnotationQueue; |
| 28 | +import com.langfuse.client.resources.annotationqueues.types.AnnotationQueueAssignmentRequest; |
28 | 29 | import com.langfuse.client.resources.annotationqueues.types.AnnotationQueueItem; |
| 30 | +import com.langfuse.client.resources.annotationqueues.types.CreateAnnotationQueueAssignmentResponse; |
29 | 31 | import com.langfuse.client.resources.annotationqueues.types.CreateAnnotationQueueItemRequest; |
| 32 | +import com.langfuse.client.resources.annotationqueues.types.CreateAnnotationQueueRequest; |
| 33 | +import com.langfuse.client.resources.annotationqueues.types.DeleteAnnotationQueueAssignmentResponse; |
30 | 34 | import com.langfuse.client.resources.annotationqueues.types.DeleteAnnotationQueueItemResponse; |
31 | 35 | import com.langfuse.client.resources.annotationqueues.types.PaginatedAnnotationQueueItems; |
32 | 36 | import com.langfuse.client.resources.annotationqueues.types.PaginatedAnnotationQueues; |
@@ -107,6 +111,65 @@ public PaginatedAnnotationQueues listQueues(GetAnnotationQueuesRequest request, |
107 | 111 | } |
108 | 112 | } |
109 | 113 |
|
| 114 | + /** |
| 115 | + * Create an annotation queue |
| 116 | + */ |
| 117 | + public AnnotationQueue createQueue(CreateAnnotationQueueRequest request) { |
| 118 | + return createQueue(request,null); |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * Create an annotation queue |
| 123 | + */ |
| 124 | + public AnnotationQueue createQueue(CreateAnnotationQueueRequest request, |
| 125 | + RequestOptions requestOptions) { |
| 126 | + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder() |
| 127 | + .addPathSegments("api/public") |
| 128 | + .addPathSegments("annotation-queues") |
| 129 | + .build(); |
| 130 | + RequestBody body; |
| 131 | + try { |
| 132 | + body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); |
| 133 | + } |
| 134 | + catch(JsonProcessingException e) { |
| 135 | + throw new LangfuseClientException("Failed to serialize request", e); |
| 136 | + } |
| 137 | + Request okhttpRequest = new Request.Builder() |
| 138 | + .url(httpUrl) |
| 139 | + .method("POST", body) |
| 140 | + .headers(Headers.of(clientOptions.headers(requestOptions))) |
| 141 | + .addHeader("Content-Type", "application/json") |
| 142 | + .addHeader("Accept", "application/json") |
| 143 | + .build(); |
| 144 | + OkHttpClient client = clientOptions.httpClient(); |
| 145 | + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { |
| 146 | + client = clientOptions.httpClientWithTimeout(requestOptions); |
| 147 | + } |
| 148 | + try (Response response = client.newCall(okhttpRequest).execute()) { |
| 149 | + ResponseBody responseBody = response.body(); |
| 150 | + if (response.isSuccessful()) { |
| 151 | + return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AnnotationQueue.class); |
| 152 | + } |
| 153 | + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; |
| 154 | + try { |
| 155 | + switch (response.code()) { |
| 156 | + case 400:throw new Error(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 157 | + case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 158 | + case 403:throw new AccessDeniedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 159 | + case 404:throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 160 | + case 405:throw new MethodNotAllowedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 161 | + } |
| 162 | + } |
| 163 | + catch (JsonProcessingException ignored) { |
| 164 | + // unable to map error response, throwing generic error |
| 165 | + } |
| 166 | + throw new LangfuseClientApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 167 | + } |
| 168 | + catch (IOException e) { |
| 169 | + throw new LangfuseClientException("Network error executing HTTP request", e); |
| 170 | + } |
| 171 | + } |
| 172 | + |
110 | 173 | /** |
111 | 174 | * Get an annotation queue by ID |
112 | 175 | */ |
@@ -469,4 +532,128 @@ public DeleteAnnotationQueueItemResponse deleteQueueItem(String queueId, String |
469 | 532 | throw new LangfuseClientException("Network error executing HTTP request", e); |
470 | 533 | } |
471 | 534 | } |
| 535 | + |
| 536 | + /** |
| 537 | + * Create an assignment for a user to an annotation queue |
| 538 | + */ |
| 539 | + public CreateAnnotationQueueAssignmentResponse createQueueAssignment(String queueId, |
| 540 | + AnnotationQueueAssignmentRequest request) { |
| 541 | + return createQueueAssignment(queueId,request,null); |
| 542 | + } |
| 543 | + |
| 544 | + /** |
| 545 | + * Create an assignment for a user to an annotation queue |
| 546 | + */ |
| 547 | + public CreateAnnotationQueueAssignmentResponse createQueueAssignment(String queueId, |
| 548 | + AnnotationQueueAssignmentRequest request, RequestOptions requestOptions) { |
| 549 | + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder() |
| 550 | + .addPathSegments("api/public") |
| 551 | + .addPathSegments("annotation-queues") |
| 552 | + .addPathSegment(queueId) |
| 553 | + .addPathSegments("assignments") |
| 554 | + .build(); |
| 555 | + RequestBody body; |
| 556 | + try { |
| 557 | + body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); |
| 558 | + } |
| 559 | + catch(JsonProcessingException e) { |
| 560 | + throw new LangfuseClientException("Failed to serialize request", e); |
| 561 | + } |
| 562 | + Request okhttpRequest = new Request.Builder() |
| 563 | + .url(httpUrl) |
| 564 | + .method("POST", body) |
| 565 | + .headers(Headers.of(clientOptions.headers(requestOptions))) |
| 566 | + .addHeader("Content-Type", "application/json") |
| 567 | + .addHeader("Accept", "application/json") |
| 568 | + .build(); |
| 569 | + OkHttpClient client = clientOptions.httpClient(); |
| 570 | + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { |
| 571 | + client = clientOptions.httpClientWithTimeout(requestOptions); |
| 572 | + } |
| 573 | + try (Response response = client.newCall(okhttpRequest).execute()) { |
| 574 | + ResponseBody responseBody = response.body(); |
| 575 | + if (response.isSuccessful()) { |
| 576 | + return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateAnnotationQueueAssignmentResponse.class); |
| 577 | + } |
| 578 | + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; |
| 579 | + try { |
| 580 | + switch (response.code()) { |
| 581 | + case 400:throw new Error(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 582 | + case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 583 | + case 403:throw new AccessDeniedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 584 | + case 404:throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 585 | + case 405:throw new MethodNotAllowedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 586 | + } |
| 587 | + } |
| 588 | + catch (JsonProcessingException ignored) { |
| 589 | + // unable to map error response, throwing generic error |
| 590 | + } |
| 591 | + throw new LangfuseClientApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 592 | + } |
| 593 | + catch (IOException e) { |
| 594 | + throw new LangfuseClientException("Network error executing HTTP request", e); |
| 595 | + } |
| 596 | + } |
| 597 | + |
| 598 | + /** |
| 599 | + * Delete an assignment for a user to an annotation queue |
| 600 | + */ |
| 601 | + public DeleteAnnotationQueueAssignmentResponse deleteQueueAssignment(String queueId, |
| 602 | + AnnotationQueueAssignmentRequest request) { |
| 603 | + return deleteQueueAssignment(queueId,request,null); |
| 604 | + } |
| 605 | + |
| 606 | + /** |
| 607 | + * Delete an assignment for a user to an annotation queue |
| 608 | + */ |
| 609 | + public DeleteAnnotationQueueAssignmentResponse deleteQueueAssignment(String queueId, |
| 610 | + AnnotationQueueAssignmentRequest request, RequestOptions requestOptions) { |
| 611 | + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()).newBuilder() |
| 612 | + .addPathSegments("api/public") |
| 613 | + .addPathSegments("annotation-queues") |
| 614 | + .addPathSegment(queueId) |
| 615 | + .addPathSegments("assignments") |
| 616 | + .build(); |
| 617 | + RequestBody body; |
| 618 | + try { |
| 619 | + body = RequestBody.create(ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); |
| 620 | + } |
| 621 | + catch(JsonProcessingException e) { |
| 622 | + throw new LangfuseClientException("Failed to serialize request", e); |
| 623 | + } |
| 624 | + Request okhttpRequest = new Request.Builder() |
| 625 | + .url(httpUrl) |
| 626 | + .method("DELETE", body) |
| 627 | + .headers(Headers.of(clientOptions.headers(requestOptions))) |
| 628 | + .addHeader("Content-Type", "application/json") |
| 629 | + .addHeader("Accept", "application/json") |
| 630 | + .build(); |
| 631 | + OkHttpClient client = clientOptions.httpClient(); |
| 632 | + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { |
| 633 | + client = clientOptions.httpClientWithTimeout(requestOptions); |
| 634 | + } |
| 635 | + try (Response response = client.newCall(okhttpRequest).execute()) { |
| 636 | + ResponseBody responseBody = response.body(); |
| 637 | + if (response.isSuccessful()) { |
| 638 | + return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteAnnotationQueueAssignmentResponse.class); |
| 639 | + } |
| 640 | + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; |
| 641 | + try { |
| 642 | + switch (response.code()) { |
| 643 | + case 400:throw new Error(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 644 | + case 401:throw new UnauthorizedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 645 | + case 403:throw new AccessDeniedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 646 | + case 404:throw new NotFoundError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 647 | + case 405:throw new MethodNotAllowedError(ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 648 | + } |
| 649 | + } |
| 650 | + catch (JsonProcessingException ignored) { |
| 651 | + // unable to map error response, throwing generic error |
| 652 | + } |
| 653 | + throw new LangfuseClientApiException("Error with status code " + response.code(), response.code(), ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); |
| 654 | + } |
| 655 | + catch (IOException e) { |
| 656 | + throw new LangfuseClientException("Network error executing HTTP request", e); |
| 657 | + } |
| 658 | + } |
472 | 659 | } |
0 commit comments