-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
title: Kotlin/Java SDK | ||
sidebar_position: 2 | ||
--- | ||
|
||
# Kotlin/Java SDK | ||
|
||
The SDK lets you use Jaqpot models and predictions in your Java or Kotlin applications. | ||
|
||
## Get your API Keys | ||
You'll need an API key and secret from your Jaqpot account. Create them by following the [API keys guide](../authentication/create-an-api-key). | ||
|
||
**The API keys are valid for 6 months from their generation date. Please store these keys securely, as they cannot be retrieved from Jaqpot after initial generation. If your keys are lost or expired, you will need to generate new ones by following the same steps above.** | ||
|
||
## Add to your project | ||
|
||
Maven central page: https://central.sonatype.com/artifact/org.jaqpot/kotlin-sdk | ||
|
||
For Gradle (Kotlin DSL): | ||
```kotlin | ||
implementation("org.jaqpot:kotlin-sdk:0.4.0") // or the latest version of the SDK | ||
``` | ||
For Maven: | ||
```xml | ||
<dependency> | ||
<groupId>org.jaqpot</groupId> | ||
<artifactId>kotlin-sdk</artifactId> | ||
<version>0.4.0</version> | ||
</dependency> | ||
``` | ||
## Basic usage | ||
Make predictions in Java: | ||
```kotlin | ||
JaqpotApiClient jaqpotApiClient = | ||
new JaqpotApiClient(System.getenv("JAQPOT_API_KEY"), System.getenv("JAQPOT_API_SECRET")); | ||
Dataset dataset = jaqpotApiClient | ||
.predictSync( | ||
modelId, | ||
List.of( | ||
Map.of("X1", "1", "X2", "2", "X3", "3", "X4", "4") | ||
) | ||
); | ||
System.out.println(dataset) | ||
``` | ||
|
||
or in Kotlin: | ||
```kotlin | ||
val jaqpotApiClient = | ||
JaqpotApiClient(System.getenv("JAQPOT_API_KEY"), System.getenv("JAQPOT_API_SECRET")) | ||
val dataset = jaqpotApiClient.predictSync( | ||
modelId, | ||
listOf( | ||
mapOf("X1" to "1", "X2" to "2", "X3" to "3", "X4" to "4") | ||
) | ||
) | ||
println(dataset) | ||
``` | ||
## Setting API Keys | ||
Use environment variables: | ||
```bash | ||
export JAQPOT_API_KEY=your_key_here | ||
export JAQPOT_API_SECRET=your_secret_here | ||
``` | ||
Or pass them directly to the client: | ||
```kotlin | ||
val client = JaqpotApiClient("your-key", "your-secret") | ||
``` | ||
|
||
## Error handling | ||
The SDK throws JaqpotSDKException on errors like: | ||
|
||
- Wrong API credentials | ||
- Model not found | ||
- Failed predictions | ||
- Network issues | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
docusaurus/docs/jaqpot-api/documentation/prediction-workflow.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
title: Prediction Workflow | ||
sidebar_position: 3 | ||
--- | ||
|
||
# Prediction Workflow | ||
|
||
When making predictions with Jaqpot models, the process is asynchronous. Here's how it works: | ||
|
||
## Steps | ||
|
||
1. Send prediction request | ||
```bash | ||
POST /model/{id}/predict | ||
``` | ||
2. Get dataset ID from response header | ||
```Location: /dataset/123456``` | ||
|
||
3. Query dataset status until complete | ||
```bash | ||
GET /dataset/123456 | ||
``` | ||
The dataset will be in one of these states: | ||
|
||
- EXECUTING: Waiting to be processed | ||
- SUCCESS: Prediction completed successfully | ||
- FAILURE: Prediction failed | ||
|
||
|
||
## Example Flow | ||
```python | ||
# 1. Make prediction request | ||
response = POST /model/42/predict | ||
dataset_id = get_id_from_location_header(response.headers["Location"]) | ||
|
||
# 2. Poll dataset until complete | ||
retries = 0 | ||
while retries < 10: | ||
dataset = GET /dataset/{dataset_id} | ||
|
||
if dataset.status in ["SUCCESS", "FAILURE"]: | ||
break | ||
|
||
# Wait 2 seconds before next check | ||
sleep(2) | ||
retries += 1 | ||
|
||
# 3. Handle result | ||
if dataset.status == "SUCCESS": | ||
predictions = dataset.predictions | ||
else: | ||
handle_error(dataset.error) | ||
``` | ||
### Notes | ||
- Maximum recommended polling attempts: 10 | ||
- Recommended interval between checks: 2 seconds | ||
- Location header format: /dataset/{id} | ||
I- f polling exceeds maximum attempts, consider the prediction failed | ||
|
||
### Common Errors | ||
|
||
- Dataset not found: Invalid dataset ID | ||
- Maximum retries exceeded: Prediction taking too long | ||
- Dataset in FAILURE state: Check error message in dataset response | ||
|
||
## SDK Implementation | ||
All official Jaqpot SDKs handle this polling mechanism automatically. For example using the Java/Kotlin SDK: | ||
```kotlin | ||
val client = JaqpotApiClient(apiKey, apiSecret) | ||
val result = client.predictSync(modelId, input) // Handles polling internally | ||
``` |
1 change: 1 addition & 0 deletions
1
.../docs/jaqpot-api/documentation/Swagger.md → .../docs/jaqpot-api/documentation/swagger.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters