rapida-python 0.1.1a0__py3-none-any.whl → 0.1.3a0__py3-none-any.whl

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.
@@ -22,32 +22,35 @@
22
22
 
23
23
 
24
24
  import logging
25
- from typing import AsyncIterator, Dict, List, Optional, Mapping
25
+ from typing import AsyncIterator, Dict, List, Optional, Mapping, Iterable
26
26
  from google.protobuf.json_format import ParseDict
27
27
  from google.protobuf.any_pb2 import Any
28
28
  from google.protobuf.struct_pb2 import Struct
29
+
29
30
  from rapida.client.response_wrapper import InvokeResponseWrapper
30
31
  from rapida.artifacts.protos import (
31
32
  common_pb2,
32
33
  integration_api_pb2,
33
34
  integration_api_pb2_grpc,
34
35
  invoker_api_pb2,
35
- invoker_api_pb2_grpc,
36
+ invoker_api_pb2_grpc, talk_api_pb2_grpc,
37
+ talk_api_pb2
36
38
  )
37
39
  from rapida.client.grpc_bridge import GRPCBridge
40
+ from rapida.values import StringValue
38
41
 
39
42
  _log = logging.getLogger("rapida.client.rapida_bridge")
40
43
 
41
44
 
42
45
  class RapidaBridge(GRPCBridge):
43
46
  def __init__(
44
- self,
45
- service_url: str,
46
- rapida_api_key: str,
47
- rapida_region: str,
48
- rapida_environment: str,
49
- rapida_source: str,
50
- rapida_is_secure: bool,
47
+ self,
48
+ service_url: str,
49
+ rapida_api_key: str,
50
+ rapida_region: str,
51
+ rapida_environment: str,
52
+ rapida_source: str,
53
+ rapida_is_secure: bool,
51
54
  ):
52
55
  """
53
56
 
@@ -67,12 +70,12 @@ class RapidaBridge(GRPCBridge):
67
70
  )
68
71
 
69
72
  async def make_invoke_call(
70
- self,
71
- endpoint_id: int,
72
- version: str,
73
- body_params: Mapping[str, Any],
74
- metadata: Optional[Dict[str, str]],
75
- override_options: Optional[Dict[str, str]],
73
+ self,
74
+ endpoint_id: int,
75
+ version: str,
76
+ body_params: Mapping[str, Any],
77
+ metadata: Optional[Dict[str, str]],
78
+ override_options: Optional[Dict[str, str]],
76
79
  ) -> InvokeResponseWrapper:
77
80
  """
78
81
  Endpoint request to the rapida api endpoint servers
@@ -105,7 +108,7 @@ class RapidaBridge(GRPCBridge):
105
108
  )
106
109
 
107
110
  async def make_probe_call(
108
- self, rapida_audit_id: int
111
+ self, rapida_audit_id: int
109
112
  ) -> invoker_api_pb2.ProbeResponse:
110
113
  """
111
114
  To get details about the request for given request id
@@ -126,7 +129,7 @@ class RapidaBridge(GRPCBridge):
126
129
  )
127
130
 
128
131
  async def make_update_call(
129
- self, rapida_audit_id: int, rapida_metadata: Optional[Dict[str, str]]
132
+ self, rapida_audit_id: int, rapida_metadata: Optional[Dict[str, str]]
130
133
  ) -> invoker_api_pb2.UpdateResponse:
131
134
  """
132
135
  Provide an interface to update the metadata for executed request
@@ -152,15 +155,15 @@ class RapidaBridge(GRPCBridge):
152
155
  response, invoker_api_pb2.UpdateResponse(), ignore_unknown_fields=True
153
156
  )
154
157
 
155
- async def chat(
156
- self,
157
- cred: Dict,
158
- provider: str,
159
- model: str,
160
- conversations: List[common_pb2.Message],
161
- tool_definitions: List[integration_api_pb2.ToolDefinition],
162
- model_parameters: List[integration_api_pb2.ModelParameter],
163
- meta: Mapping[str, str] = None,
158
+ async def make_chat_call(
159
+ self,
160
+ cred: Dict,
161
+ provider: str,
162
+ model: str,
163
+ conversations: List[common_pb2.Message],
164
+ tool_definitions: List[integration_api_pb2.ToolDefinition],
165
+ model_parameters: List[integration_api_pb2.ModelParameter],
166
+ meta: Mapping[str, str] = None,
164
167
  ) -> integration_api_pb2.ChatResponse:
165
168
  """
166
169
  Asynchronously initiates a chat interaction with the Rapida service.
@@ -216,15 +219,15 @@ class RapidaBridge(GRPCBridge):
216
219
  response, integration_api_pb2.ChatResponse(), ignore_unknown_fields=True
217
220
  )
218
221
 
219
- async def generate(
220
- self,
221
- cred: Dict,
222
- provider: str,
223
- model: str,
224
- system_prompt: str,
225
- prompt: str,
226
- model_parameters: Mapping[str, str] = None,
227
- meta: Mapping[str, str] = None,
222
+ async def make_generate_call(
223
+ self,
224
+ cred: Dict,
225
+ provider: str,
226
+ model: str,
227
+ system_prompt: str,
228
+ prompt: str,
229
+ model_parameters: Mapping[str, str] = None,
230
+ meta: Mapping[str, str] = None,
228
231
  ) -> integration_api_pb2.GenerateResponse:
229
232
  """
230
233
  Prepares and sends a generation request to the Rapida service.
@@ -278,14 +281,14 @@ class RapidaBridge(GRPCBridge):
278
281
  response, integration_api_pb2.GenerateResponse(), ignore_unknown_fields=True
279
282
  )
280
283
 
281
- async def embedding(
282
- self,
283
- cred: Dict,
284
- provider: str,
285
- model: str,
286
- contents: List[str],
287
- model_parameters: Mapping[str, str] = None,
288
- meta: Mapping[str, str] = None,
284
+ async def make_embedding_call(
285
+ self,
286
+ cred: Dict,
287
+ provider: str,
288
+ model: str,
289
+ contents: List[str],
290
+ model_parameters: Mapping[str, str] = None,
291
+ meta: Mapping[str, str] = None,
289
292
  ) -> integration_api_pb2.EmbeddingResponse:
290
293
 
291
294
  credentials = Struct()
@@ -297,7 +300,7 @@ class RapidaBridge(GRPCBridge):
297
300
  args.append(
298
301
  integration_api_pb2.ModelParameter(
299
302
  key=k,
300
- value=v,
303
+ value=StringValue(v),
301
304
  )
302
305
  )
303
306
 
@@ -324,15 +327,15 @@ class RapidaBridge(GRPCBridge):
324
327
  ignore_unknown_fields=True,
325
328
  )
326
329
 
327
- async def chat_stream(
328
- self,
329
- cred: Dict,
330
- provider: str,
331
- model: str,
332
- conversations: List[common_pb2.Message],
333
- tool_definitions: List[integration_api_pb2.ToolDefinition],
334
- model_parameters: List[integration_api_pb2.ModelParameter],
335
- meta: Mapping[str, str] = None,
330
+ async def make_chat_stream(
331
+ self,
332
+ cred: Dict,
333
+ provider: str,
334
+ model: str,
335
+ conversations: List[common_pb2.Message],
336
+ tool_definitions: List[integration_api_pb2.ToolDefinition],
337
+ model_parameters: List[integration_api_pb2.ModelParameter],
338
+ meta: Mapping[str, str] = None,
336
339
  ) -> AsyncIterator[integration_api_pb2.ChatResponse]:
337
340
  """
338
341
  Asynchronously initiates a chat interaction with the Rapida service and streams the responses.
@@ -372,18 +375,77 @@ class RapidaBridge(GRPCBridge):
372
375
 
373
376
  # Stream the chat response from the gRPC server
374
377
  async for response in self.fetch_stream(
375
- stub=integration_api_pb2_grpc.RapidaServiceStub,
376
- attr="StreamChat",
377
- message_type=integration_api_pb2.ChatRequest(
378
- credential=integration_api_pb2.Credential(value=credentials),
379
- model=f"{provider}/{model}",
380
- conversations=conversations,
381
- toolDefinitions=tool_definitions,
382
- modelParameters=model_parameters,
383
- additionalData=meta,
384
- ),
385
- preserving_proto_field_name=True,
378
+ stub=integration_api_pb2_grpc.RapidaServiceStub,
379
+ attr="StreamChat",
380
+ message_type=integration_api_pb2.ChatRequest(
381
+ credential=integration_api_pb2.Credential(value=credentials),
382
+ model=f"{provider}/{model}",
383
+ conversations=conversations,
384
+ toolDefinitions=tool_definitions,
385
+ modelParameters=model_parameters,
386
+ additionalData=meta,
387
+ ),
388
+ preserving_proto_field_name=True,
386
389
  ):
387
390
  yield ParseDict(
388
391
  response, integration_api_pb2.ChatResponse(), ignore_unknown_fields=True
389
392
  )
393
+
394
+ async def make_initiate_assistant_talk(self,
395
+ assistant_id: int, version: str,
396
+ source: common_pb2.Source,
397
+ params: Mapping[str, Any],
398
+ args: Mapping[str, Any],
399
+ metadata: Optional[Dict[str, Any]] = None,
400
+ options: Optional[Dict[str, str]] = None
401
+ ) -> talk_api_pb2.InitiateAssistantTalkResponse:
402
+ response = await self.fetch(
403
+ stub=talk_api_pb2_grpc.TalkServiceStub,
404
+ attr="InitiateAssistantTalk",
405
+ message_type=talk_api_pb2.InitiateAssistantTalkRequest(
406
+ assistant=talk_api_pb2.AssistantDefinition(
407
+ assistantId=assistant_id, version=version
408
+ ),
409
+ source=source,
410
+ params=talk_api_pb2.InitiateAssistantTalkParameter(items=params),
411
+ args=args,
412
+ metadata=metadata,
413
+ options=options,
414
+ ),
415
+ preserving_proto_field_name=True,
416
+ )
417
+
418
+ return ParseDict(
419
+ response,
420
+ talk_api_pb2.InitiateAssistantTalkResponse(),
421
+ ignore_unknown_fields=True,
422
+ )
423
+
424
+ async def make_initiate_bulk_assistant_talk(self,
425
+ assistant_id: int, version: str,
426
+ source: common_pb2.Source,
427
+ params: Iterable[Mapping[str, Any]],
428
+ args: Mapping[str, Any],
429
+ metadata: Optional[Dict[str, Any]] = None,
430
+ options: Optional[Dict[str, str]] = None
431
+ ) -> talk_api_pb2.InitiateBulkAssistantTalkResponse:
432
+ response = await self.fetch(
433
+ stub=talk_api_pb2_grpc.TalkServiceStub,
434
+ attr="InitiateBulkAssistantTalk",
435
+ message_type=talk_api_pb2.InitiateBulkAssistantTalkRequest(
436
+ assistant=talk_api_pb2.AssistantDefinition(
437
+ assistantId=assistant_id, version=version
438
+ ),
439
+ source=source,
440
+ params=[talk_api_pb2.InitiateAssistantTalkParameter(items=p) for p in params],
441
+ args=args,
442
+ metadata=metadata,
443
+ options=options,
444
+ ),
445
+ preserving_proto_field_name=True,
446
+ )
447
+ return ParseDict(
448
+ response,
449
+ talk_api_pb2.InitiateBulkAssistantTalkResponse(),
450
+ ignore_unknown_fields=True,
451
+ )
rapida/constants.py CHANGED
@@ -29,5 +29,5 @@ HEADER_REGION_KEY = "x-rapida-region"
29
29
 
30
30
 
31
31
  ENDPOINT_URL = "connect.rapida.ai"
32
- ASSISTANT_URL = "assistant-01.rapida.ai"
32
+ ASSISTANT_URL = "workflow-01.rapida.ai"
33
33
  GATEWAY_URL = "gateway-01.rapida.ai"
rapida/rapida_client.py CHANGED
@@ -22,9 +22,12 @@
22
22
 
23
23
  import warnings
24
24
  from typing import AsyncIterator, Dict, List, Union, Optional, Tuple, Mapping
25
+
26
+ from google.protobuf.json_format import ParseDict, MessageToDict
27
+
28
+ from rapida.rapida_source import RapidaSource
25
29
  from rapida.client.rapida_bridge import RapidaBridge
26
30
  from rapida.client.response_wrapper import (
27
- ToolDefinition,
28
31
  InvokeResponseWrapper,
29
32
  Message,
30
33
  ToolDefinition,
@@ -33,10 +36,12 @@ from rapida.rapida_client_options import RapidaClientOptions
33
36
  from rapida.exceptions import RapidaException
34
37
  from rapida.exceptions.exceptions import handle_request_exception
35
38
  from rapida.exceptions.exceptions import RapidaConfigurationException
36
- from rapida.artifacts.protos import common_pb2, integration_api_pb2
39
+ from rapida.artifacts.protos import common_pb2, integration_api_pb2, talk_api_pb2
37
40
  from rapida.artifacts.protos.invoker_api_pb2 import InvokerError
38
41
  from google.protobuf.any_pb2 import Any
39
42
 
43
+ from rapida.values import MapToDict
44
+
40
45
 
41
46
  class RapidaClient:
42
47
  # an client/bridge of rapida endpoint
@@ -85,18 +90,18 @@ class RapidaEndpointClient(RapidaClient):
85
90
  )
86
91
 
87
92
  def _endpoint_params(
88
- self,
89
- endpoint: Tuple[int, Union[str, None]],
93
+ self,
94
+ endpoint: Tuple[int, Union[str, None]],
90
95
  ) -> Tuple[int, str]:
91
96
  rapida_endpoint, rapida_endpoint_version = endpoint
92
97
  if rapida_endpoint is None:
93
98
  raise Exception(
94
- "The endpoint key is required. Please provide a endpoint key.",
99
+ "The endpoint id is required. Please provide a endpoint id.",
95
100
  )
96
101
 
97
102
  if rapida_endpoint_version is None:
98
103
  warnings.warn(
99
- "The version is required. Default latest will be used.",
104
+ "The version is optional. Default latest will be used.",
100
105
  )
101
106
  return rapida_endpoint, "latest"
102
107
  return rapida_endpoint, rapida_endpoint_version
@@ -122,17 +127,17 @@ class RapidaEndpointClient(RapidaClient):
122
127
  return _extras
123
128
 
124
129
  async def invoke(
125
- self,
126
- endpoint: Tuple[int, Union[str, None]],
127
- inputs: Mapping[str, Any],
128
- metadata: Optional[Dict[str, str]] = None,
129
- options: Optional[Dict[str, Any]] = None,
130
- ) -> InvokeResponseWrapper:
130
+ self,
131
+ endpoint: Tuple[int, Union[str, None]],
132
+ arguments: Mapping[str, Any],
133
+ metadata: Optional[Dict[str, str]] = None,
134
+ options: Optional[Dict[str, Any]] = None,
135
+ ) -> InvokeResponseWrapper | None:
131
136
  """
132
137
  Invokes a deployment with the specified key.
133
138
 
134
139
  Args:
135
- inputs: Dictionary of input parameters for the prompts
140
+ arguments: Dictionary of input parameters for the prompts
136
141
  metadata: Dictionary of metadata for the current execution
137
142
  options: Dictionary of options for the override parameters for the model
138
143
  endpoint (int, str): The endpoint key.
@@ -147,15 +152,15 @@ class RapidaEndpointClient(RapidaClient):
147
152
  response = await self.rapida_bridge.make_invoke_call(
148
153
  endpoint_id,
149
154
  endpoint_version,
150
- inputs,
155
+ arguments,
151
156
  metadata,
152
157
  options,
153
158
  )
154
159
 
155
160
  if response.is_success():
156
161
  return response
157
-
158
162
  self.handle_deployment_exception(response.error)
163
+ return None
159
164
 
160
165
  async def update_metadata(self, rapida_audit_id: int, rapida_metadata: Dict):
161
166
  """
@@ -178,18 +183,20 @@ class RapidaEndpointClient(RapidaClient):
178
183
  if response.success:
179
184
  return response
180
185
  self.handle_deployment_exception(response.error)
186
+ return None
181
187
 
182
188
  async def probe(self, rapida_audit_id: int):
183
189
  """
184
190
  Probe request for given endpoint audit id
185
191
  Args:
186
- audit_id: request id for probe
192
+ rapida_audit_id: request id for probe
187
193
 
188
194
  """
189
195
  response = await self.rapida_bridge.make_probe_call(rapida_audit_id)
190
196
  if response.success:
191
197
  return response
192
198
  self.handle_deployment_exception(response.error)
199
+ return None
193
200
 
194
201
  def handle_deployment_exception(self, error: Union[None, InvokerError]):
195
202
  """
@@ -227,14 +234,14 @@ class RapidaGatewayClient(RapidaClient):
227
234
  )
228
235
 
229
236
  async def chat(
230
- self,
231
- credentials: Dict,
232
- provider: str,
233
- model: str,
234
- conversations: List[Message],
235
- tools: List[ToolDefinition] = None,
236
- model_parameters: Mapping[str, Any] = None,
237
- meta: Mapping[str, str] = None,
237
+ self,
238
+ credentials: Dict,
239
+ provider: str,
240
+ model: str,
241
+ conversations: List[Message],
242
+ tools: List[ToolDefinition] = None,
243
+ model_parameters: Mapping[str, Any] = None,
244
+ meta: Mapping[str, str] = None,
238
245
  ) -> integration_api_pb2.ChatResponse:
239
246
 
240
247
  conv: List[common_pb2.Message] = []
@@ -255,7 +262,7 @@ class RapidaGatewayClient(RapidaClient):
255
262
  for v in tools:
256
263
  tool_definitions.append(v.to_tool_definition())
257
264
 
258
- return await self.rapida_bridge.chat(
265
+ return await self.rapida_bridge.make_chat_call(
259
266
  cred=credentials,
260
267
  provider=provider,
261
268
  model=model,
@@ -266,14 +273,14 @@ class RapidaGatewayClient(RapidaClient):
266
273
  )
267
274
 
268
275
  async def chat_stream(
269
- self,
270
- credentials: Dict,
271
- provider: str,
272
- model: str,
273
- conversations: List[Message],
274
- tools: List[ToolDefinition] = None,
275
- model_parameters: Mapping[str, Any] = None,
276
- meta: Mapping[str, str] = None,
276
+ self,
277
+ credentials: Dict,
278
+ provider: str,
279
+ model: str,
280
+ conversations: List[Message],
281
+ tools: List[ToolDefinition] = None,
282
+ model_parameters: Mapping[str, Any] = None,
283
+ meta: Mapping[str, str] = None,
277
284
  ) -> AsyncIterator[integration_api_pb2.ChatResponse]:
278
285
 
279
286
  conv: List[common_pb2.Message] = []
@@ -294,29 +301,29 @@ class RapidaGatewayClient(RapidaClient):
294
301
  for v in tools:
295
302
  tool_definitions.append(v.to_tool_definition())
296
303
 
297
- async for response in self.rapida_bridge.chat_stream(
298
- cred=credentials,
299
- provider=provider,
300
- model=model,
301
- conversations=conv,
302
- tool_definitions=tool_definitions,
303
- model_parameters=args,
304
- meta=meta,
304
+ async for response in self.rapida_bridge.make_chat_stream(
305
+ cred=credentials,
306
+ provider=provider,
307
+ model=model,
308
+ conversations=conv,
309
+ tool_definitions=tool_definitions,
310
+ model_parameters=args,
311
+ meta=meta,
305
312
  ):
306
313
  yield response
307
314
 
308
315
  async def generate(
309
- self,
310
- cred: Dict,
311
- provider: str,
312
- model: str,
313
- system_prompt: str,
314
- prompt: str,
315
- model_parameters: Mapping[str, str],
316
- meta: Mapping[str, str],
316
+ self,
317
+ cred: Dict,
318
+ provider: str,
319
+ model: str,
320
+ system_prompt: str,
321
+ prompt: str,
322
+ model_parameters: Mapping[str, str],
323
+ meta: Mapping[str, str],
317
324
  ):
318
325
 
319
- return await self.rapida_bridge.generate(
326
+ return await self.rapida_bridge.make_generate_call(
320
327
  cred=cred,
321
328
  provider=provider,
322
329
  model=model,
@@ -327,15 +334,15 @@ class RapidaGatewayClient(RapidaClient):
327
334
  )
328
335
 
329
336
  async def embedding(
330
- self,
331
- cred: Dict,
332
- provider: str,
333
- model: str,
334
- contents: List[str],
335
- model_parameters: Mapping[str, str],
336
- meta: Mapping[str, str],
337
+ self,
338
+ cred: Dict,
339
+ provider: str,
340
+ model: str,
341
+ contents: List[str],
342
+ model_parameters: Mapping[str, str],
343
+ meta: Mapping[str, str],
337
344
  ):
338
- return await self.rapida_bridge.embedding(
345
+ return await self.rapida_bridge.make_embedding_call(
339
346
  cred=cred,
340
347
  provider=provider,
341
348
  model=model,
@@ -360,4 +367,89 @@ class RapidaAssistantClient(RapidaClient):
360
367
  rapida_region=options.rapida_region.get(),
361
368
  rapida_environment=options.rapida_environment.get(),
362
369
  rapida_is_secure=options.is_secure,
370
+ rapida_source=options.rapida_source.get(),
371
+ )
372
+
373
+ def _assistant_params(
374
+ self,
375
+ assistant: Tuple[int, Union[str, None]],
376
+ ) -> Tuple[int, str]:
377
+ assistant_id, assistant_version = assistant
378
+ if assistant_id is None:
379
+ raise Exception(
380
+ "The assistant id is required. Please provide a assistant id.",
381
+ )
382
+
383
+ if assistant_version is None:
384
+ warnings.warn(
385
+ "The version is optional. Default latest will be used.",
386
+ )
387
+ return assistant_id, "latest"
388
+ return assistant_id, assistant_version
389
+
390
+ async def initiate_assistant_deployment(self,
391
+ assistant: Tuple[int, Union[str, None]],
392
+ source: RapidaSource,
393
+ params: Mapping[str, Any],
394
+ arguments: Optional[Mapping[str, Any]] = None,
395
+ metadata: Optional[Mapping[str, Any]] = None,
396
+ options: Optional[Mapping[
397
+ str, Any]] = None) -> Dict | None:
398
+ assistant_id, version = self._assistant_params(assistant)
399
+ response = await self.rapida_bridge.make_initiate_assistant_talk(
400
+ assistant_id,
401
+ version,
402
+ source.source(),
403
+ params,
404
+ arguments,
405
+ metadata,
406
+ options,
407
+
408
+ )
409
+ if response.success:
410
+ return MapToDict(response.data.items)
411
+ self.handle_assistant_exception(response.error)
412
+ return None
413
+
414
+ async def initiate_bulk_assistant_deployment(self,
415
+ assistant: Tuple[int, Union[str, None]],
416
+ source: RapidaSource,
417
+ params: List[Dict[str, Any]],
418
+ arguments: Optional[Dict[str, Any]] = None,
419
+ metadata: Optional[Dict[str, Any]] = None,
420
+ options: Optional[Dict[str, Any]] = None) -> List[Dict] | None:
421
+ assistant_id, version = self._assistant_params(assistant)
422
+ response = await self.rapida_bridge.make_initiate_bulk_assistant_talk(
423
+ assistant_id,
424
+ version,
425
+ source.source(),
426
+ params,
427
+ arguments,
428
+ metadata,
429
+ options,
430
+ )
431
+
432
+ if response.success:
433
+ return [MapToDict(proto_map.items) for proto_map in response.data]
434
+ self.handle_assistant_exception(response.error)
435
+ return None
436
+
437
+ def handle_assistant_exception(self, error: Union[None, common_pb2.Error]):
438
+ """
439
+ Handling exception for all the common endpoint error
440
+ Args:
441
+ error: An instance of invokeError if found in response
442
+
443
+ """
444
+
445
+ if error is None:
446
+ raise RapidaException(
447
+ code=500,
448
+ message="An unknown error occurred.",
449
+ source="internal client error",
450
+ )
451
+ raise RapidaException(
452
+ code=500,
453
+ message=error.errorMessage,
454
+ source=error.humanMessage,
363
455
  )
@@ -46,10 +46,10 @@ class RapidaClientOptions:
46
46
  def __init__(
47
47
  self,
48
48
  api_key: Optional[str] = None,
49
- endpoint_url: Optional[str] = None,
50
49
  environment: Optional[RapidaEnvironment] = RapidaEnvironment.PRODUCTION,
51
50
  region: Optional[RapidaRegion] = RapidaRegion.ALL,
52
51
  is_secure: bool = True,
52
+ endpoint_url: Optional[str] = None,
53
53
  assistant_url: Optional[str] = None,
54
54
  gateway_url: Optional[str] = None,
55
55
  ):
rapida/rapida_source.py CHANGED
@@ -23,6 +23,8 @@
23
23
  from enum import Enum
24
24
  import logging
25
25
 
26
+ from rapida.artifacts.protos import common_pb2, common_pb2_grpc
27
+
26
28
 
27
29
  class RapidaSource(Enum):
28
30
  """
@@ -32,21 +34,52 @@ class RapidaSource(Enum):
32
34
  WEB_PLUGIN = "web-plugin"
33
35
  RAPIDA_APP = "rapida-app"
34
36
  DEBUGGER = "debugger"
37
+
38
+ # language SDKs
35
39
  PYTHON_SDK = "python-sdk"
36
40
  NODE_SDK = "node-sdk"
37
41
  GO_SDK = "go-sdk"
38
- TYPESCRIPT_SDK = "typescript-sdk"
39
42
  JAVA_SDK = "java-sdk"
40
43
  PHP_SDK = "php-sdk"
41
44
  RUST_SDK = "rust-sdk"
45
+ REACT_SDK = "react-sdk"
46
+
47
+ # extensions
42
48
  TWILIO_CALL = "twilio-call"
43
49
 
50
+ MAPPING = {
51
+ WEB_PLUGIN: common_pb2.Source.WEB_PLUGIN,
52
+ RAPIDA_APP: common_pb2.Source.RAPIDA_APP,
53
+ PYTHON_SDK: common_pb2.Source.PYTHON_SDK,
54
+ NODE_SDK: common_pb2.Source.NODE_SDK,
55
+ GO_SDK: common_pb2.Source.GO_SDK,
56
+ JAVA_SDK: common_pb2.Source.JAVA_SDK,
57
+ PHP_SDK: common_pb2.Source.PHP_SDK,
58
+ RUST_SDK: common_pb2.Source.RUST_SDK,
59
+ REACT_SDK: common_pb2.Source.REACT_SDK,
60
+ TWILIO_CALL: common_pb2.Source.TWILIO_CALL,
61
+ }
62
+
44
63
  def get(self) -> str:
45
64
  return str(self.value)
46
65
 
66
+ def source(self) -> common_pb2.Source:
67
+ mapping = {
68
+ RapidaSource.WEB_PLUGIN: common_pb2.Source.WEB_PLUGIN,
69
+ RapidaSource.RAPIDA_APP: common_pb2.Source.RAPIDA_APP,
70
+ RapidaSource.PYTHON_SDK: common_pb2.Source.PYTHON_SDK,
71
+ RapidaSource.NODE_SDK: common_pb2.Source.NODE_SDK,
72
+ RapidaSource.GO_SDK: common_pb2.Source.GO_SDK,
73
+ RapidaSource.JAVA_SDK: common_pb2.Source.JAVA_SDK,
74
+ RapidaSource.PHP_SDK: common_pb2.Source.PHP_SDK,
75
+ RapidaSource.RUST_SDK: common_pb2.Source.RUST_SDK,
76
+ RapidaSource.REACT_SDK: common_pb2.Source.REACT_SDK,
77
+ RapidaSource.TWILIO_CALL: common_pb2.Source.TWILIO_CALL,
78
+ }
79
+ return mapping.get(self)
80
+
47
81
  @staticmethod
48
82
  def from_str(label: str):
49
- logging.info(f"Got the label {label}")
50
83
  source_map = {
51
84
  "web-plugin": RapidaSource.WEB_PLUGIN,
52
85
  "rapida-app": RapidaSource.RAPIDA_APP,
@@ -54,7 +87,6 @@ class RapidaSource(Enum):
54
87
  "python-sdk": RapidaSource.PYTHON_SDK,
55
88
  "node-sdk": RapidaSource.NODE_SDK,
56
89
  "go-sdk": RapidaSource.GO_SDK,
57
- "typescript-sdk": RapidaSource.TYPESCRIPT_SDK,
58
90
  "java-sdk": RapidaSource.JAVA_SDK,
59
91
  "php-sdk": RapidaSource.PHP_SDK,
60
92
  "rust-sdk": RapidaSource.RUST_SDK,
@@ -69,3 +101,4 @@ class RapidaSource(Enum):
69
101
  "'go-sdk', 'typescript-sdk', 'java-sdk', 'php-sdk', 'rust-sdk', 'twilio-call'."
70
102
  )
71
103
  return result
104
+
rapida/values.py CHANGED
@@ -22,8 +22,8 @@
22
22
 
23
23
  import mimetypes
24
24
  import re
25
+ import typing
25
26
 
26
- from google.protobuf.any_pb2 import Any
27
27
  from google.protobuf.wrappers_pb2 import (
28
28
  StringValue as _StringValue,
29
29
  BytesValue,
@@ -33,7 +33,9 @@ from google.protobuf.wrappers_pb2 import (
33
33
  import os
34
34
  from PIL import Image
35
35
 
36
- from rapida import RapidaException
36
+ from rapida.exceptions.exceptions import RapidaException
37
+ from google.protobuf.any_pb2 import Any
38
+ from google.protobuf import wrappers_pb2, timestamp_pb2, duration_pb2, empty_pb2, struct_pb2, json_format
37
39
 
38
40
 
39
41
  def StringValue(_in: str) -> Any:
@@ -317,3 +319,53 @@ def URLValue(url: str) -> Any:
317
319
  any_message.Pack(string_value)
318
320
 
319
321
  return any_message
322
+
323
+
324
+ def AnyToValue(any_value: Any) -> typing.Any:
325
+ if not any_value or not getattr(any_value, "type_url", None):
326
+ return None
327
+
328
+ type_map: dict[str, typing.Type] = {
329
+ "type.googleapis.com/google.protobuf.StringValue": wrappers_pb2.StringValue,
330
+ "type.googleapis.com/google.protobuf.Int32Value": wrappers_pb2.Int32Value,
331
+ "type.googleapis.com/google.protobuf.Int64Value": wrappers_pb2.Int64Value,
332
+ "type.googleapis.com/google.protobuf.UInt32Value": wrappers_pb2.UInt32Value,
333
+ "type.googleapis.com/google.protobuf.UInt64Value": wrappers_pb2.UInt64Value,
334
+ "type.googleapis.com/google.protobuf.FloatValue": wrappers_pb2.FloatValue,
335
+ "type.googleapis.com/google.protobuf.DoubleValue": wrappers_pb2.DoubleValue,
336
+ "type.googleapis.com/google.protobuf.BoolValue": wrappers_pb2.BoolValue,
337
+ "type.googleapis.com/google.protobuf.BytesValue": wrappers_pb2.BytesValue,
338
+ "type.googleapis.com/google.protobuf.Timestamp": timestamp_pb2.Timestamp,
339
+ "type.googleapis.com/google.protobuf.Duration": duration_pb2.Duration,
340
+ "type.googleapis.com/google.protobuf.Empty": empty_pb2.Empty,
341
+ "type.googleapis.com/google.protobuf.Struct": struct_pb2.Struct,
342
+ }
343
+
344
+ msg_class = type_map.get(any_value.type_url)
345
+ if msg_class:
346
+ msg = msg_class()
347
+ any_value.Unpack(msg)
348
+
349
+ if isinstance(msg, timestamp_pb2.Timestamp):
350
+ return msg.ToDatetime()
351
+ elif isinstance(msg, duration_pb2.Duration):
352
+ return msg.ToTimedelta()
353
+ elif isinstance(msg, empty_pb2.Empty):
354
+ return None
355
+ elif isinstance(msg, struct_pb2.Struct):
356
+ return json_format.MessageToDict(msg)
357
+ elif hasattr(msg, "value"):
358
+ return msg.value
359
+ else:
360
+ return json_format.MessageToDict(msg)
361
+ else:
362
+ return json_format.MessageToJson(any_value)
363
+
364
+
365
+ def MapToDict(proto_map: typing.Mapping[str, Any]) -> dict[str, typing.Any]:
366
+ result: dict[str, typing.Any] = {}
367
+
368
+ for key, any_value in proto_map.items():
369
+ result[key] = AnyToValue(any_value)
370
+
371
+ return result
rapida/version.py CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  _MAJOR = "0"
24
24
  _MINOR = "1"
25
- _REVISION = "1-alpha"
25
+ _REVISION = "3-alpha"
26
26
 
27
27
  VERSION_SHORT = f"{_MAJOR}.{_MINOR}"
28
28
  VERSION = f"{_MAJOR}.{_MINOR}.{_REVISION}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rapida-python
3
- Version: 0.1.1a0
3
+ Version: 0.1.3a0
4
4
  Summary: rapidaAi sdk to integrate rapida.ai api's
5
5
  Home-page: https://github.com/rapidaai/rapida-python
6
6
  Author-email: code@rapida.ai
@@ -1,17 +1,17 @@
1
1
  bin/__init__.py,sha256=uunvHyOaVic6mTNNF4PCIyo1VGRDH5PwAoLhf3I-lCA,35
2
2
  rapida/__init__.py,sha256=nOtzJAi6XBDfgaowERqtLoDcKskRrsUERdjUNzUYgaM,2171
3
- rapida/constants.py,sha256=5kQv86tiIkoM7cqfM0nB5wRtpOW_LP8qXSZTn9vo4Wk,1445
4
- rapida/rapida_client.py,sha256=xauRKSQ0691EeNuDIRlhbBqhpAnTq5O-CEKkgevVefM,12684
5
- rapida/rapida_client_options.py,sha256=89YFRtKZlvz7WyffJqe8U2Z5VdNQSzM8UgHO3IVMvGQ,2915
3
+ rapida/constants.py,sha256=7qVonsY5oJGY7TY7XLd51l4CQch4NnRlbJ774TVD6fM,1444
4
+ rapida/rapida_client.py,sha256=7m8SVIkLsFdiddLRXyME07u7UQJI_6tP5ka8PeNnX1w,16535
5
+ rapida/rapida_client_options.py,sha256=lE13nuQ_b9VExVwtqP2fpik5RrErPawfUPtlXIlRqIc,2915
6
6
  rapida/rapida_environment.py,sha256=S0wpHjNAokg3PbGXt5QkzATmX0_jPCjCC8zC_G33qaQ,1780
7
7
  rapida/rapida_region.py,sha256=ZO6_VGTlawtM2G_XOPVQldupOlMRRS__A97KGu8TQkE,1788
8
- rapida/rapida_source.py,sha256=IeIDIERDtEJn2cqJ0qXpOMnENb900Pr0ma7vE1U2unM,2718
9
- rapida/values.py,sha256=Ws7Omz96k0jbgWFOBtrBqugrjsk8j8DpTPuyV14_0xs,9278
10
- rapida/version.py,sha256=62odGDcHP0GN3tfqOYCjMMqRLSAajc9Gucjj69120J0,1275
8
+ rapida/rapida_source.py,sha256=LwBRU-CwTgce3rDfXMfOA5xMJ11kIxZHrPBPGwUVvOQ,3955
9
+ rapida/values.py,sha256=sfRWMh-AemF5kdWX6yYIx8qiC2lzKoWkeVc_kuoB-g0,11550
10
+ rapida/version.py,sha256=WnfI7kdasNH46IpovJI5i_o7K-0dM_8Kz-KZgUKOrVM,1275
11
11
  rapida/artifacts/__init__.py,sha256=uunvHyOaVic6mTNNF4PCIyo1VGRDH5PwAoLhf3I-lCA,35
12
12
  rapida/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  rapida/client/grpc_bridge.py,sha256=3mvALHj6JKyJX1qXymnGTn3RoYLR2lLYGFijdONABok,8678
14
- rapida/client/rapida_bridge.py,sha256=sy3BZaZml5cXAWiXmFr9j5WyYJ4XYSE8ebmm4y2p5nI,14103
14
+ rapida/client/rapida_bridge.py,sha256=aObV6qo2Ge2VhdhvgnrRZEP_642qjkPspBRS2JizIbw,17286
15
15
  rapida/client/response_wrapper.py,sha256=hOaEvrnVNbsETBxgR5lr4rQfiE6WTgTpoYexVl7jT-k,8829
16
16
  rapida/exceptions/__init__.py,sha256=-Sn1p5ezX1P90_kBPvFYUUz-Pc1d33uv3KQYPsK4qqQ,1546
17
17
  rapida/exceptions/exceptions.py,sha256=B26HQSaK_KwDYt44EonJYk-Gvqw0jfa_ho8vwupVG1s,3976
@@ -19,7 +19,7 @@ rapida/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  rapida/tests/test_rapida_client.py,sha256=I3PJCz_R2S1sqptCRxo81BHV6K8Jtf_4DjEIBtnpfQk,5781
20
20
  rapida/tests/test_rapida_client_options.py,sha256=zOWRx9LTNF-9MYajWeFeIFWg_HUuAirH4EdffeH8W7M,3203
21
21
  rapida/tests/test_values.py,sha256=pnXy4djs7b-xn5_W2SXSEJBtRBm9tbmucLKWyqSnmm8,1709
22
- rapida_python-0.1.1a0.dist-info/METADATA,sha256=3WJvyzakxD2bv5qgnUCxy53J1UobsHcRHraOMI6by_U,1914
23
- rapida_python-0.1.1a0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
24
- rapida_python-0.1.1a0.dist-info/top_level.txt,sha256=046qVW6wPXCDmFm-V2YJcXQY0vApej2JLfv1NDKevoE,11
25
- rapida_python-0.1.1a0.dist-info/RECORD,,
22
+ rapida_python-0.1.3a0.dist-info/METADATA,sha256=OREr6tnwWfwtQicMKaUrNI5V4IO3lUhIzynG8TqoVgI,1914
23
+ rapida_python-0.1.3a0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
24
+ rapida_python-0.1.3a0.dist-info/top_level.txt,sha256=046qVW6wPXCDmFm-V2YJcXQY0vApej2JLfv1NDKevoE,11
25
+ rapida_python-0.1.3a0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.44.0)
2
+ Generator: bdist_wheel (0.45.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5