codemie-sdk-python 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of codemie-sdk-python might be problematic. Click here for more details.
- codemie_sdk_python-0.1.1/LICENSE +19 -0
- codemie_sdk_python-0.1.1/PKG-INFO +120 -0
- codemie_sdk_python-0.1.1/README.md +105 -0
- codemie_sdk_python-0.1.1/pyproject.toml +22 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/__init__.py +23 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/auth/__init__.py +5 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/auth/credentials.py +112 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/client/__init__.py +5 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/client/client.py +107 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/exceptions.py +45 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/models/assistant.py +192 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/models/common.py +39 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/models/datasource.py +293 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/models/integration.py +68 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/models/llm.py +48 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/models/task.py +44 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/models/user.py +50 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/models/workflow.py +86 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/services/assistant.py +173 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/services/datasource.py +150 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/services/integration.py +152 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/services/llm.py +38 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/services/task.py +34 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/services/user.py +34 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/services/workflow.py +144 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/services/workflow_execution.py +102 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/utils/__init__.py +5 -0
- codemie_sdk_python-0.1.1/src/codemie_sdk/utils/http.py +226 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2018 The Python Packaging Authority
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: codemie-sdk-python
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: CodeMie SDK for Python
|
|
5
|
+
Author: Vadym Vlasenko
|
|
6
|
+
Author-email: vadym_vlasenko@epam.com
|
|
7
|
+
Requires-Python: >=3.12,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Requires-Dist: pydantic (>=2.6.1,<3.0.0)
|
|
11
|
+
Requires-Dist: pytest-cov (>=6.0.0,<7.0.0)
|
|
12
|
+
Requires-Dist: requests (>=2.31.0,<3.0.0)
|
|
13
|
+
Requires-Dist: ruff (>=0.11.0,<0.12.0)
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# CodeMie Python SDK
|
|
17
|
+
|
|
18
|
+
Python SDK for CodeMie services
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
pip install codemie-sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Basic usage
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from codemie_sdk import CodeMieClient
|
|
33
|
+
|
|
34
|
+
# Initialize client with authentication parameters
|
|
35
|
+
client = CodeMieClient(
|
|
36
|
+
auth_server_url="https://keycloak.example.com",
|
|
37
|
+
auth_client_id="your-client-id",
|
|
38
|
+
auth_client_secret="your-client-secret",
|
|
39
|
+
auth_realm_name="your-realm",
|
|
40
|
+
codemie_api_domain="https://codemie-preview.lab.epam.com/code-assistant-api"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Create a new workflow
|
|
44
|
+
workflow = client.workflow.create('project-id', 'workflow-name', {'param': 'value'}, token=client.token)
|
|
45
|
+
|
|
46
|
+
# Execute tool
|
|
47
|
+
tool_result = client.tool.execute(
|
|
48
|
+
tool_name='my-tool',
|
|
49
|
+
project='project-id',
|
|
50
|
+
tool_args={'param': 'value'},
|
|
51
|
+
token=client.token
|
|
52
|
+
)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Tool Operations
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
# List available tools
|
|
59
|
+
tools = client.tool.list(token=client.token)
|
|
60
|
+
|
|
61
|
+
# Get tool schema
|
|
62
|
+
schema = client.tool.schema('tool-name', token=client.token)
|
|
63
|
+
|
|
64
|
+
# Execute tool with optional parameters
|
|
65
|
+
result = client.tool.execute(
|
|
66
|
+
tool_name='my-tool',
|
|
67
|
+
project='project-id',
|
|
68
|
+
tool_args={'param': 'value'},
|
|
69
|
+
token=client.token,
|
|
70
|
+
llm_model='gpt-4', # optional
|
|
71
|
+
tool_attributes={'attr': 'value'}, # optional
|
|
72
|
+
tool_creds={'cred': 'secret'}, # optional
|
|
73
|
+
datasource_id='ds-123', # optional
|
|
74
|
+
params={'retry_count': 3} # optional
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Workflow Operations
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
# Create workflow
|
|
82
|
+
workflow = client.workflow.create('project-id', 'workflow-name', {'param': 'value'}, token=client.token)
|
|
83
|
+
|
|
84
|
+
# Get workflow status
|
|
85
|
+
status = client.workflow.status('workflow-id', token=client.token)
|
|
86
|
+
|
|
87
|
+
# List workflows
|
|
88
|
+
workflows = client.workflow.list('project-id', token=client.token)
|
|
89
|
+
|
|
90
|
+
# Get workflow result
|
|
91
|
+
result = client.workflow.result('workflow-id', token=client.token)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Development
|
|
95
|
+
|
|
96
|
+
### Setup
|
|
97
|
+
|
|
98
|
+
1. Create and activate virtual environment:
|
|
99
|
+
```sh
|
|
100
|
+
python -m venv venv
|
|
101
|
+
source venv/bin/activate # Linux/MacOS
|
|
102
|
+
venv\Scripts\activate # Windows
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
2. Install dependencies:
|
|
106
|
+
```sh
|
|
107
|
+
pip install -r requirements.txt
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Running Tests
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
make test
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Building Package
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
make build
|
|
120
|
+
```
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# CodeMie Python SDK
|
|
2
|
+
|
|
3
|
+
Python SDK for CodeMie services
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pip install codemie-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
### Basic usage
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from codemie_sdk import CodeMieClient
|
|
18
|
+
|
|
19
|
+
# Initialize client with authentication parameters
|
|
20
|
+
client = CodeMieClient(
|
|
21
|
+
auth_server_url="https://keycloak.example.com",
|
|
22
|
+
auth_client_id="your-client-id",
|
|
23
|
+
auth_client_secret="your-client-secret",
|
|
24
|
+
auth_realm_name="your-realm",
|
|
25
|
+
codemie_api_domain="https://codemie-preview.lab.epam.com/code-assistant-api"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
# Create a new workflow
|
|
29
|
+
workflow = client.workflow.create('project-id', 'workflow-name', {'param': 'value'}, token=client.token)
|
|
30
|
+
|
|
31
|
+
# Execute tool
|
|
32
|
+
tool_result = client.tool.execute(
|
|
33
|
+
tool_name='my-tool',
|
|
34
|
+
project='project-id',
|
|
35
|
+
tool_args={'param': 'value'},
|
|
36
|
+
token=client.token
|
|
37
|
+
)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Tool Operations
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
# List available tools
|
|
44
|
+
tools = client.tool.list(token=client.token)
|
|
45
|
+
|
|
46
|
+
# Get tool schema
|
|
47
|
+
schema = client.tool.schema('tool-name', token=client.token)
|
|
48
|
+
|
|
49
|
+
# Execute tool with optional parameters
|
|
50
|
+
result = client.tool.execute(
|
|
51
|
+
tool_name='my-tool',
|
|
52
|
+
project='project-id',
|
|
53
|
+
tool_args={'param': 'value'},
|
|
54
|
+
token=client.token,
|
|
55
|
+
llm_model='gpt-4', # optional
|
|
56
|
+
tool_attributes={'attr': 'value'}, # optional
|
|
57
|
+
tool_creds={'cred': 'secret'}, # optional
|
|
58
|
+
datasource_id='ds-123', # optional
|
|
59
|
+
params={'retry_count': 3} # optional
|
|
60
|
+
)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Workflow Operations
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
# Create workflow
|
|
67
|
+
workflow = client.workflow.create('project-id', 'workflow-name', {'param': 'value'}, token=client.token)
|
|
68
|
+
|
|
69
|
+
# Get workflow status
|
|
70
|
+
status = client.workflow.status('workflow-id', token=client.token)
|
|
71
|
+
|
|
72
|
+
# List workflows
|
|
73
|
+
workflows = client.workflow.list('project-id', token=client.token)
|
|
74
|
+
|
|
75
|
+
# Get workflow result
|
|
76
|
+
result = client.workflow.result('workflow-id', token=client.token)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Development
|
|
80
|
+
|
|
81
|
+
### Setup
|
|
82
|
+
|
|
83
|
+
1. Create and activate virtual environment:
|
|
84
|
+
```sh
|
|
85
|
+
python -m venv venv
|
|
86
|
+
source venv/bin/activate # Linux/MacOS
|
|
87
|
+
venv\Scripts\activate # Windows
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
2. Install dependencies:
|
|
91
|
+
```sh
|
|
92
|
+
pip install -r requirements.txt
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Running Tests
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
make test
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Building Package
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
make build
|
|
105
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "codemie-sdk-python"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
description = "CodeMie SDK for Python"
|
|
5
|
+
authors = [
|
|
6
|
+
"Vadym Vlasenko <vadym_vlasenko@epam.com>",
|
|
7
|
+
]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
packages = [
|
|
10
|
+
{ include = "codemie_sdk", from = "src" }
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[tool.poetry.dependencies]
|
|
14
|
+
python = "^3.12"
|
|
15
|
+
requests = "^2.31.0"
|
|
16
|
+
pydantic = "^2.6.1"
|
|
17
|
+
ruff = "^0.11.0"
|
|
18
|
+
pytest-cov = "^6.0.0"
|
|
19
|
+
|
|
20
|
+
[build-system]
|
|
21
|
+
requires = ["poetry-core"]
|
|
22
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CodeMie SDK for Python
|
|
3
|
+
~~~~~~~~~~~~~~~~~~~~~
|
|
4
|
+
|
|
5
|
+
A Python SDK for interacting with CodeMie API.
|
|
6
|
+
|
|
7
|
+
Basic usage:
|
|
8
|
+
|
|
9
|
+
>>> from codemie_sdk import CodeMieClient
|
|
10
|
+
>>> client = CodeMieClient(
|
|
11
|
+
... auth_server_url="https://auth.example.com",
|
|
12
|
+
... auth_client_id="client_id",
|
|
13
|
+
... auth_client_secret="secret",
|
|
14
|
+
... auth_realm_name="realm",
|
|
15
|
+
... codemie_api_domain="api.codemie.com"
|
|
16
|
+
... )
|
|
17
|
+
>>> assistants = client.assistants.list()
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from .client.client import CodeMieClient
|
|
21
|
+
|
|
22
|
+
__version__ = "0.1.11"
|
|
23
|
+
__all__ = ["CodeMieClient"]
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Authentication credentials module for CodeMie SDK."""
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class KeycloakCredentials:
|
|
8
|
+
"""Keycloak authentication credentials handler."""
|
|
9
|
+
|
|
10
|
+
def __init__(
|
|
11
|
+
self,
|
|
12
|
+
server_url: str,
|
|
13
|
+
realm_name: str,
|
|
14
|
+
client_id: Optional[str] = None,
|
|
15
|
+
client_secret: Optional[str] = None,
|
|
16
|
+
username: Optional[str] = None,
|
|
17
|
+
password: Optional[str] = None,
|
|
18
|
+
verify_ssl: bool = True,
|
|
19
|
+
):
|
|
20
|
+
"""Initialize Keycloak credentials.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
server_url: Keycloak server URL
|
|
24
|
+
realm_name: Realm name
|
|
25
|
+
client_id: Client ID (optional if using username/password)
|
|
26
|
+
client_secret: Client secret (optional if using username/password)
|
|
27
|
+
username: Username/email for password grant (optional)
|
|
28
|
+
password: Password for password grant (optional)
|
|
29
|
+
verify_ssl: Whether to verify SSL certificates (default: True)
|
|
30
|
+
"""
|
|
31
|
+
self.server_url = server_url.rstrip("/")
|
|
32
|
+
self.realm_name = realm_name
|
|
33
|
+
self.client_id = client_id
|
|
34
|
+
self.client_secret = client_secret
|
|
35
|
+
self.username = username
|
|
36
|
+
self.password = password
|
|
37
|
+
self.verify_ssl = verify_ssl
|
|
38
|
+
|
|
39
|
+
if not ((client_id and client_secret) or (username and password)):
|
|
40
|
+
raise ValueError(
|
|
41
|
+
"Either client credentials (client_id, client_secret) or "
|
|
42
|
+
"user credentials (username, password) must be provided"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
def get_token(self) -> str:
|
|
46
|
+
"""Get access token using either client credentials or password grant."""
|
|
47
|
+
url = (
|
|
48
|
+
f"{self.server_url}/realms/{self.realm_name}/protocol/openid-connect/token"
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
if self.username and self.password:
|
|
52
|
+
# Use Resource Owner Password Credentials flow
|
|
53
|
+
payload = {
|
|
54
|
+
"grant_type": "password",
|
|
55
|
+
"username": self.username,
|
|
56
|
+
"password": self.password,
|
|
57
|
+
"client_id": self.client_id
|
|
58
|
+
or "codemie-sdk", # Use default client if not specified
|
|
59
|
+
}
|
|
60
|
+
if self.client_secret:
|
|
61
|
+
payload["client_secret"] = self.client_secret
|
|
62
|
+
else:
|
|
63
|
+
# Use Client Credentials flow
|
|
64
|
+
payload = {
|
|
65
|
+
"grant_type": "client_credentials",
|
|
66
|
+
"client_id": self.client_id,
|
|
67
|
+
"client_secret": self.client_secret,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
response = requests.post(url, data=payload, verify=self.verify_ssl)
|
|
71
|
+
response.raise_for_status()
|
|
72
|
+
return response.json()["access_token"]
|
|
73
|
+
|
|
74
|
+
def exchange_token_for_user(self, email: str, access_token: str) -> str:
|
|
75
|
+
"""Exchange service account token for user token."""
|
|
76
|
+
user_id = self.find_user_by_email(email, access_token)
|
|
77
|
+
return self._exchange_token_for_user(user_id, access_token)
|
|
78
|
+
|
|
79
|
+
def find_user_by_email(self, email: str, access_token: str) -> str:
|
|
80
|
+
"""Find user ID by email."""
|
|
81
|
+
url = f"{self.server_url}/admin/realms/{self.realm_name}/users?email={email}"
|
|
82
|
+
headers = {
|
|
83
|
+
"Authorization": f"Bearer {access_token}",
|
|
84
|
+
"Content-Type": "application/json",
|
|
85
|
+
}
|
|
86
|
+
response = requests.get(url, headers=headers, verify=self.verify_ssl)
|
|
87
|
+
response.raise_for_status()
|
|
88
|
+
|
|
89
|
+
users = response.json()
|
|
90
|
+
if not users:
|
|
91
|
+
raise ValueError(f"User with email {email} not found")
|
|
92
|
+
return users[0]["id"]
|
|
93
|
+
|
|
94
|
+
def _exchange_token_for_user(self, user_id: str, service_account_token: str) -> str:
|
|
95
|
+
"""Exchange token for specific user."""
|
|
96
|
+
url = (
|
|
97
|
+
f"{self.server_url}/realms/{self.realm_name}/protocol/openid-connect/token"
|
|
98
|
+
)
|
|
99
|
+
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
|
100
|
+
payload = {
|
|
101
|
+
"client_id": self.client_id,
|
|
102
|
+
"client_secret": self.client_secret,
|
|
103
|
+
"grant_type": "urn:ietf:params:oauth:grant-datasource_type:token-exchange",
|
|
104
|
+
"subject_token": service_account_token,
|
|
105
|
+
"requested_subject": user_id,
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
response = requests.post(
|
|
109
|
+
url, headers=headers, data=payload, verify=self.verify_ssl
|
|
110
|
+
)
|
|
111
|
+
response.raise_for_status()
|
|
112
|
+
return response.json()["access_token"]
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Base client implementation for CodeMie SDK."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from ..auth.credentials import KeycloakCredentials
|
|
6
|
+
from ..services.assistant import AssistantService
|
|
7
|
+
from ..services.datasource import DatasourceService
|
|
8
|
+
from ..services.llm import LLMService
|
|
9
|
+
from ..services.integration import IntegrationService
|
|
10
|
+
from ..services.task import TaskService
|
|
11
|
+
from ..services.user import UserService
|
|
12
|
+
from ..services.workflow import WorkflowService
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CodeMieClient:
|
|
16
|
+
"""Main client class for interacting with CodeMie API."""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
auth_server_url: str,
|
|
21
|
+
auth_realm_name: str,
|
|
22
|
+
codemie_api_domain: str,
|
|
23
|
+
auth_client_id: Optional[str] = None,
|
|
24
|
+
auth_client_secret: Optional[str] = None,
|
|
25
|
+
username: Optional[str] = None,
|
|
26
|
+
password: Optional[str] = None,
|
|
27
|
+
verify_ssl: bool = True,
|
|
28
|
+
):
|
|
29
|
+
"""Initialize CodeMie client with authentication credentials.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
auth_server_url: Keycloak server URL
|
|
33
|
+
auth_realm_name: Realm name for authentication
|
|
34
|
+
codemie_api_domain: CodeMie API domain
|
|
35
|
+
auth_client_id: Client ID for authentication (optional if using username/password)
|
|
36
|
+
auth_client_secret: Client secret for authentication (optional if using username/password)
|
|
37
|
+
username: Username/email for password grant (optional if using client credentials)
|
|
38
|
+
password: Password for password grant (optional if using client credentials)
|
|
39
|
+
verify_ssl: Whether to verify SSL certificates (default: True)
|
|
40
|
+
"""
|
|
41
|
+
self.auth = KeycloakCredentials(
|
|
42
|
+
server_url=auth_server_url,
|
|
43
|
+
realm_name=auth_realm_name,
|
|
44
|
+
client_id=auth_client_id,
|
|
45
|
+
client_secret=auth_client_secret,
|
|
46
|
+
username=username,
|
|
47
|
+
password=password,
|
|
48
|
+
verify_ssl=verify_ssl,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
self._token: Optional[str] = None
|
|
52
|
+
self._api_domain = codemie_api_domain.rstrip("/")
|
|
53
|
+
self._verify_ssl = verify_ssl
|
|
54
|
+
|
|
55
|
+
# Initialize token first
|
|
56
|
+
self._token = self.auth.get_token()
|
|
57
|
+
|
|
58
|
+
# Initialize services with verify_ssl parameter and token
|
|
59
|
+
self.assistants = AssistantService(
|
|
60
|
+
self._api_domain, self._token, verify_ssl=verify_ssl
|
|
61
|
+
)
|
|
62
|
+
self.llms = LLMService(self._api_domain, self._token, verify_ssl=verify_ssl)
|
|
63
|
+
self.integrations = IntegrationService(
|
|
64
|
+
self._api_domain, self._token, verify_ssl=verify_ssl
|
|
65
|
+
)
|
|
66
|
+
self.tasks = TaskService(self._api_domain, self._token, verify_ssl=verify_ssl)
|
|
67
|
+
self.users = UserService(self._api_domain, self._token, verify_ssl=verify_ssl)
|
|
68
|
+
self.datasources = DatasourceService(
|
|
69
|
+
self._api_domain, self._token, verify_ssl=verify_ssl
|
|
70
|
+
)
|
|
71
|
+
self.workflows = WorkflowService(
|
|
72
|
+
self._api_domain, self._token, verify_ssl=self._verify_ssl
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def token(self) -> str:
|
|
77
|
+
"""Get current token or fetch new one if not available."""
|
|
78
|
+
if not self._token:
|
|
79
|
+
self._token = self.auth.get_token()
|
|
80
|
+
return self._token
|
|
81
|
+
|
|
82
|
+
def refresh_token(self) -> str:
|
|
83
|
+
"""Force token refresh."""
|
|
84
|
+
self._token = self.auth.get_token()
|
|
85
|
+
# Update token in services
|
|
86
|
+
self.assistants = AssistantService(
|
|
87
|
+
self._api_domain, self._token, verify_ssl=self._verify_ssl
|
|
88
|
+
)
|
|
89
|
+
self.llms = LLMService(
|
|
90
|
+
self._api_domain, self._token, verify_ssl=self._verify_ssl
|
|
91
|
+
)
|
|
92
|
+
self.integrations = IntegrationService(
|
|
93
|
+
self._api_domain, self._token, verify_ssl=self._verify_ssl
|
|
94
|
+
)
|
|
95
|
+
self.tasks = TaskService(
|
|
96
|
+
self._api_domain, self._token, verify_ssl=self._verify_ssl
|
|
97
|
+
)
|
|
98
|
+
self.users = UserService(
|
|
99
|
+
self._api_domain, self._token, verify_ssl=self._verify_ssl
|
|
100
|
+
)
|
|
101
|
+
self.datasources = DatasourceService(
|
|
102
|
+
self._api_domain, self._token, verify_ssl=self._verify_ssl
|
|
103
|
+
)
|
|
104
|
+
self.workflows = WorkflowService(
|
|
105
|
+
self._api_domain, self._token, verify_ssl=self._verify_ssl
|
|
106
|
+
)
|
|
107
|
+
return self._token
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Custom exceptions for the CodeMie SDK."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CodeMieError(Exception):
|
|
7
|
+
"""Base exception for all CodeMie SDK errors."""
|
|
8
|
+
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ApiError(CodeMieError):
|
|
13
|
+
"""Exception raised for API errors."""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
message: str,
|
|
18
|
+
status_code: Optional[int] = None,
|
|
19
|
+
response: Optional[dict] = None,
|
|
20
|
+
):
|
|
21
|
+
"""Initialize API error.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
message: Error message
|
|
25
|
+
status_code: HTTP status code if applicable
|
|
26
|
+
response: Raw API response if available
|
|
27
|
+
"""
|
|
28
|
+
self.status_code = status_code
|
|
29
|
+
self.response = response
|
|
30
|
+
super().__init__(message)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class NotFoundError(ApiError):
|
|
34
|
+
"""Exception raised when a resource is not found."""
|
|
35
|
+
|
|
36
|
+
def __init__(self, resource_type: str, resource_id: str):
|
|
37
|
+
"""Initialize not found error.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
resource_type: Type of resource that was not found (e.g., "Integration")
|
|
41
|
+
resource_id: ID or identifier of the resource
|
|
42
|
+
"""
|
|
43
|
+
super().__init__(
|
|
44
|
+
message=f"{resource_type} with {resource_id} not found", status_code=404
|
|
45
|
+
)
|