trustgraph-vertexai 0.22.5__tar.gz → 0.22.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.
Potentially problematic release.
This version of trustgraph-vertexai might be problematic. Click here for more details.
- {trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/PKG-INFO +2 -2
- {trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/trustgraph/model/text_completion/vertexai/llm.py +29 -109
- trustgraph-vertexai-0.22.7/trustgraph/vertexai_version.py +1 -0
- {trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/trustgraph_vertexai.egg-info/PKG-INFO +2 -2
- trustgraph-vertexai-0.22.5/trustgraph/vertexai_version.py +0 -1
- {trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/README.md +0 -0
- {trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/scripts/text-completion-vertexai +0 -0
- {trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/setup.cfg +0 -0
- {trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/setup.py +0 -0
- {trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/trustgraph/model/text_completion/vertexai/__init__.py +0 -0
- {trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/trustgraph/model/text_completion/vertexai/__main__.py +0 -0
- {trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/trustgraph_vertexai.egg-info/SOURCES.txt +0 -0
- {trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/trustgraph_vertexai.egg-info/dependency_links.txt +0 -0
- {trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/trustgraph_vertexai.egg-info/requires.txt +0 -0
- {trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/trustgraph_vertexai.egg-info/top_level.txt +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: trustgraph-vertexai
|
|
3
|
-
Version: 0.22.
|
|
3
|
+
Version: 0.22.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.22.
|
|
6
|
+
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.22.7.tar.gz
|
|
7
7
|
Author: trustgraph.ai
|
|
8
8
|
Author-email: security@trustgraph.ai
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -4,50 +4,30 @@ Simple LLM service, performs text prompt completion using VertexAI on
|
|
|
4
4
|
Google Cloud. Input is prompt, output is response.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
-
import vertexai
|
|
8
|
-
import time
|
|
9
|
-
from prometheus_client import Histogram
|
|
10
|
-
import os
|
|
11
|
-
|
|
12
7
|
from google.oauth2 import service_account
|
|
13
8
|
import google
|
|
9
|
+
import vertexai
|
|
14
10
|
|
|
15
11
|
from vertexai.preview.generative_models import (
|
|
16
|
-
Content,
|
|
17
|
-
|
|
18
|
-
GenerativeModel,
|
|
19
|
-
GenerationConfig,
|
|
20
|
-
HarmCategory,
|
|
21
|
-
HarmBlockThreshold,
|
|
22
|
-
Part,
|
|
23
|
-
Tool,
|
|
12
|
+
Content, FunctionDeclaration, GenerativeModel, GenerationConfig,
|
|
13
|
+
HarmCategory, HarmBlockThreshold, Part, Tool,
|
|
24
14
|
)
|
|
25
15
|
|
|
26
|
-
from .... schema import TextCompletionRequest, TextCompletionResponse, Error
|
|
27
|
-
from .... schema import text_completion_request_queue
|
|
28
|
-
from .... schema import text_completion_response_queue
|
|
29
|
-
from .... log_level import LogLevel
|
|
30
|
-
from .... base import ConsumerProducer
|
|
31
16
|
from .... exceptions import TooManyRequests
|
|
17
|
+
from .... base import LlmService, LlmResult
|
|
32
18
|
|
|
33
|
-
|
|
19
|
+
default_ident = "text-completion"
|
|
34
20
|
|
|
35
|
-
default_input_queue = text_completion_request_queue
|
|
36
|
-
default_output_queue = text_completion_response_queue
|
|
37
|
-
default_subscriber = module
|
|
38
21
|
default_model = 'gemini-1.0-pro-001'
|
|
39
22
|
default_region = 'us-central1'
|
|
40
23
|
default_temperature = 0.0
|
|
41
24
|
default_max_output = 8192
|
|
42
25
|
default_private_key = "private.json"
|
|
43
26
|
|
|
44
|
-
class Processor(
|
|
27
|
+
class Processor(LlmService):
|
|
45
28
|
|
|
46
29
|
def __init__(self, **params):
|
|
47
30
|
|
|
48
|
-
input_queue = params.get("input_queue", default_input_queue)
|
|
49
|
-
output_queue = params.get("output_queue", default_output_queue)
|
|
50
|
-
subscriber = params.get("subscriber", default_subscriber)
|
|
51
31
|
region = params.get("region", default_region)
|
|
52
32
|
model = params.get("model", default_model)
|
|
53
33
|
private_key = params.get("private_key", default_private_key)
|
|
@@ -57,28 +37,7 @@ class Processor(ConsumerProducer):
|
|
|
57
37
|
if private_key is None:
|
|
58
38
|
raise RuntimeError("Private key file not specified")
|
|
59
39
|
|
|
60
|
-
super(Processor, self).__init__(
|
|
61
|
-
**params | {
|
|
62
|
-
"input_queue": input_queue,
|
|
63
|
-
"output_queue": output_queue,
|
|
64
|
-
"subscriber": subscriber,
|
|
65
|
-
"input_schema": TextCompletionRequest,
|
|
66
|
-
"output_schema": TextCompletionResponse,
|
|
67
|
-
}
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
if not hasattr(__class__, "text_completion_metric"):
|
|
71
|
-
__class__.text_completion_metric = Histogram(
|
|
72
|
-
'text_completion_duration',
|
|
73
|
-
'Text completion duration (seconds)',
|
|
74
|
-
buckets=[
|
|
75
|
-
0.25, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0,
|
|
76
|
-
8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0,
|
|
77
|
-
17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0,
|
|
78
|
-
30.0, 35.0, 40.0, 45.0, 50.0, 60.0, 80.0, 100.0,
|
|
79
|
-
120.0
|
|
80
|
-
]
|
|
81
|
-
)
|
|
40
|
+
super(Processor, self).__init__(**params)
|
|
82
41
|
|
|
83
42
|
self.parameters = {
|
|
84
43
|
"temperature": temperature,
|
|
@@ -110,7 +69,11 @@ class Processor(ConsumerProducer):
|
|
|
110
69
|
print("Initialise VertexAI...", flush=True)
|
|
111
70
|
|
|
112
71
|
if private_key:
|
|
113
|
-
credentials =
|
|
72
|
+
credentials = (
|
|
73
|
+
service_account.Credentials.from_service_account_file(
|
|
74
|
+
private_key
|
|
75
|
+
)
|
|
76
|
+
)
|
|
114
77
|
else:
|
|
115
78
|
credentials = None
|
|
116
79
|
|
|
@@ -131,50 +94,29 @@ class Processor(ConsumerProducer):
|
|
|
131
94
|
|
|
132
95
|
print("Initialisation complete", flush=True)
|
|
133
96
|
|
|
134
|
-
async def
|
|
97
|
+
async def generate_content(self, system, prompt):
|
|
135
98
|
|
|
136
99
|
try:
|
|
137
100
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
# Sender-produced ID
|
|
141
|
-
|
|
142
|
-
id = msg.properties()["id"]
|
|
101
|
+
prompt = system + "\n\n" + prompt
|
|
143
102
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
103
|
+
response = self.llm.generate_content(
|
|
104
|
+
prompt, generation_config=self.generation_config,
|
|
105
|
+
safety_settings=self.safety_settings
|
|
106
|
+
)
|
|
147
107
|
|
|
148
|
-
|
|
108
|
+
resp = LlmResult()
|
|
109
|
+
resp.text = response.text
|
|
110
|
+
resp.in_token = response.usage_metadata.prompt_token_count
|
|
111
|
+
resp.out_token = response.usage_metadata.candidates_token_count
|
|
112
|
+
resp.model = self.model
|
|
149
113
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
safety_settings=self.safety_settings
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
resp = response.text
|
|
156
|
-
inputtokens = int(response.usage_metadata.prompt_token_count)
|
|
157
|
-
outputtokens = int(response.usage_metadata.candidates_token_count)
|
|
158
|
-
print(resp, flush=True)
|
|
159
|
-
print(f"Input Tokens: {inputtokens}", flush=True)
|
|
160
|
-
print(f"Output Tokens: {outputtokens}", flush=True)
|
|
114
|
+
print(f"Input Tokens: {resp.in_token}", flush=True)
|
|
115
|
+
print(f"Output Tokens: {resp.out_token}", flush=True)
|
|
161
116
|
|
|
162
117
|
print("Send response...", flush=True)
|
|
163
118
|
|
|
164
|
-
|
|
165
|
-
error=None,
|
|
166
|
-
response=resp,
|
|
167
|
-
in_token=inputtokens,
|
|
168
|
-
out_token=outputtokens,
|
|
169
|
-
model=self.model
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
await self.send(r, properties={"id": id})
|
|
173
|
-
|
|
174
|
-
print("Done.", flush=True)
|
|
175
|
-
|
|
176
|
-
# Acknowledge successful processing of the message
|
|
177
|
-
self.consumer.acknowledge(msg)
|
|
119
|
+
return resp
|
|
178
120
|
|
|
179
121
|
except google.api_core.exceptions.ResourceExhausted as e:
|
|
180
122
|
|
|
@@ -186,40 +128,19 @@ class Processor(ConsumerProducer):
|
|
|
186
128
|
except Exception as e:
|
|
187
129
|
|
|
188
130
|
# Apart from rate limits, treat all exceptions as unrecoverable
|
|
189
|
-
|
|
190
131
|
print(f"Exception: {e}")
|
|
191
|
-
|
|
192
|
-
print("Send error response...", flush=True)
|
|
193
|
-
|
|
194
|
-
r = TextCompletionResponse(
|
|
195
|
-
error=Error(
|
|
196
|
-
type = "llm-error",
|
|
197
|
-
message = str(e),
|
|
198
|
-
),
|
|
199
|
-
response=None,
|
|
200
|
-
in_token=None,
|
|
201
|
-
out_token=None,
|
|
202
|
-
model=None,
|
|
203
|
-
)
|
|
204
|
-
|
|
205
|
-
await self.send(r, properties={"id": id})
|
|
206
|
-
|
|
207
|
-
self.consumer.acknowledge(msg)
|
|
132
|
+
raise e
|
|
208
133
|
|
|
209
134
|
@staticmethod
|
|
210
135
|
def add_args(parser):
|
|
211
136
|
|
|
212
|
-
|
|
213
|
-
parser, default_input_queue, default_subscriber,
|
|
214
|
-
default_output_queue,
|
|
215
|
-
)
|
|
137
|
+
LlmService.add_args(parser)
|
|
216
138
|
|
|
217
139
|
parser.add_argument(
|
|
218
140
|
'-m', '--model',
|
|
219
141
|
default=default_model,
|
|
220
142
|
help=f'LLM model (default: {default_model})'
|
|
221
143
|
)
|
|
222
|
-
# Also: text-bison-32k
|
|
223
144
|
|
|
224
145
|
parser.add_argument(
|
|
225
146
|
'-k', '--private-key',
|
|
@@ -247,6 +168,5 @@ class Processor(ConsumerProducer):
|
|
|
247
168
|
)
|
|
248
169
|
|
|
249
170
|
def run():
|
|
250
|
-
|
|
251
|
-
Processor.launch(module, __doc__)
|
|
171
|
+
Processor.launch(default_ident, __doc__)
|
|
252
172
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.22.7"
|
{trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/trustgraph_vertexai.egg-info/PKG-INFO
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: trustgraph-vertexai
|
|
3
|
-
Version: 0.22.
|
|
3
|
+
Version: 0.22.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.22.
|
|
6
|
+
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.22.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.22.5"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/trustgraph_vertexai.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/trustgraph_vertexai.egg-info/requires.txt
RENAMED
|
File without changes
|
{trustgraph-vertexai-0.22.5 → trustgraph-vertexai-0.22.7}/trustgraph_vertexai.egg-info/top_level.txt
RENAMED
|
File without changes
|