trustgraph-vertexai 0.11.11__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.11.11/PKG-INFO +19 -0
- trustgraph-vertexai-0.11.11/README.md +1 -0
- trustgraph-vertexai-0.11.11/scripts/text-completion-vertexai +6 -0
- trustgraph-vertexai-0.11.11/setup.cfg +4 -0
- trustgraph-vertexai-0.11.11/setup.py +45 -0
- trustgraph-vertexai-0.11.11/trustgraph/model/text_completion/vertexai/__init__.py +3 -0
- trustgraph-vertexai-0.11.11/trustgraph/model/text_completion/vertexai/__main__.py +7 -0
- trustgraph-vertexai-0.11.11/trustgraph/model/text_completion/vertexai/llm.py +257 -0
- trustgraph-vertexai-0.11.11/trustgraph/vertexai_version.py +1 -0
- trustgraph-vertexai-0.11.11/trustgraph_vertexai.egg-info/PKG-INFO +19 -0
- trustgraph-vertexai-0.11.11/trustgraph_vertexai.egg-info/SOURCES.txt +12 -0
- trustgraph-vertexai-0.11.11/trustgraph_vertexai.egg-info/dependency_links.txt +1 -0
- trustgraph-vertexai-0.11.11/trustgraph_vertexai.egg-info/requires.txt +4 -0
- trustgraph-vertexai-0.11.11/trustgraph_vertexai.egg-info/top_level.txt +2 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: trustgraph-vertexai
|
|
3
|
+
Version: 0.11.11
|
|
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
|
+
Home-page: https://github.com/trustgraph-ai/trustgraph
|
|
6
|
+
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.11.11.tar.gz
|
|
7
|
+
Author: trustgraph.ai
|
|
8
|
+
Author-email: security@trustgraph.ai
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: trustgraph-base
|
|
15
|
+
Requires-Dist: pulsar-client
|
|
16
|
+
Requires-Dist: google-cloud-aiplatform
|
|
17
|
+
Requires-Dist: prometheus-client
|
|
18
|
+
|
|
19
|
+
See https://trustgraph.ai/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
See https://trustgraph.ai/
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import setuptools
|
|
2
|
+
import os
|
|
3
|
+
import importlib
|
|
4
|
+
|
|
5
|
+
with open("README.md", "r") as fh:
|
|
6
|
+
long_description = fh.read()
|
|
7
|
+
|
|
8
|
+
# Load a version number module
|
|
9
|
+
spec = importlib.util.spec_from_file_location(
|
|
10
|
+
'version', 'trustgraph/vertexai_version.py'
|
|
11
|
+
)
|
|
12
|
+
version_module = importlib.util.module_from_spec(spec)
|
|
13
|
+
spec.loader.exec_module(version_module)
|
|
14
|
+
|
|
15
|
+
version = version_module.__version__
|
|
16
|
+
|
|
17
|
+
setuptools.setup(
|
|
18
|
+
name="trustgraph-vertexai",
|
|
19
|
+
version=version,
|
|
20
|
+
author="trustgraph.ai",
|
|
21
|
+
author_email="security@trustgraph.ai",
|
|
22
|
+
description="TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline.",
|
|
23
|
+
long_description=long_description,
|
|
24
|
+
long_description_content_type="text/markdown",
|
|
25
|
+
url="https://github.com/trustgraph-ai/trustgraph",
|
|
26
|
+
packages=setuptools.find_namespace_packages(
|
|
27
|
+
where='./',
|
|
28
|
+
),
|
|
29
|
+
classifiers=[
|
|
30
|
+
"Programming Language :: Python :: 3",
|
|
31
|
+
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
|
|
32
|
+
"Operating System :: OS Independent",
|
|
33
|
+
],
|
|
34
|
+
python_requires='>=3.8',
|
|
35
|
+
download_url = "https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v" + version + ".tar.gz",
|
|
36
|
+
install_requires=[
|
|
37
|
+
"trustgraph-base",
|
|
38
|
+
"pulsar-client",
|
|
39
|
+
"google-cloud-aiplatform",
|
|
40
|
+
"prometheus-client",
|
|
41
|
+
],
|
|
42
|
+
scripts=[
|
|
43
|
+
"scripts/text-completion-vertexai",
|
|
44
|
+
]
|
|
45
|
+
)
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
|
|
2
|
+
"""
|
|
3
|
+
Simple LLM service, performs text prompt completion using VertexAI on
|
|
4
|
+
Google Cloud. Input is prompt, output is response.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import vertexai
|
|
8
|
+
import time
|
|
9
|
+
from prometheus_client import Histogram
|
|
10
|
+
|
|
11
|
+
from google.oauth2 import service_account
|
|
12
|
+
import google
|
|
13
|
+
|
|
14
|
+
from vertexai.preview.generative_models import (
|
|
15
|
+
Content,
|
|
16
|
+
FunctionDeclaration,
|
|
17
|
+
GenerativeModel,
|
|
18
|
+
GenerationConfig,
|
|
19
|
+
HarmCategory,
|
|
20
|
+
HarmBlockThreshold,
|
|
21
|
+
Part,
|
|
22
|
+
Tool,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
from .... schema import TextCompletionRequest, TextCompletionResponse, Error
|
|
26
|
+
from .... schema import text_completion_request_queue
|
|
27
|
+
from .... schema import text_completion_response_queue
|
|
28
|
+
from .... log_level import LogLevel
|
|
29
|
+
from .... base import ConsumerProducer
|
|
30
|
+
from .... exceptions import TooManyRequests
|
|
31
|
+
|
|
32
|
+
module = ".".join(__name__.split(".")[1:-1])
|
|
33
|
+
|
|
34
|
+
default_input_queue = text_completion_request_queue
|
|
35
|
+
default_output_queue = text_completion_response_queue
|
|
36
|
+
default_subscriber = module
|
|
37
|
+
default_model = 'gemini-1.0-pro-001'
|
|
38
|
+
default_region = 'us-central1'
|
|
39
|
+
default_temperature = 0.0
|
|
40
|
+
default_max_output = 8192
|
|
41
|
+
|
|
42
|
+
class Processor(ConsumerProducer):
|
|
43
|
+
|
|
44
|
+
def __init__(self, **params):
|
|
45
|
+
|
|
46
|
+
input_queue = params.get("input_queue", default_input_queue)
|
|
47
|
+
output_queue = params.get("output_queue", default_output_queue)
|
|
48
|
+
subscriber = params.get("subscriber", default_subscriber)
|
|
49
|
+
region = params.get("region", default_region)
|
|
50
|
+
model = params.get("model", default_model)
|
|
51
|
+
private_key = params.get("private_key")
|
|
52
|
+
temperature = params.get("temperature", default_temperature)
|
|
53
|
+
max_output = params.get("max_output", default_max_output)
|
|
54
|
+
|
|
55
|
+
super(Processor, self).__init__(
|
|
56
|
+
**params | {
|
|
57
|
+
"input_queue": input_queue,
|
|
58
|
+
"output_queue": output_queue,
|
|
59
|
+
"subscriber": subscriber,
|
|
60
|
+
"input_schema": TextCompletionRequest,
|
|
61
|
+
"output_schema": TextCompletionResponse,
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
if not hasattr(__class__, "text_completion_metric"):
|
|
66
|
+
__class__.text_completion_metric = Histogram(
|
|
67
|
+
'text_completion_duration',
|
|
68
|
+
'Text completion duration (seconds)',
|
|
69
|
+
buckets=[
|
|
70
|
+
0.25, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0,
|
|
71
|
+
8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0,
|
|
72
|
+
17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0,
|
|
73
|
+
30.0, 35.0, 40.0, 45.0, 50.0, 60.0, 80.0, 100.0,
|
|
74
|
+
120.0
|
|
75
|
+
]
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
self.parameters = {
|
|
79
|
+
"temperature": temperature,
|
|
80
|
+
"top_p": 1.0,
|
|
81
|
+
"top_k": 32,
|
|
82
|
+
"candidate_count": 1,
|
|
83
|
+
"max_output_tokens": max_output,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
self.generation_config = GenerationConfig(
|
|
87
|
+
temperature=temperature,
|
|
88
|
+
top_p=1.0,
|
|
89
|
+
top_k=10,
|
|
90
|
+
candidate_count=1,
|
|
91
|
+
max_output_tokens=max_output,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# Block none doesn't seem to work
|
|
95
|
+
block_level = HarmBlockThreshold.BLOCK_ONLY_HIGH
|
|
96
|
+
# block_level = HarmBlockThreshold.BLOCK_NONE
|
|
97
|
+
|
|
98
|
+
self.safety_settings = {
|
|
99
|
+
HarmCategory.HARM_CATEGORY_HARASSMENT: block_level,
|
|
100
|
+
HarmCategory.HARM_CATEGORY_HATE_SPEECH: block_level,
|
|
101
|
+
HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: block_level,
|
|
102
|
+
HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: block_level,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
print("Initialise VertexAI...", flush=True)
|
|
106
|
+
|
|
107
|
+
if private_key:
|
|
108
|
+
credentials = service_account.Credentials.from_service_account_file(private_key)
|
|
109
|
+
else:
|
|
110
|
+
credentials = None
|
|
111
|
+
|
|
112
|
+
if credentials:
|
|
113
|
+
vertexai.init(
|
|
114
|
+
location=region,
|
|
115
|
+
credentials=credentials,
|
|
116
|
+
project=credentials.project_id,
|
|
117
|
+
)
|
|
118
|
+
else:
|
|
119
|
+
vertexai.init(
|
|
120
|
+
location=region
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
print(f"Initialise model {model}", flush=True)
|
|
124
|
+
self.llm = GenerativeModel(model)
|
|
125
|
+
self.model = model
|
|
126
|
+
|
|
127
|
+
print("Initialisation complete", flush=True)
|
|
128
|
+
|
|
129
|
+
def handle(self, msg):
|
|
130
|
+
|
|
131
|
+
try:
|
|
132
|
+
|
|
133
|
+
v = msg.value()
|
|
134
|
+
|
|
135
|
+
# Sender-produced ID
|
|
136
|
+
|
|
137
|
+
id = msg.properties()["id"]
|
|
138
|
+
|
|
139
|
+
print(f"Handling prompt {id}...", flush=True)
|
|
140
|
+
|
|
141
|
+
prompt = v.prompt
|
|
142
|
+
|
|
143
|
+
with __class__.text_completion_metric.time():
|
|
144
|
+
|
|
145
|
+
response = self.llm.generate_content(
|
|
146
|
+
prompt, generation_config=self.generation_config,
|
|
147
|
+
safety_settings=self.safety_settings
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
resp = response.text
|
|
151
|
+
inputtokens = int(response.usage_metadata.prompt_token_count)
|
|
152
|
+
outputtokens = int(response.usage_metadata.candidates_token_count)
|
|
153
|
+
print(resp, flush=True)
|
|
154
|
+
print(f"Input Tokens: {inputtokens}", flush=True)
|
|
155
|
+
print(f"Output Tokens: {outputtokens}", flush=True)
|
|
156
|
+
|
|
157
|
+
print("Send response...", flush=True)
|
|
158
|
+
|
|
159
|
+
r = TextCompletionResponse(
|
|
160
|
+
error=None,
|
|
161
|
+
response=resp,
|
|
162
|
+
in_token=inputtokens,
|
|
163
|
+
out_token=outputtokens,
|
|
164
|
+
model=self.model
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
self.producer.send(r, properties={"id": id})
|
|
168
|
+
|
|
169
|
+
print("Done.", flush=True)
|
|
170
|
+
|
|
171
|
+
# Acknowledge successful processing of the message
|
|
172
|
+
self.consumer.acknowledge(msg)
|
|
173
|
+
|
|
174
|
+
except google.api_core.exceptions.ResourceExhausted as e:
|
|
175
|
+
|
|
176
|
+
print("Send rate limit response...", flush=True)
|
|
177
|
+
|
|
178
|
+
r = TextCompletionResponse(
|
|
179
|
+
error=Error(
|
|
180
|
+
type = "rate-limit",
|
|
181
|
+
message = str(e),
|
|
182
|
+
),
|
|
183
|
+
response=None,
|
|
184
|
+
in_token=None,
|
|
185
|
+
out_token=None,
|
|
186
|
+
model=None,
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
self.producer.send(r, properties={"id": id})
|
|
190
|
+
|
|
191
|
+
self.consumer.acknowledge(msg)
|
|
192
|
+
|
|
193
|
+
except Exception as e:
|
|
194
|
+
|
|
195
|
+
print(f"Exception: {e}")
|
|
196
|
+
|
|
197
|
+
print("Send error response...", flush=True)
|
|
198
|
+
|
|
199
|
+
r = TextCompletionResponse(
|
|
200
|
+
error=Error(
|
|
201
|
+
type = "llm-error",
|
|
202
|
+
message = str(e),
|
|
203
|
+
),
|
|
204
|
+
response=None,
|
|
205
|
+
in_token=None,
|
|
206
|
+
out_token=None,
|
|
207
|
+
model=None,
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
self.producer.send(r, properties={"id": id})
|
|
211
|
+
|
|
212
|
+
self.consumer.acknowledge(msg)
|
|
213
|
+
|
|
214
|
+
@staticmethod
|
|
215
|
+
def add_args(parser):
|
|
216
|
+
|
|
217
|
+
ConsumerProducer.add_args(
|
|
218
|
+
parser, default_input_queue, default_subscriber,
|
|
219
|
+
default_output_queue,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
parser.add_argument(
|
|
223
|
+
'-m', '--model',
|
|
224
|
+
default=default_model,
|
|
225
|
+
help=f'LLM model (default: {default_model})'
|
|
226
|
+
)
|
|
227
|
+
# Also: text-bison-32k
|
|
228
|
+
|
|
229
|
+
parser.add_argument(
|
|
230
|
+
'-k', '--private-key',
|
|
231
|
+
help=f'Google Cloud private JSON file'
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
parser.add_argument(
|
|
235
|
+
'-r', '--region',
|
|
236
|
+
default=default_region,
|
|
237
|
+
help=f'Google Cloud region (default: {default_region})',
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
parser.add_argument(
|
|
241
|
+
'-t', '--temperature',
|
|
242
|
+
type=float,
|
|
243
|
+
default=default_temperature,
|
|
244
|
+
help=f'LLM temperature parameter (default: {default_temperature})'
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
parser.add_argument(
|
|
248
|
+
'-x', '--max-output',
|
|
249
|
+
type=int,
|
|
250
|
+
default=default_max_output,
|
|
251
|
+
help=f'LLM max output tokens (default: {default_max_output})'
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
def run():
|
|
255
|
+
|
|
256
|
+
Processor.start(module, __doc__)
|
|
257
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.11.11"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: trustgraph-vertexai
|
|
3
|
+
Version: 0.11.11
|
|
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
|
+
Home-page: https://github.com/trustgraph-ai/trustgraph
|
|
6
|
+
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.11.11.tar.gz
|
|
7
|
+
Author: trustgraph.ai
|
|
8
|
+
Author-email: security@trustgraph.ai
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.8
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: trustgraph-base
|
|
15
|
+
Requires-Dist: pulsar-client
|
|
16
|
+
Requires-Dist: google-cloud-aiplatform
|
|
17
|
+
Requires-Dist: prometheus-client
|
|
18
|
+
|
|
19
|
+
See https://trustgraph.ai/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
scripts/text-completion-vertexai
|
|
4
|
+
trustgraph/vertexai_version.py
|
|
5
|
+
trustgraph/model/text_completion/vertexai/__init__.py
|
|
6
|
+
trustgraph/model/text_completion/vertexai/__main__.py
|
|
7
|
+
trustgraph/model/text_completion/vertexai/llm.py
|
|
8
|
+
trustgraph_vertexai.egg-info/PKG-INFO
|
|
9
|
+
trustgraph_vertexai.egg-info/SOURCES.txt
|
|
10
|
+
trustgraph_vertexai.egg-info/dependency_links.txt
|
|
11
|
+
trustgraph_vertexai.egg-info/requires.txt
|
|
12
|
+
trustgraph_vertexai.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|