Skip to content

Commit 4cce23e

Browse files
chore(docs): update readme (#73)
1 parent fb49e1e commit 4cce23e

File tree

3 files changed

+57
-45
lines changed

3 files changed

+57
-45
lines changed

README.md

+50-38
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ 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+
5255
OpenlayerClient client = OpenlayerOkHttpClient.fromEnv();
5356

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

6972
### Example: creating a resource
7073

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.
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.
7375

7476
```java
77+
import com.openlayer.api.core.JsonValue;
7578
import com.openlayer.api.models.InferencePipelineDataStreamParams;
7679
import com.openlayer.api.models.InferencePipelineDataStreamResponse;
7780
import java.util.List;
@@ -85,7 +88,7 @@ InferencePipelineDataStreamParams params = InferencePipelineDataStreamParams.bui
8588
.costColumnName("cost")
8689
.timestampColumnName("timestamp")
8790
.build()))
88-
.row(List.of(InferencePipelineDataStreamParams.Row.builder()
91+
.rows(List.of(InferencePipelineDataStreamParams.Row.builder()
8992
.putAdditionalProperty("user_query", JsonValue.from("what is the meaning of life?"))
9093
.putAdditionalProperty("output", JsonValue.from("42"))
9194
.putAdditionalProperty("tokens", JsonValue.from(7))
@@ -104,14 +107,14 @@ InferencePipelineDataStreamResponse response = client.inferencePipelines().data(
104107

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

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.
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.
109111

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.
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.
112113

113114
```java
114-
import com.openlayer.api.models.core.JsonValue;
115+
import com.openlayer.api.core.JsonValue;
116+
import com.openlayer.api.models.InferencePipelineDataStreamParams;
117+
115118
InferencePipelineDataStreamParams params = InferencePipelineDataStreamParams.builder()
116119
// ... normal properties
117120
.putAdditionalProperty("secret_param", JsonValue.from("4242"))
@@ -125,15 +128,19 @@ InferencePipelineDataStreamParams params = InferencePipelineDataStreamParams.bui
125128
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.
126129

127130
```java
131+
import com.openlayer.api.models.InferencePipelineDataStreamResponse;
132+
128133
InferencePipelineDataStreamResponse response = client.inferencePipelines().data().stream().validate();
129134
```
130135

131136
### Response properties as JSON
132137

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.
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.
135139

136140
```java
141+
import com.openlayer.api.core.JsonField;
142+
import java.util.Optional;
143+
137144
JsonField field = responseObj._field();
138145

139146
if (field.isMissing()) {
@@ -155,6 +162,8 @@ if (field.isMissing()) {
155162
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:
156163

157164
```java
165+
import com.openlayer.api.core.JsonValue;
166+
158167
JsonValue secret = projectCreateResponse._additionalProperties().get("secret_field");
159168
```
160169

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

169178
- **`OpenlayerException`** - Base exception for all exceptions
170179

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.
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.
172181

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 |
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 |
182191

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)
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)
187196

188197
## Network options
189198

190199
### Retries
191200

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:
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:
194202

195203
```java
204+
import com.openlayer.api.client.OpenlayerClient;
205+
import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient;
206+
196207
OpenlayerClient client = OpenlayerOkHttpClient.builder()
197208
.fromEnv()
198209
.maxRetries(4)
@@ -204,6 +215,10 @@ OpenlayerClient client = OpenlayerOkHttpClient.builder()
204215
Requests time out after 1 minute by default. You can configure this on the client builder:
205216

206217
```java
218+
import com.openlayer.api.client.OpenlayerClient;
219+
import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient;
220+
import java.time.Duration;
221+
207222
OpenlayerClient client = OpenlayerOkHttpClient.builder()
208223
.fromEnv()
209224
.timeout(Duration.ofSeconds(30))
@@ -215,24 +230,24 @@ OpenlayerClient client = OpenlayerOkHttpClient.builder()
215230
Requests can be routed through a proxy. You can configure this on the client builder:
216231

217232
```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+
218238
OpenlayerClient client = OpenlayerOkHttpClient.builder()
219239
.fromEnv()
220-
.proxy(new Proxy(
221-
Type.HTTP,
222-
new InetSocketAddress("proxy.com", 8080)
223-
))
240+
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("example.com", 8080)))
224241
.build();
225242
```
226243

227244
## Making custom/undocumented requests
228245

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.
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.
231247

232248
### Undocumented request params
233249

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

237252
```kotlin
238253
FooCreateParams address = FooCreateParams.builder()
@@ -243,10 +258,7 @@ FooCreateParams address = FooCreateParams.builder()
243258

244259
### Undocumented response properties
245260

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.
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.
250262

251263
## Logging
252264

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

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

@@ -32,6 +32,7 @@ class InferencePipelineRowUpdateParamsTest {
3232
val params =
3333
InferencePipelineRowUpdateParams.builder()
3434
.inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
35+
.inferenceId("inferenceId")
3536
.row(JsonValue.from(mapOf<String, Any>()))
3637
.config(
3738
InferencePipelineRowUpdateParams.Config.builder()
@@ -42,7 +43,6 @@ class InferencePipelineRowUpdateParamsTest {
4243
.timestampColumnName("timestamp")
4344
.build()
4445
)
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-
.row(JsonValue.from(mapOf<String, Any>()))
5857
.inferenceId("inferenceId")
58+
.row(JsonValue.from(mapOf<String, Any>()))
5959
.build()
6060
val expected = QueryParams.builder()
6161
expected.put("inferenceId", "inferenceId")
@@ -67,6 +67,7 @@ class InferencePipelineRowUpdateParamsTest {
6767
val params =
6868
InferencePipelineRowUpdateParams.builder()
6969
.inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
70+
.inferenceId("inferenceId")
7071
.row(JsonValue.from(mapOf<String, Any>()))
7172
.config(
7273
InferencePipelineRowUpdateParams.Config.builder()
@@ -77,7 +78,6 @@ class InferencePipelineRowUpdateParamsTest {
7778
.timestampColumnName("timestamp")
7879
.build()
7980
)
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-
.row(JsonValue.from(mapOf<String, Any>()))
103102
.inferenceId("inferenceId")
103+
.row(JsonValue.from(mapOf<String, Any>()))
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-
.row(JsonValue.from(mapOf<String, Any>()))
116115
.inferenceId("inferenceId")
116+
.row(JsonValue.from(mapOf<String, Any>()))
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,6 +24,7 @@ class RowServiceTest {
2424
rowService.update(
2525
InferencePipelineRowUpdateParams.builder()
2626
.inferencePipelineId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
27+
.inferenceId("inferenceId")
2728
.row(JsonValue.from(mapOf<String, Any>()))
2829
.config(
2930
InferencePipelineRowUpdateParams.Config.builder()
@@ -34,7 +35,6 @@ class RowServiceTest {
3435
.timestampColumnName("timestamp")
3536
.build()
3637
)
37-
.inferenceId("inferenceId")
3838
.build()
3939
)
4040
println(inferencePipelineRowUpdateResponse)

0 commit comments

Comments
 (0)