trustgraph-bedrock 0.20.5__tar.gz → 0.20.7__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.
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trustgraph-bedrock
3
- Version: 0.20.5
3
+ Version: 0.20.7
4
4
  Summary: TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline.
5
5
  Home-page: https://github.com/trustgraph-ai/trustgraph
6
- Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.20.5.tar.gz
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.20.7.tar.gz
7
7
  Author: trustgraph.ai
8
8
  Author-email: security@trustgraph.ai
9
9
  Classifier: Programming Language :: Python :: 3
@@ -0,0 +1 @@
1
+ __version__ = "0.20.7"
@@ -5,6 +5,7 @@ Input is prompt, output is response. Mistral is default.
5
5
  """
6
6
 
7
7
  import boto3
8
+ from botocore.errorfactory import ThrottlingException
8
9
  import json
9
10
  from prometheus_client import Histogram
10
11
  import os
@@ -24,32 +25,48 @@ default_subscriber = module
24
25
  default_model = 'mistral.mistral-large-2407-v1:0'
25
26
  default_temperature = 0.0
26
27
  default_max_output = 2048
27
- default_aws_id_key = os.getenv("AWS_ID_KEY", None)
28
- default_aws_secret = os.getenv("AWS_SECRET", None)
29
- default_aws_region = os.getenv("AWS_REGION", 'us-west-2')
28
+
29
+ # Actually, these could all just be None, no need to get environment
30
+ # variables, as Boto3 would pick all these up if not passed in as args
31
+ default_access_key_id = os.getenv("AWS_ACCESS_KEY_ID", None)
32
+ default_secret_access_key = os.getenv("AWS_SECRET_ACCESS_KEY", None)
33
+ default_session_token = os.getenv("AWS_SESSION_TOKEN", None)
34
+ default_profile = os.getenv("AWS_PROFILE", None)
35
+ default_region = os.getenv("AWS_DEFAULT_REGION", None)
30
36
 
31
37
  class Processor(ConsumerProducer):
32
38
 
33
39
  def __init__(self, **params):
40
+
41
+ print(params)
34
42
 
35
43
  input_queue = params.get("input_queue", default_input_queue)
36
44
  output_queue = params.get("output_queue", default_output_queue)
37
45
  subscriber = params.get("subscriber", default_subscriber)
46
+
38
47
  model = params.get("model", default_model)
39
- aws_id_key = params.get("aws_id_key", default_aws_id_key)
40
- aws_secret = params.get("aws_secret", default_aws_secret)
41
- aws_region = params.get("aws_region", default_aws_region)
42
48
  temperature = params.get("temperature", default_temperature)
43
49
  max_output = params.get("max_output", default_max_output)
44
50
 
45
- if aws_id_key is None:
46
- raise RuntimeError("AWS ID not specified")
51
+ aws_access_key_id = params.get(
52
+ "aws_access_key_id", default_access_key_id
53
+ )
54
+
55
+ aws_secret_access_key = params.get(
56
+ "aws_secret_access_key", default_secret_access_key
57
+ )
47
58
 
48
- if aws_secret is None:
49
- raise RuntimeError("AWS secret not specified")
59
+ aws_session_token = params.get(
60
+ "aws_session_token", default_session_token
61
+ )
50
62
 
51
- if aws_region is None:
52
- raise RuntimeError("AWS region not specified")
63
+ aws_region = params.get(
64
+ "aws_region", default_region
65
+ )
66
+
67
+ aws_profile = params.get(
68
+ "aws_profile", default_profile
69
+ )
53
70
 
54
71
  super(Processor, self).__init__(
55
72
  **params | {
@@ -82,9 +99,11 @@ class Processor(ConsumerProducer):
82
99
  self.max_output = max_output
83
100
 
84
101
  self.session = boto3.Session(
85
- aws_access_key_id=aws_id_key,
86
- aws_secret_access_key=aws_secret,
87
- region_name=aws_region
102
+ aws_access_key_id=aws_access_key_id,
103
+ aws_secret_access_key=aws_secret_access_key,
104
+ aws_session_token=aws_session_token,
105
+ profile_name=aws_profile,
106
+ region_name=aws_region,
88
107
  )
89
108
 
90
109
  self.bedrock = self.session.client(service_name='bedrock-runtime')
@@ -179,9 +198,6 @@ class Processor(ConsumerProducer):
179
198
  accept = 'application/json'
180
199
  contentType = 'application/json'
181
200
 
182
- # FIXME: Consider catching request limits and raise TooManyRequests
183
- # See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/retries.html
184
-
185
201
  with __class__.text_completion_metric.time():
186
202
  response = self.bedrock.invoke_model(
187
203
  body=promptbody, modelId=self.model, accept=accept,
@@ -243,10 +259,7 @@ class Processor(ConsumerProducer):
243
259
 
244
260
  print("Done.", flush=True)
245
261
 
246
-
247
- # FIXME: Wrong exception, don't know what Bedrock throws
248
- # for a rate limit
249
- except TooManyRequests:
262
+ except ThrottlingException:
250
263
 
251
264
  print("Send rate limit response...", flush=True)
252
265
 
@@ -300,21 +313,27 @@ class Processor(ConsumerProducer):
300
313
  )
301
314
 
302
315
  parser.add_argument(
303
- '-z', '--aws-id-key',
304
- default=default_aws_id_key,
305
- help=f'AWS ID Key'
316
+ '-z', '--aws-access-key-id',
317
+ default=default_access_key_id,
318
+ help=f'AWS access key ID'
306
319
  )
307
320
 
308
321
  parser.add_argument(
309
- '-k', '--aws-secret',
310
- default=default_aws_secret,
311
- help=f'AWS Secret Key'
322
+ '-k', '--aws-secret-access-key',
323
+ default=default_secret_access_key,
324
+ help=f'AWS secret access key'
312
325
  )
313
326
 
314
327
  parser.add_argument(
315
328
  '-r', '--aws-region',
316
- default=default_aws_region,
317
- help=f'AWS Region'
329
+ default=default_region,
330
+ help=f'AWS region'
331
+ )
332
+
333
+ parser.add_argument(
334
+ '--aws-profile', '--profile',
335
+ default=default_profile,
336
+ help=f'AWS profile name'
318
337
  )
319
338
 
320
339
  parser.add_argument(
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trustgraph-bedrock
3
- Version: 0.20.5
3
+ Version: 0.20.7
4
4
  Summary: TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline.
5
5
  Home-page: https://github.com/trustgraph-ai/trustgraph
6
- Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.20.5.tar.gz
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.20.7.tar.gz
7
7
  Author: trustgraph.ai
8
8
  Author-email: security@trustgraph.ai
9
9
  Classifier: Programming Language :: Python :: 3
@@ -1 +0,0 @@
1
- __version__ = "0.20.5"