trustgraph-base 0.16.3__tar.gz → 0.16.4__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.
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/PKG-INFO +2 -2
- trustgraph-base-0.16.4/trustgraph/api/__init__.py +3 -0
- trustgraph-base-0.16.4/trustgraph/api/api.py +336 -0
- trustgraph-base-0.16.4/trustgraph/base_version.py +1 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph_base.egg-info/PKG-INFO +2 -2
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph_base.egg-info/SOURCES.txt +2 -0
- trustgraph-base-0.16.3/trustgraph/base_version.py +0 -1
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/README.md +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/setup.cfg +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/setup.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/base/__init__.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/base/base_processor.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/base/consumer.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/base/consumer_producer.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/base/producer.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/__init__.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/agent_client.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/base.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/document_embeddings_client.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/document_rag_client.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/embeddings_client.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/graph_embeddings_client.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/graph_rag_client.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/llm_client.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/prompt_client.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/triples_query_client.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/exceptions.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/knowledge/__init__.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/knowledge/defs.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/knowledge/document.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/knowledge/identifier.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/knowledge/organization.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/knowledge/publication.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/log_level.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/objects/__init__.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/objects/field.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/objects/object.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/rdf.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/schema/__init__.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/schema/agent.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/schema/documents.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/schema/graph.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/schema/metadata.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/schema/models.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/schema/object.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/schema/prompt.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/schema/retrieval.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/schema/topic.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/schema/types.py +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph_base.egg-info/dependency_links.txt +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph_base.egg-info/requires.txt +0 -0
- {trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph_base.egg-info/top_level.txt +0 -0
@@ -1,12 +1,12 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: trustgraph-base
|
3
|
-
Version: 0.16.
|
3
|
+
Version: 0.16.4
|
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
6
|
Author: trustgraph.ai
|
7
7
|
Author-email: security@trustgraph.ai
|
8
8
|
License: UNKNOWN
|
9
|
-
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.16.
|
9
|
+
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.16.4.tar.gz
|
10
10
|
Platform: UNKNOWN
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
12
12
|
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
@@ -0,0 +1,336 @@
|
|
1
|
+
|
2
|
+
import requests
|
3
|
+
import json
|
4
|
+
import dataclasses
|
5
|
+
import base64
|
6
|
+
|
7
|
+
from trustgraph.knowledge import hash
|
8
|
+
|
9
|
+
class ProtocolException(Exception):
|
10
|
+
pass
|
11
|
+
|
12
|
+
class ApplicationException(Exception):
|
13
|
+
pass
|
14
|
+
|
15
|
+
class Uri(str):
|
16
|
+
def is_uri(self): return True
|
17
|
+
def is_literal(self): return False
|
18
|
+
|
19
|
+
class Literal(str):
|
20
|
+
def is_uri(self): return False
|
21
|
+
def is_literal(self): return True
|
22
|
+
|
23
|
+
@dataclasses.dataclass
|
24
|
+
class Triple:
|
25
|
+
s : str
|
26
|
+
p : str
|
27
|
+
o : str
|
28
|
+
|
29
|
+
class Api:
|
30
|
+
|
31
|
+
def __init__(self, url="http://localhost:8088/"):
|
32
|
+
|
33
|
+
self.url = url
|
34
|
+
|
35
|
+
if not url.endswith("/"):
|
36
|
+
self.url += "/"
|
37
|
+
|
38
|
+
self.url += "api/v1/"
|
39
|
+
|
40
|
+
def check_error(self, response):
|
41
|
+
|
42
|
+
if "error" in response:
|
43
|
+
|
44
|
+
try:
|
45
|
+
msg = response["error"]["message"]
|
46
|
+
tp = response["error"]["message"]
|
47
|
+
except:
|
48
|
+
raise ApplicationException(
|
49
|
+
"Error, but the error object is broken"
|
50
|
+
)
|
51
|
+
|
52
|
+
raise ApplicationException(f"{tp}: {msg}")
|
53
|
+
|
54
|
+
def text_completion(self, system, prompt):
|
55
|
+
|
56
|
+
# The input consists of system and prompt strings
|
57
|
+
input = {
|
58
|
+
"system": system,
|
59
|
+
"prompt": prompt
|
60
|
+
}
|
61
|
+
|
62
|
+
url = f"{self.url}text-completion"
|
63
|
+
|
64
|
+
# Invoke the API, input is passed as JSON
|
65
|
+
resp = requests.post(url, json=input)
|
66
|
+
|
67
|
+
# Should be a 200 status code
|
68
|
+
if resp.status_code != 200:
|
69
|
+
raise ProtocolException(f"Status code {resp.status_code}")
|
70
|
+
|
71
|
+
try:
|
72
|
+
# Parse the response as JSON
|
73
|
+
object = resp.json()
|
74
|
+
except:
|
75
|
+
raise ProtocolException(f"Expected JSON response")
|
76
|
+
|
77
|
+
self.check_error(resp)
|
78
|
+
|
79
|
+
try:
|
80
|
+
return object["response"]
|
81
|
+
except:
|
82
|
+
raise ProtocolException(f"Response not formatted correctly")
|
83
|
+
|
84
|
+
def agent(self, question):
|
85
|
+
|
86
|
+
# The input consists of a question
|
87
|
+
input = {
|
88
|
+
"question": question
|
89
|
+
}
|
90
|
+
|
91
|
+
url = f"{self.url}agent"
|
92
|
+
|
93
|
+
# Invoke the API, input is passed as JSON
|
94
|
+
resp = requests.post(url, json=input)
|
95
|
+
|
96
|
+
# Should be a 200 status code
|
97
|
+
if resp.status_code != 200:
|
98
|
+
raise ProtocolException(f"Status code {resp.status_code}")
|
99
|
+
|
100
|
+
try:
|
101
|
+
# Parse the response as JSON
|
102
|
+
object = resp.json()
|
103
|
+
except:
|
104
|
+
raise ProtocolException(f"Expected JSON response")
|
105
|
+
|
106
|
+
self.check_error(resp)
|
107
|
+
|
108
|
+
try:
|
109
|
+
return object["answer"]
|
110
|
+
except:
|
111
|
+
raise ProtocolException(f"Response not formatted correctly")
|
112
|
+
|
113
|
+
def graph_rag(self, question):
|
114
|
+
|
115
|
+
# The input consists of a question
|
116
|
+
input = {
|
117
|
+
"query": question
|
118
|
+
}
|
119
|
+
|
120
|
+
url = f"{self.url}graph-rag"
|
121
|
+
|
122
|
+
# Invoke the API, input is passed as JSON
|
123
|
+
resp = requests.post(url, json=input)
|
124
|
+
|
125
|
+
# Should be a 200 status code
|
126
|
+
if resp.status_code != 200:
|
127
|
+
raise ProtocolException(f"Status code {resp.status_code}")
|
128
|
+
|
129
|
+
try:
|
130
|
+
# Parse the response as JSON
|
131
|
+
object = resp.json()
|
132
|
+
except:
|
133
|
+
raise ProtocolException(f"Expected JSON response")
|
134
|
+
|
135
|
+
self.check_error(resp)
|
136
|
+
|
137
|
+
try:
|
138
|
+
return object["response"]
|
139
|
+
except:
|
140
|
+
raise ProtocolException(f"Response not formatted correctly")
|
141
|
+
|
142
|
+
def embeddings(self, text):
|
143
|
+
|
144
|
+
# The input consists of a text block
|
145
|
+
input = {
|
146
|
+
"text": text
|
147
|
+
}
|
148
|
+
|
149
|
+
url = f"{self.url}embeddings"
|
150
|
+
|
151
|
+
# Invoke the API, input is passed as JSON
|
152
|
+
resp = requests.post(url, json=input)
|
153
|
+
|
154
|
+
# Should be a 200 status code
|
155
|
+
if resp.status_code != 200:
|
156
|
+
raise ProtocolException(f"Status code {resp.status_code}")
|
157
|
+
|
158
|
+
try:
|
159
|
+
# Parse the response as JSON
|
160
|
+
object = resp.json()
|
161
|
+
except:
|
162
|
+
raise ProtocolException(f"Expected JSON response")
|
163
|
+
|
164
|
+
self.check_error(resp)
|
165
|
+
|
166
|
+
try:
|
167
|
+
return object["vectors"]
|
168
|
+
except:
|
169
|
+
raise ProtocolException(f"Response not formatted correctly")
|
170
|
+
|
171
|
+
def prompt(self, id, variables):
|
172
|
+
|
173
|
+
# The input consists of system and prompt strings
|
174
|
+
input = {
|
175
|
+
"id": id,
|
176
|
+
"variables": variables
|
177
|
+
}
|
178
|
+
|
179
|
+
url = f"{self.url}prompt"
|
180
|
+
|
181
|
+
# Invoke the API, input is passed as JSON
|
182
|
+
resp = requests.post(url, json=input)
|
183
|
+
|
184
|
+
# Should be a 200 status code
|
185
|
+
if resp.status_code != 200:
|
186
|
+
raise ProtocolException(f"Status code {resp.status_code}")
|
187
|
+
|
188
|
+
try:
|
189
|
+
# Parse the response as JSON
|
190
|
+
object = resp.json()
|
191
|
+
except:
|
192
|
+
raise ProtocolException("Expected JSON response")
|
193
|
+
|
194
|
+
self.check_error(resp)
|
195
|
+
|
196
|
+
if "text" in object:
|
197
|
+
return object["text"]
|
198
|
+
|
199
|
+
if "object" in object:
|
200
|
+
try:
|
201
|
+
return json.loads(object["object"])
|
202
|
+
except Exception as e:
|
203
|
+
raise ProtocolException(
|
204
|
+
"Returned object not well-formed JSON"
|
205
|
+
)
|
206
|
+
|
207
|
+
raise ProtocolException("Response not formatted correctly")
|
208
|
+
|
209
|
+
def triples_query(self, s=None, p=None, o=None, limit=10000):
|
210
|
+
|
211
|
+
# The input consists of system and prompt strings
|
212
|
+
input = {
|
213
|
+
"limit": limit
|
214
|
+
}
|
215
|
+
|
216
|
+
if s: input["s"] = s
|
217
|
+
if p: input["p"] = p
|
218
|
+
if o: input["o"] = o
|
219
|
+
|
220
|
+
url = f"{self.url}triples-query"
|
221
|
+
|
222
|
+
# Invoke the API, input is passed as JSON
|
223
|
+
resp = requests.post(url, json=input)
|
224
|
+
|
225
|
+
# Should be a 200 status code
|
226
|
+
if resp.status_code != 200:
|
227
|
+
raise ProtocolException(f"Status code {resp.status_code}")
|
228
|
+
|
229
|
+
try:
|
230
|
+
# Parse the response as JSON
|
231
|
+
object = resp.json()
|
232
|
+
except:
|
233
|
+
raise ProtocolException("Expected JSON response")
|
234
|
+
|
235
|
+
self.check_error(resp)
|
236
|
+
|
237
|
+
if "response" not in object:
|
238
|
+
raise ProtocolException("Response not formatted correctly")
|
239
|
+
|
240
|
+
def to_value(x):
|
241
|
+
if x["e"]: return Uri(x["v"])
|
242
|
+
return Literal(x["v"])
|
243
|
+
|
244
|
+
return [
|
245
|
+
Triple(
|
246
|
+
s=to_value(t["s"]),
|
247
|
+
p=to_value(t["p"]),
|
248
|
+
o=to_value(t["o"])
|
249
|
+
)
|
250
|
+
for t in object["response"]
|
251
|
+
]
|
252
|
+
|
253
|
+
return object["response"]
|
254
|
+
|
255
|
+
def load_document(self, document, id=None, metadata=None):
|
256
|
+
|
257
|
+
if id is None:
|
258
|
+
|
259
|
+
if metadata is not None:
|
260
|
+
|
261
|
+
# Situation makes no sense. What can the metadata possibly
|
262
|
+
# mean if the caller doesn't know the document ID.
|
263
|
+
# Metadata should relate to the document by ID
|
264
|
+
raise RuntimeError("Can't specify metadata without id")
|
265
|
+
|
266
|
+
id = hash(document)
|
267
|
+
|
268
|
+
triples = []
|
269
|
+
|
270
|
+
def emit(t):
|
271
|
+
triples.append(t)
|
272
|
+
|
273
|
+
if metadata:
|
274
|
+
metadata.emit(
|
275
|
+
lambda t: triples.append({
|
276
|
+
"s": t.s.value,
|
277
|
+
"p": t.p.value,
|
278
|
+
"o": t.o.value
|
279
|
+
})
|
280
|
+
)
|
281
|
+
|
282
|
+
input = {
|
283
|
+
"id": id,
|
284
|
+
"metadata": triples,
|
285
|
+
"data": base64.b64encode(document).decode("utf-8"),
|
286
|
+
}
|
287
|
+
|
288
|
+
url = f"{self.url}load/document"
|
289
|
+
|
290
|
+
# Invoke the API, input is passed as JSON
|
291
|
+
resp = requests.post(url, json=input)
|
292
|
+
|
293
|
+
# Should be a 200 status code
|
294
|
+
if resp.status_code != 200:
|
295
|
+
raise ProtocolException(f"Status code {resp.status_code}")
|
296
|
+
|
297
|
+
def load_text(self, text, id=None, metadata=None, charset="utf-8"):
|
298
|
+
|
299
|
+
if id is None:
|
300
|
+
|
301
|
+
if metadata is not None:
|
302
|
+
|
303
|
+
# Situation makes no sense. What can the metadata possibly
|
304
|
+
# mean if the caller doesn't know the document ID.
|
305
|
+
# Metadata should relate to the document by ID
|
306
|
+
raise RuntimeError("Can't specify metadata without id")
|
307
|
+
|
308
|
+
id = hash(text)
|
309
|
+
|
310
|
+
triples = []
|
311
|
+
|
312
|
+
if metadata:
|
313
|
+
metadata.emit(
|
314
|
+
lambda t: triples.append({
|
315
|
+
"s": t.s.value,
|
316
|
+
"p": t.p.value,
|
317
|
+
"o": t.o.value
|
318
|
+
})
|
319
|
+
)
|
320
|
+
|
321
|
+
input = {
|
322
|
+
"id": id,
|
323
|
+
"metadata": triples,
|
324
|
+
"charset": charset,
|
325
|
+
"text": base64.b64encode(text).decode("utf-8"),
|
326
|
+
}
|
327
|
+
|
328
|
+
url = f"{self.url}load/text"
|
329
|
+
|
330
|
+
# Invoke the API, input is passed as JSON
|
331
|
+
resp = requests.post(url, json=input)
|
332
|
+
|
333
|
+
# Should be a 200 status code
|
334
|
+
if resp.status_code != 200:
|
335
|
+
raise ProtocolException(f"Status code {resp.status_code}")
|
336
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = "0.16.4"
|
@@ -1,12 +1,12 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: trustgraph-base
|
3
|
-
Version: 0.16.
|
3
|
+
Version: 0.16.4
|
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
6
|
Author: trustgraph.ai
|
7
7
|
Author-email: security@trustgraph.ai
|
8
8
|
License: UNKNOWN
|
9
|
-
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.16.
|
9
|
+
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.16.4.tar.gz
|
10
10
|
Platform: UNKNOWN
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
12
12
|
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
@@ -1 +0,0 @@
|
|
1
|
-
__version__ = "0.16.3"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/document_embeddings_client.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/graph_embeddings_client.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph/clients/triples_query_client.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{trustgraph-base-0.16.3 → trustgraph-base-0.16.4}/trustgraph_base.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|