Skip to content

Commit f32b8fe

Browse files
chore(internal): codegen related update (#74)
1 parent e4abac7 commit f32b8fe

File tree

3 files changed

+45
-57
lines changed

3 files changed

+45
-57
lines changed

README.md

+38-50
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ Use `OpenlayerOkHttpClient.builder()` to configure the client.
4949
Alternately, set the environment with `OPENLAYER_API_KEY`, and use `OpenlayerOkHttpClient.fromEnv()` to read from the environment.
5050

5151
```java
52-
import com.openlayer.api.client.OpenlayerClient;
53-
import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient;
54-
5552
OpenlayerClient client = OpenlayerOkHttpClient.fromEnv();
5653

5754
// Note: you can also call fromEnv() from the client builder, for example if you need to set additional properties
@@ -71,10 +68,10 @@ Read the documentation for more configuration options.
7168

7269
### Example: creating a resource
7370

74-
To create a new inference pipeline data, first use the `InferencePipelineDataStreamParams` builder to specify attributes, then pass that to the `stream` method of the `data` service.
71+
To create a new inference pipeline data, first use the `InferencePipelineDataStreamParams` builder to specify attributes,
72+
then pass that to the `stream` method of the `data` service.
7573

7674
```java
77-
import com.openlayer.api.core.JsonValue;
7875
import com.openlayer.api.models.InferencePipelineDataStreamParams;
7976
import com.openlayer.api.models.InferencePipelineDataStreamResponse;
8077
import java.util.List;
@@ -88,7 +85,7 @@ InferencePipelineDataStreamParams params = InferencePipelineDataStreamParams.bui
8885
.costColumnName("cost")
8986
.timestampColumnName("timestamp")
9087
.build()))
91-
.rows(List.of(InferencePipelineDataStreamParams.Row.builder()
88+
.row(List.of(InferencePipelineDataStreamParams.Row.builder()
9289
.putAdditionalProperty("user_query", JsonValue.from("what is the meaning of life?"))
9390
.putAdditionalProperty("output", JsonValue.from("42"))
9491
.putAdditionalProperty("tokens", JsonValue.from(7))
@@ -107,14 +104,14 @@ InferencePipelineDataStreamResponse response = client.inferencePipelines().data(
107104

108105
To make a request to the Openlayer API, you generally build an instance of the appropriate `Params` class.
109106

110-
In [Example: creating a resource](#example-creating-a-resource) above, we used the `InferencePipelineDataStreamParams.builder()` to pass to the `stream` method of the `data` service.
107+
In [Example: creating a resource](#example-creating-a-resource) above, we used the `InferencePipelineDataStreamParams.builder()` to pass to
108+
the `stream` method of the `data` service.
111109

112-
Sometimes, the API may support other properties that are not yet supported in the Java SDK types. In that case, you can attach them using the `putAdditionalProperty` method.
110+
Sometimes, the API may support other properties that are not yet supported in the Java SDK types. In that case,
111+
you can attach them using the `putAdditionalProperty` method.
113112

114113
```java
115-
import com.openlayer.api.core.JsonValue;
116-
import com.openlayer.api.models.InferencePipelineDataStreamParams;
117-
114+
import com.openlayer.api.models.core.JsonValue;
118115
InferencePipelineDataStreamParams params = InferencePipelineDataStreamParams.builder()
119116
// ... normal properties
120117
.putAdditionalProperty("secret_param", JsonValue.from("4242"))
@@ -128,19 +125,15 @@ InferencePipelineDataStreamParams params = InferencePipelineDataStreamParams.bui
128125
When receiving a response, the Openlayer Java SDK will deserialize it into instances of the typed model classes. In rare cases, the API may return a response property that doesn't match the expected Java type. If you directly access the mistaken property, the SDK will throw an unchecked `OpenlayerInvalidDataException` at runtime. If you would prefer to check in advance that that response is completely well-typed, call `.validate()` on the returned model.
129126

130127
```java
131-
import com.openlayer.api.models.InferencePipelineDataStreamResponse;
132-
133128
InferencePipelineDataStreamResponse response = client.inferencePipelines().data().stream().validate();
134129
```
135130

136131
### Response properties as JSON
137132

138-
In rare cases, you may want to access the underlying JSON value for a response property rather than using the typed version provided by this SDK. Each model property has a corresponding JSON version, with an underscore before the method name, which returns a `JsonField` value.
133+
In rare cases, you may want to access the underlying JSON value for a response property rather than using the typed version provided by
134+
this SDK. Each model property has a corresponding JSON version, with an underscore before the method name, which returns a `JsonField` value.
139135

140136
```java
141-
import com.openlayer.api.core.JsonField;
142-
import java.util.Optional;
143-
144137
JsonField field = responseObj._field();
145138

146139
if (field.isMissing()) {
@@ -162,8 +155,6 @@ if (field.isMissing()) {
162155
Sometimes, the server response may include additional properties that are not yet available in this library's types. You can access them using the model's `_additionalProperties` method:
163156

164157
```java
165-
import com.openlayer.api.core.JsonValue;
166-
167158
JsonValue secret = projectCreateResponse._additionalProperties().get("secret_field");
168159
```
169160

@@ -177,33 +168,31 @@ This library throws exceptions in a single hierarchy for easy handling:
177168

178169
- **`OpenlayerException`** - Base exception for all exceptions
179170

180-
- **`OpenlayerServiceException`** - HTTP errors with a well-formed response body we were able to parse. The exception message and the `.debuggingRequestId()` will be set by the server.
171+
- **`OpenlayerServiceException`** - HTTP errors with a well-formed response body we were able to parse. The exception message and the `.debuggingRequestId()` will be set by the server.
181172

182-
| 400 | BadRequestException |
183-
| ------ | ----------------------------- |
184-
| 401 | AuthenticationException |
185-
| 403 | PermissionDeniedException |
186-
| 404 | NotFoundException |
187-
| 422 | UnprocessableEntityException |
188-
| 429 | RateLimitException |
189-
| 5xx | InternalServerException |
190-
| others | UnexpectedStatusCodeException |
173+
| 400 | BadRequestException |
174+
| ------ | ----------------------------- |
175+
| 401 | AuthenticationException |
176+
| 403 | PermissionDeniedException |
177+
| 404 | NotFoundException |
178+
| 422 | UnprocessableEntityException |
179+
| 429 | RateLimitException |
180+
| 5xx | InternalServerException |
181+
| others | UnexpectedStatusCodeException |
191182

192-
- **`OpenlayerIoException`** - I/O networking errors
193-
- **`OpenlayerInvalidDataException`** - any other exceptions on the client side, e.g.:
194-
- We failed to serialize the request body
195-
- We failed to parse the response body (has access to response code and body)
183+
- **`OpenlayerIoException`** - I/O networking errors
184+
- **`OpenlayerInvalidDataException`** - any other exceptions on the client side, e.g.:
185+
- We failed to serialize the request body
186+
- We failed to parse the response body (has access to response code and body)
196187

197188
## Network options
198189

199190
### Retries
200191

201-
Requests that experience certain errors are automatically retried 2 times by default, with a short exponential backoff. Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors will all be retried by default. You can provide a `maxRetries` on the client builder to configure this:
192+
Requests that experience certain errors are automatically retried 2 times by default, with a short exponential backoff. Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors will all be retried by default.
193+
You can provide a `maxRetries` on the client builder to configure this:
202194

203195
```java
204-
import com.openlayer.api.client.OpenlayerClient;
205-
import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient;
206-
207196
OpenlayerClient client = OpenlayerOkHttpClient.builder()
208197
.fromEnv()
209198
.maxRetries(4)
@@ -215,10 +204,6 @@ OpenlayerClient client = OpenlayerOkHttpClient.builder()
215204
Requests time out after 1 minute by default. You can configure this on the client builder:
216205

217206
```java
218-
import com.openlayer.api.client.OpenlayerClient;
219-
import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient;
220-
import java.time.Duration;
221-
222207
OpenlayerClient client = OpenlayerOkHttpClient.builder()
223208
.fromEnv()
224209
.timeout(Duration.ofSeconds(30))
@@ -230,24 +215,24 @@ OpenlayerClient client = OpenlayerOkHttpClient.builder()
230215
Requests can be routed through a proxy. You can configure this on the client builder:
231216

232217
```java
233-
import com.openlayer.api.client.OpenlayerClient;
234-
import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient;
235-
import java.net.InetSocketAddress;
236-
import java.net.Proxy;
237-
238218
OpenlayerClient client = OpenlayerOkHttpClient.builder()
239219
.fromEnv()
240-
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("example.com", 8080)))
220+
.proxy(new Proxy(
221+
Type.HTTP,
222+
new InetSocketAddress("proxy.com", 8080)
223+
))
241224
.build();
242225
```
243226

244227
## Making custom/undocumented requests
245228

246-
This library is typed for convenient access to the documented API. If you need to access undocumented params or response properties, the library can still be used.
229+
This library is typed for convenient access to the documented API. If you need to access undocumented
230+
params or response properties, the library can still be used.
247231

248232
### Undocumented request params
249233

250-
To make requests using undocumented parameters, you can provide or override parameters on the params object while building it.
234+
To make requests using undocumented parameters, you can provide or override parameters on the params object
235+
while building it.
251236

252237
```kotlin
253238
FooCreateParams address = FooCreateParams.builder()
@@ -258,7 +243,10 @@ FooCreateParams address = FooCreateParams.builder()
258243

259244
### Undocumented response properties
260245

261-
To access undocumented response properties, you can use `res._additionalProperties()` on a response object to get a map of untyped fields of type `Map<String, JsonValue>`. You can then access fields like `._additionalProperties().get("secret_prop").asString()` or use other helpers defined on the `JsonValue` class to extract it to a desired type.
246+
To access undocumented response properties, you can use `res._additionalProperties()` on a response object to
247+
get a map of untyped fields of type `Map<String, JsonValue>`. You can then access fields like
248+
`._additionalProperties().get("secret_prop").asString()` or use other helpers defined on the `JsonValue` class
249+
to extract it to a desired type.
262250

263251
## Logging
264252

openlayer-java-core/src/test/kotlin/com/openlayer/api/models/InferencePipelineRowUpdateParamsTest.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class InferencePipelineRowUpdateParamsTest {
1313
fun createInferencePipelineRowUpdateParams() {
1414
InferencePipelineRowUpdateParams.builder()
1515
.inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
16-
.inferenceId("inferenceId")
1716
.row(JsonValue.from(mapOf<String, Any>()))
1817
.config(
1918
InferencePipelineRowUpdateParams.Config.builder()
@@ -24,6 +23,7 @@ class InferencePipelineRowUpdateParamsTest {
2423
.timestampColumnName("timestamp")
2524
.build()
2625
)
26+
.inferenceId("inferenceId")
2727
.build()
2828
}
2929

@@ -32,7 +32,6 @@ class InferencePipelineRowUpdateParamsTest {
3232
val params =
3333
InferencePipelineRowUpdateParams.builder()
3434
.inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
35-
.inferenceId("inferenceId")
3635
.row(JsonValue.from(mapOf<String, Any>()))
3736
.config(
3837
InferencePipelineRowUpdateParams.Config.builder()
@@ -43,6 +42,7 @@ class InferencePipelineRowUpdateParamsTest {
4342
.timestampColumnName("timestamp")
4443
.build()
4544
)
45+
.inferenceId("inferenceId")
4646
.build()
4747
val expected = QueryParams.builder()
4848
expected.put("inferenceId", "inferenceId")
@@ -54,8 +54,8 @@ class InferencePipelineRowUpdateParamsTest {
5454
val params =
5555
InferencePipelineRowUpdateParams.builder()
5656
.inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
57-
.inferenceId("inferenceId")
5857
.row(JsonValue.from(mapOf<String, Any>()))
58+
.inferenceId("inferenceId")
5959
.build()
6060
val expected = QueryParams.builder()
6161
expected.put("inferenceId", "inferenceId")
@@ -67,7 +67,6 @@ class InferencePipelineRowUpdateParamsTest {
6767
val params =
6868
InferencePipelineRowUpdateParams.builder()
6969
.inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
70-
.inferenceId("inferenceId")
7170
.row(JsonValue.from(mapOf<String, Any>()))
7271
.config(
7372
InferencePipelineRowUpdateParams.Config.builder()
@@ -78,6 +77,7 @@ class InferencePipelineRowUpdateParamsTest {
7877
.timestampColumnName("timestamp")
7978
.build()
8079
)
80+
.inferenceId("inferenceId")
8181
.build()
8282
val body = params.getBody()
8383
assertThat(body).isNotNull
@@ -99,8 +99,8 @@ class InferencePipelineRowUpdateParamsTest {
9999
val params =
100100
InferencePipelineRowUpdateParams.builder()
101101
.inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
102-
.inferenceId("inferenceId")
103102
.row(JsonValue.from(mapOf<String, Any>()))
103+
.inferenceId("inferenceId")
104104
.build()
105105
val body = params.getBody()
106106
assertThat(body).isNotNull
@@ -112,8 +112,8 @@ class InferencePipelineRowUpdateParamsTest {
112112
val params =
113113
InferencePipelineRowUpdateParams.builder()
114114
.inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
115-
.inferenceId("inferenceId")
116115
.row(JsonValue.from(mapOf<String, Any>()))
116+
.inferenceId("inferenceId")
117117
.build()
118118
assertThat(params).isNotNull
119119
// path param "inferencePipelineId"

openlayer-java-core/src/test/kotlin/com/openlayer/api/services/blocking/inferencePipelines/RowServiceTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class RowServiceTest {
2424
rowService.update(
2525
InferencePipelineRowUpdateParams.builder()
2626
.inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
27-
.inferenceId("inferenceId")
2827
.row(JsonValue.from(mapOf<String, Any>()))
2928
.config(
3029
InferencePipelineRowUpdateParams.Config.builder()
@@ -35,6 +34,7 @@ class RowServiceTest {
3534
.timestampColumnName("timestamp")
3635
.build()
3736
)
37+
.inferenceId("inferenceId")
3838
.build()
3939
)
4040
println(inferencePipelineRowUpdateResponse)

0 commit comments

Comments
 (0)