Skip to content

Commit 0fa0571

Browse files
committed
feat: added agentkit implimentation
1 parent 99588bd commit 0fa0571

4 files changed

Lines changed: 54 additions & 21 deletions

File tree

README.md

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Rapida Python SDK
22

3-
[![Build and Publish Python SDK](https://github.com/rapidaai/rapida-python/actions/workflows/python-build.yml/badge.svg?branch=main)](https://github.com/rapidaai/rapida-python/actions/workflows/build.yml)
3+
[![Build and Publish Python SDK](https://github.com/rapidaai/rapida-python/actions/workflows/python-build.yml/badge.svg?branch=main)](https://github.com/rapidaai/rapida-python/actions/workflows/python-build.yml)
44

55
The Rapida Python SDK provides a powerful interface for interacting with Rapida AI services. This SDK simplifies the process of making API calls, handling authentication, and managing responses from Rapida endpoints.
66

@@ -17,18 +17,13 @@ pip install rapida-python
1717
Here's how to get started with the Rapida Python SDK:
1818

1919
```python
20-
from rapida import (
21-
ConnectionConfig,
22-
)
23-
from pprint import pprint
24-
20+
from rapida import ConnectionConfig
2521

2622
connection_config = ConnectionConfig.default_connection_config(
2723
ConnectionConfig.with_sdk(
28-
"{your-api-key-here}" # Replace with your actual API key
24+
"{your-api-key-here}"
2925
)
3026
)
31-
3227
```
3328

3429
## Authentication
@@ -40,8 +35,11 @@ You can configure the Rapida SDK to authenticate using your **API Key** or **Per
4035
```python
4136
import os
4237
from rapida.connections import ConnectionConfig
43-
connection_config = ConnectionConfig.with_sdk(
44-
os.environ["RAPIDA_API_KEY"] # API Key from environment variables
38+
39+
connection_config = ConnectionConfig.default_connection_config(
40+
ConnectionConfig.with_sdk(
41+
os.environ["RAPIDA_API_KEY"] # API Key from environment variables
42+
)
4543
)
4644
```
4745

@@ -51,25 +49,46 @@ connection_config = ConnectionConfig.with_sdk(
5149
import os
5250
from rapida.connections import ConnectionConfig
5351

54-
connection_config = ConnectionConfig.with_personal_token(
55-
os.environ["RAPIDA_AUTHORIZATION_TOKEN"], # Authorization Token
56-
os.environ["RAPIDA_AUTH_ID"], # Authentication ID
57-
os.environ["RAPIDA_PROJECT_ID"], # Project ID
52+
connection_config = ConnectionConfig.default_connection_config(
53+
ConnectionConfig.with_personal_token(
54+
os.environ["RAPIDA_AUTHORIZATION_TOKEN"], # Authorization Token
55+
os.environ["RAPIDA_AUTH_ID"], # Authentication ID
56+
os.environ["RAPIDA_PROJECT_ID"], # Project ID
57+
)
5858
)
5959
```
6060

6161
## Configuration Options
6262

63-
The `DefaultConnectionConfig` accepts multiple options for configuring the SDK. Key options include:
63+
`ConnectionConfig` accepts multiple options for configuring the SDK:
6464

6565
- `with_sdk(api_key: str)`: Sets the API key for authentication.
6666
- `with_personal_token(auth_token: str, auth_id: str, project_id: str)`: Configures the connection for personal tokens.
67-
- `with_endpoint_url(url: str)`: Overrides the default API endpoint URL.
68-
- `with_timeout(timeout: float)`: Sets the timeout for API requests (in seconds).
67+
- `with_webplugin_client(api_key: str, user_id: Optional[str] = None)`: Configures web plugin client authentication.
68+
- `with_debugger(authorization: str, user_id: str, project_id: str)`: Configures debugger authentication.
69+
- `with_custom_endpoint(endpoint: Optional[dict] = None, debug: Optional[bool] = None)`: Overrides the default assistant, web, and endpoint API hosts.
70+
- `with_local()`: Uses local service endpoints and insecure gRPC channels for local development.
71+
- `default_connection_config(auth)`: Creates a `ConnectionConfig` with the supplied auth metadata.
72+
73+
Example using custom endpoints:
74+
75+
```python
76+
from rapida import ConnectionConfig
77+
78+
connection_config = ConnectionConfig.default_connection_config(
79+
ConnectionConfig.with_sdk("{your-api-key-here}")
80+
).with_custom_endpoint(
81+
{
82+
"assistant": "assistant.example.com:50051",
83+
"web": "api.example.com:50051",
84+
"endpoint": "endpoint.example.com:50051",
85+
}
86+
)
87+
```
6988

7089
## Compatibility
7190

72-
This SDK requires **Python 3.8 or later**. Ensure your system meets this requirement:
91+
This SDK requires **Python 3.9 or later**. Ensure your system meets this requirement:
7392

7493
```bash
7594
python --version

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "rapida-python"
7-
version = "0.1.28"
7+
version = "0.1.29"
88
description = "RapidaAI SDK to integrate rapida.ai APIs"
99
readme = "README.md"
1010
authors = [{name = "RapidaAI", email = "code@rapida.ai"}]

rapida/agentkit/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,13 @@ def intercept_service(self, continuation, handler_call_details):
171171
return continuation(handler_call_details)
172172

173173
def _abort_handler(self):
174-
def abort(ignored_request, context):
174+
def abort(ignored_request_iterator, context):
175175
context.abort(
176176
grpc.StatusCode.UNAUTHENTICATED, "Invalid authorization token"
177177
)
178+
return iter(())
178179

179-
return grpc.unary_unary_rpc_method_handler(abort)
180+
return grpc.stream_stream_rpc_method_handler(abort)
180181

181182

182183
# ============================================================================
@@ -658,6 +659,7 @@ def stop(self, grace: Optional[int] = 5) -> None:
658659
if self._server:
659660
logger.info(f"Stopping server (grace={grace}s)...")
660661
self._server.stop(grace)
662+
self._server = None
661663
logger.info("Server stopped")
662664

663665
def wait_for_termination(self, timeout: Optional[float] = None) -> bool:

tests/agentkit/test_agentkit.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,12 @@ def test_abort_handler_is_not_none(self):
895895
handler = interceptor._abort_handler()
896896
assert handler is not None
897897

898+
def test_abort_handler_is_stream_stream_compatible(self):
899+
interceptor = AuthorizationInterceptor(AuthConfig(enabled=True, token="t"))
900+
handler = interceptor._abort_handler()
901+
assert handler.request_streaming is True
902+
assert handler.response_streaming is True
903+
898904

899905
# ============================================================================
900906
# AgentKitServer
@@ -1123,6 +1129,12 @@ def test_stop_with_default_grace(self):
11231129
server.stop()
11241130
mock_grpc_server.stop.assert_called_once_with(5)
11251131

1132+
def test_stop_marks_server_not_running(self):
1133+
server = self._make_server()
1134+
server._server = MagicMock()
1135+
server.stop()
1136+
assert server.is_running is False
1137+
11261138
def test_stop_noop_when_server_never_started(self):
11271139
server = self._make_server()
11281140
# Must not raise

0 commit comments

Comments
 (0)