Skip to content

Commit

Permalink
feat: kotlin/java sdk docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alarv committed Nov 14, 2024
1 parent 8c23110 commit 6acad67
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 1 deletion.
76 changes: 76 additions & 0 deletions docusaurus/docs/jaqpot-api/SDKs/java-kotlin-sdk.md
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

2 changes: 1 addition & 1 deletion docusaurus/docs/jaqpot-api/SDKs/qsartoolbox-python-sdk.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: QSAR Toolbox Python SDK
sidebar_position: 2
sidebar_position: 3
---

The jaqpotpy SDK provides seamless access to QSAR Toolbox, a comprehensive software application designed for filling data gaps in toxicity data. Through the SDK, users can interact with three main components of QSAR Toolbox:
Expand Down
71 changes: 71 additions & 0 deletions docusaurus/docs/jaqpot-api/documentation/prediction-workflow.md
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
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
title: Swagger API Documentation
sidebar_position: 2
---
Browse our complete API documentation through Swagger UI. Here you'll find all available endpoints, request/response examples, and authentication details. The API follows REST principles and returns JSON responses.
Expand Down

0 comments on commit 6acad67

Please sign in to comment.