Skip to content

Commit 682b82b

Browse files
committed
Fix AI model URL bug and update SDK documentation
- Fix aimodels.get_by_id() to use super().get() to avoid recursion - Update README.md with new authentication methods - Document AI model calling functionality - Add comprehensive API reference - Update Quick Start examples with Keycloak configuration
1 parent b0d2e1b commit 682b82b

File tree

4 files changed

+101
-21
lines changed

4 files changed

+101
-21
lines changed

dataspace_sdk/resources/aimodels.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def search(
6161
if sort:
6262
params["sort"] = sort
6363

64-
return self.get("/api/search/aimodel/", params=params)
64+
return super().get("/api/search/aimodel/", params=params)
6565

6666
def get_by_id(self, model_id: str) -> Dict[str, Any]:
6767
"""
@@ -73,7 +73,8 @@ def get_by_id(self, model_id: str) -> Dict[str, Any]:
7373
Returns:
7474
Dictionary containing AI model information
7575
"""
76-
return self.get(f"/api/aimodels/{model_id}/")
76+
# Use parent class get method with full endpoint path
77+
return super().get(f"/api/aimodels/{model_id}/")
7778

7879
def get_by_id_graphql(self, model_id: str) -> Dict[str, Any]:
7980
"""

dataspace_sdk/resources/datasets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def search(
5757
if sort:
5858
params["sort"] = sort
5959

60-
return self.get("/api/search/dataset/", params=params)
60+
return super().get("/api/search/dataset/", params=params)
6161

6262
def get_by_id(self, dataset_id: str) -> Dict[str, Any]:
6363
"""

dataspace_sdk/resources/usecases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def search(
5757
if sort:
5858
params["sort"] = sort
5959

60-
return self.get("/api/search/usecase/", params=params)
60+
return super().get("/api/search/usecase/", params=params)
6161

6262
def get_by_id(self, usecase_id: int) -> Dict[str, Any]:
6363
"""

docs/sdk/README.md

Lines changed: 96 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,20 @@ pip install -e ".[dev]"
2929
```python
3030
from dataspace_sdk import DataSpaceClient
3131

32-
# Initialize the client
33-
client = DataSpaceClient(base_url="https://api.dataspace.example.com")
32+
# Initialize the client with Keycloak configuration
33+
client = DataSpaceClient(
34+
base_url="https://dev.api.civicdataspace.in",
35+
keycloak_url="https://opub-kc.civicdatalab.in",
36+
keycloak_realm="DataSpace",
37+
keycloak_client_id="dataspace",
38+
keycloak_client_secret="your_client_secret"
39+
)
3440

35-
# Login with Keycloak token
36-
user_info = client.login(keycloak_token="your_keycloak_token")
41+
# Login with username and password
42+
user_info = client.login(
43+
username="[email protected]",
44+
password="your_password"
45+
)
3746
print(f"Logged in as: {user_info['user']['username']}")
3847

3948
# Search for datasets
@@ -49,36 +58,66 @@ dataset = client.datasets.get_by_id("dataset-uuid")
4958
print(f"Dataset: {dataset['title']}")
5059

5160
# Get organization's resources
52-
org_id = user_info['user']['organizations'][0]['id']
53-
org_datasets = client.datasets.get_organization_datasets(org_id)
61+
if user_info['user']['organizations']:
62+
org_id = user_info['user']['organizations'][0]['id']
63+
org_datasets = client.datasets.get_organization_datasets(org_id)
5464
```
5565

5666
## Features
5767

58-
- **Authentication**: Login with Keycloak tokens and automatic token refresh
68+
- **Authentication**: Multiple authentication methods (username/password, Keycloak token, service account)
69+
- **Automatic Token Management**: Automatic token refresh and re-login
5970
- **Datasets**: Search, retrieve, and list datasets with filtering and pagination
60-
- **AI Models**: Search, retrieve, and list AI models with filtering
71+
- **AI Models**: Search, retrieve, call, and list AI models with filtering
6172
- **Use Cases**: Search, retrieve, and list use cases with filtering
6273
- **Organization Resources**: Get resources specific to your organizations
6374
- **GraphQL & REST**: Supports both GraphQL and REST API endpoints
75+
- **Error Handling**: Comprehensive exception handling with detailed error messages
6476

6577
## Authentication
6678

67-
### Login with Keycloak
79+
The SDK supports three authentication methods:
80+
81+
### 1. Username and Password (Recommended for Users)
6882

6983
```python
7084
from dataspace_sdk import DataSpaceClient
7185

72-
client = DataSpaceClient(base_url="https://api.dataspace.example.com")
86+
client = DataSpaceClient(
87+
base_url="https://dev.api.civicdataspace.in",
88+
keycloak_url="https://opub-kc.civicdatalab.in",
89+
keycloak_realm="DataSpace",
90+
keycloak_client_id="dataspace",
91+
keycloak_client_secret="your_client_secret"
92+
)
7393

74-
# Login with Keycloak token
75-
response = client.login(keycloak_token="your_keycloak_token")
94+
# Login with username and password
95+
user_info = client.login(
96+
username="[email protected]",
97+
password="your_password"
98+
)
7699

77100
# Access user information
78-
print(response['user']['username'])
79-
print(response['user']['organizations'])
101+
print(user_info['user']['username'])
102+
print(user_info['user']['organizations'])
80103
```
81104

105+
### 2. Keycloak Token (For Token Pass-through)
106+
107+
```python
108+
# Login with an existing Keycloak token
109+
response = client.login_with_token(keycloak_token="your_keycloak_token")
110+
```
111+
112+
### 3. Service Account (For Backend Services)
113+
114+
```python
115+
# Login as a service account using client credentials
116+
service_info = client.login_as_service_account()
117+
```
118+
119+
For detailed authentication documentation, see [AUTHENTICATION_COMPLETE.md](./AUTHENTICATION_COMPLETE.md)
120+
82121
### Token Refresh
83122

84123
```python
@@ -203,6 +242,36 @@ print(f"Provider: {model['provider']}")
203242
print(f"Endpoints: {len(model['endpoints'])}")
204243
```
205244

245+
### Call an AI Model
246+
247+
```python
248+
# Call an AI model with input text
249+
result = client.aimodels.call_model(
250+
model_id="model-uuid",
251+
input_text="What is the capital of France?",
252+
parameters={
253+
"temperature": 0.7,
254+
"max_tokens": 100
255+
}
256+
)
257+
258+
if result['success']:
259+
print(f"Output: {result['output']}")
260+
print(f"Latency: {result['latency_ms']}ms")
261+
print(f"Provider: {result['provider']}")
262+
else:
263+
print(f"Error: {result['error']}")
264+
265+
# For long-running operations, use async call
266+
task = client.aimodels.call_model_async(
267+
model_id="model-uuid",
268+
input_text="Generate a long document...",
269+
parameters={"max_tokens": 2000}
270+
)
271+
print(f"Task ID: {task['task_id']}")
272+
print(f"Status: {task['status']}")
273+
```
274+
206275
### List All AI Models
207276

208277
```python
@@ -249,6 +318,7 @@ results = client.usecases.search(
249318
### Get Use Case by ID
250319

251320
```python
321+
# Get use case by ID
252322
usecase = client.usecases.get_by_id(123)
253323

254324
print(f"Title: {usecase['title']}")
@@ -375,7 +445,9 @@ Main client for interacting with DataSpace API.
375445

376446
**Methods:**
377447

378-
- `login(keycloak_token: str) -> dict`: Login with Keycloak token
448+
- `login(username: str, password: str) -> dict`: Login with username and password
449+
- `login_with_token(keycloak_token: str) -> dict`: Login with Keycloak token
450+
- `login_as_service_account() -> dict`: Login as service account (client credentials)
379451
- `refresh_token() -> str`: Refresh access token
380452
- `get_user_info() -> dict`: Get current user information
381453
- `is_authenticated() -> bool`: Check authentication status
@@ -395,10 +467,12 @@ Client for dataset operations.
395467
**Methods:**
396468

397469
- `search(...)`: Search datasets with filters
398-
- `get_by_id(dataset_id: str)`: Get dataset by UUID
470+
- `get_by_id(dataset_id: str)`: Get dataset by UUID (GraphQL)
399471
- `list_all(...)`: List all datasets with pagination
400472
- `get_trending(limit: int)`: Get trending datasets
401473
- `get_organization_datasets(organization_id: str, ...)`: Get organization's datasets
474+
- `get_resources(dataset_id: str)`: Get dataset resources
475+
- `list_by_organization(organization_id: str, ...)`: List datasets by organization
402476

403477
### AIModelClient
404478

@@ -409,8 +483,13 @@ Client for AI model operations.
409483
- `search(...)`: Search AI models with filters
410484
- `get_by_id(model_id: str)`: Get AI model by UUID (REST)
411485
- `get_by_id_graphql(model_id: str)`: Get AI model by UUID (GraphQL)
486+
- `call_model(model_id: str, input_text: str, parameters: dict)`: Call an AI model
487+
- `call_model_async(model_id: str, input_text: str, parameters: dict)`: Call an AI model asynchronously
412488
- `list_all(...)`: List all AI models with pagination
413489
- `get_organization_models(organization_id: str, ...)`: Get organization's AI models
490+
- `create(data: dict)`: Create a new AI model
491+
- `update(model_id: str, data: dict)`: Update an AI model
492+
- `delete_model(model_id: str)`: Delete an AI model
414493

415494
### UseCaseClient
416495

@@ -419,7 +498,7 @@ Client for use case operations.
419498
**Methods:**
420499

421500
- `search(...)`: Search use cases with filters
422-
- `get_by_id(usecase_id: int)`: Get use case by ID
501+
- `get_by_id(usecase_id: int)`: Get use case by ID (GraphQL)
423502
- `list_all(...)`: List all use cases with pagination
424503
- `get_organization_usecases(organization_id: str, ...)`: Get organization's use cases
425504

0 commit comments

Comments
 (0)