trustgraph-base 0.23.10__tar.gz → 0.23.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.
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/PKG-INFO +2 -2
- trustgraph-base-0.23.11/trustgraph/api/api.py +69 -0
- trustgraph-base-0.23.11/trustgraph/api/config.py +97 -0
- trustgraph-base-0.23.11/trustgraph/api/exceptions.py +6 -0
- trustgraph-base-0.23.10/trustgraph/api/api.py → trustgraph-base-0.23.11/trustgraph/api/flow.py +58 -192
- trustgraph-base-0.23.11/trustgraph/api/library.py +259 -0
- trustgraph-base-0.23.11/trustgraph/api/types.py +42 -0
- trustgraph-base-0.23.11/trustgraph/base_version.py +1 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph_base.egg-info/PKG-INFO +2 -2
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph_base.egg-info/SOURCES.txt +5 -0
- trustgraph-base-0.23.10/trustgraph/base_version.py +0 -1
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/README.md +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/setup.cfg +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/setup.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/api/__init__.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/__init__.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/agent_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/agent_service.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/async_processor.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/consumer.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/consumer_spec.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/document_embeddings_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/document_embeddings_query_service.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/document_embeddings_store_service.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/embeddings_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/embeddings_service.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/flow.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/flow_processor.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/graph_embeddings_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/graph_embeddings_query_service.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/graph_embeddings_store_service.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/graph_rag_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/llm_service.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/metrics.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/producer.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/producer_spec.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/prompt_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/publisher.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/pubsub.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/request_response_spec.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/setting_spec.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/spec.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/subscriber.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/subscriber_spec.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/text_completion_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/triples_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/triples_query_service.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/triples_store_service.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/__init__.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/agent_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/base.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/config_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/document_embeddings_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/document_rag_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/embeddings_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/graph_embeddings_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/graph_rag_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/llm_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/prompt_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/triples_query_client.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/exceptions.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/knowledge/__init__.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/knowledge/defs.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/knowledge/document.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/knowledge/identifier.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/knowledge/organization.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/knowledge/publication.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/log_level.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/objects/__init__.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/objects/field.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/objects/object.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/rdf.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/__init__.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/agent.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/config.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/documents.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/flows.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/graph.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/library.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/lookup.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/metadata.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/models.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/object.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/prompt.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/retrieval.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/topic.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/schema/types.py +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph_base.egg-info/dependency_links.txt +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph_base.egg-info/requires.txt +0 -0
- {trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph_base.egg-info/top_level.txt +0 -0
@@ -1,9 +1,9 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: trustgraph-base
|
3
|
-
Version: 0.23.
|
3
|
+
Version: 0.23.11
|
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.23.
|
6
|
+
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.23.11.tar.gz
|
7
7
|
Author: trustgraph.ai
|
8
8
|
Author-email: security@trustgraph.ai
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
@@ -0,0 +1,69 @@
|
|
1
|
+
|
2
|
+
import requests
|
3
|
+
import json
|
4
|
+
import base64
|
5
|
+
import time
|
6
|
+
|
7
|
+
from . library import Library
|
8
|
+
from . flow import Flow
|
9
|
+
from . config import Config
|
10
|
+
from . exceptions import *
|
11
|
+
from . types import *
|
12
|
+
|
13
|
+
def check_error(response):
|
14
|
+
|
15
|
+
if "error" in response:
|
16
|
+
|
17
|
+
try:
|
18
|
+
msg = response["error"]["message"]
|
19
|
+
tp = response["error"]["type"]
|
20
|
+
except:
|
21
|
+
raise ApplicationException(response["error"])
|
22
|
+
|
23
|
+
raise ApplicationException(f"{tp}: {msg}")
|
24
|
+
|
25
|
+
class Api:
|
26
|
+
|
27
|
+
def __init__(self, url="http://localhost:8088/"):
|
28
|
+
|
29
|
+
self.url = url
|
30
|
+
|
31
|
+
if not url.endswith("/"):
|
32
|
+
self.url += "/"
|
33
|
+
|
34
|
+
self.url += "api/v1/"
|
35
|
+
|
36
|
+
def flow(self):
|
37
|
+
return Flow(api=self)
|
38
|
+
|
39
|
+
def config(self):
|
40
|
+
return Config(api=self)
|
41
|
+
|
42
|
+
def request(self, path, request):
|
43
|
+
|
44
|
+
url = f"{self.url}{path}"
|
45
|
+
|
46
|
+
# print("uri:", url)
|
47
|
+
# print(json.dumps(request, indent=4))
|
48
|
+
|
49
|
+
# Invoke the API, input is passed as JSON
|
50
|
+
resp = requests.post(url, json=request)
|
51
|
+
|
52
|
+
# Should be a 200 status code
|
53
|
+
if resp.status_code != 200:
|
54
|
+
raise ProtocolException(f"Status code {resp.status_code}")
|
55
|
+
|
56
|
+
# print(resp.text)
|
57
|
+
|
58
|
+
try:
|
59
|
+
# Parse the response as JSON
|
60
|
+
object = resp.json()
|
61
|
+
except:
|
62
|
+
raise ProtocolException(f"Expected JSON response")
|
63
|
+
|
64
|
+
check_error(object)
|
65
|
+
|
66
|
+
return object
|
67
|
+
|
68
|
+
def library(self):
|
69
|
+
return Library(self)
|
@@ -0,0 +1,97 @@
|
|
1
|
+
|
2
|
+
from . exceptions import *
|
3
|
+
from . types import ConfigValue
|
4
|
+
|
5
|
+
class Config:
|
6
|
+
|
7
|
+
def __init__(self, api):
|
8
|
+
self.api = api
|
9
|
+
|
10
|
+
def request(self, request):
|
11
|
+
return self.api.request("config", request)
|
12
|
+
|
13
|
+
def get(self, keys):
|
14
|
+
|
15
|
+
# The input consists of system and prompt strings
|
16
|
+
input = {
|
17
|
+
"operation": "get",
|
18
|
+
"keys": [
|
19
|
+
{ "type": k.type, "key": k.key }
|
20
|
+
for k in keys
|
21
|
+
]
|
22
|
+
}
|
23
|
+
|
24
|
+
object = self.request(input)
|
25
|
+
|
26
|
+
try:
|
27
|
+
return [
|
28
|
+
ConfigValue(
|
29
|
+
type = v["type"],
|
30
|
+
key = v["key"],
|
31
|
+
value = v["value"]
|
32
|
+
)
|
33
|
+
for v in object["values"]
|
34
|
+
]
|
35
|
+
except Exception as e:
|
36
|
+
print(e)
|
37
|
+
raise ProtocolException("Response not formatted correctly")
|
38
|
+
|
39
|
+
def put(self, values):
|
40
|
+
|
41
|
+
# The input consists of system and prompt strings
|
42
|
+
input = {
|
43
|
+
"operation": "put",
|
44
|
+
"values": [
|
45
|
+
{ "type": v.type, "key": v.key, "value": v.value }
|
46
|
+
for v in values
|
47
|
+
]
|
48
|
+
}
|
49
|
+
|
50
|
+
self.request(input)
|
51
|
+
|
52
|
+
def list(self, type):
|
53
|
+
|
54
|
+
# The input consists of system and prompt strings
|
55
|
+
input = {
|
56
|
+
"operation": "list",
|
57
|
+
"type": type,
|
58
|
+
}
|
59
|
+
|
60
|
+
return self.request(input)["directory"]
|
61
|
+
|
62
|
+
def get_values(self, type):
|
63
|
+
|
64
|
+
# The input consists of system and prompt strings
|
65
|
+
input = {
|
66
|
+
"operation": "getvalues",
|
67
|
+
"type": type,
|
68
|
+
}
|
69
|
+
|
70
|
+
object = self.request(input)["directory"]
|
71
|
+
|
72
|
+
try:
|
73
|
+
return [
|
74
|
+
ConfigValue(
|
75
|
+
type = v["type"],
|
76
|
+
key = v["key"],
|
77
|
+
value = v["value"]
|
78
|
+
)
|
79
|
+
for v in object["values"]
|
80
|
+
]
|
81
|
+
except:
|
82
|
+
raise ProtocolException(f"Response not formatted correctly")
|
83
|
+
|
84
|
+
def all(self):
|
85
|
+
|
86
|
+
# The input consists of system and prompt strings
|
87
|
+
input = {
|
88
|
+
"operation": "config"
|
89
|
+
}
|
90
|
+
|
91
|
+
object = self.request(input)
|
92
|
+
|
93
|
+
try:
|
94
|
+
return object["config"], object["version"]
|
95
|
+
except:
|
96
|
+
raise ProtocolException(f"Response not formatted correctly")
|
97
|
+
|
trustgraph-base-0.23.10/trustgraph/api/api.py → trustgraph-base-0.23.11/trustgraph/api/flow.py
RENAMED
@@ -1,175 +1,41 @@
|
|
1
1
|
|
2
|
-
import requests
|
3
2
|
import json
|
4
|
-
import dataclasses
|
5
3
|
import base64
|
6
4
|
|
7
|
-
from
|
5
|
+
from .. knowledge import hash, Uri, Literal
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
def to_value(x):
|
8
|
+
if x["e"]: return Uri(x["v"])
|
9
|
+
return Literal(x["v"])
|
11
10
|
|
12
|
-
class
|
13
|
-
pass
|
14
|
-
|
15
|
-
@dataclasses.dataclass
|
16
|
-
class Triple:
|
17
|
-
s : str
|
18
|
-
p : str
|
19
|
-
o : str
|
20
|
-
|
21
|
-
@dataclasses.dataclass
|
22
|
-
class ConfigKey:
|
23
|
-
type : str
|
24
|
-
key : str
|
25
|
-
|
26
|
-
@dataclasses.dataclass
|
27
|
-
class ConfigValue:
|
28
|
-
type : str
|
29
|
-
key : str
|
30
|
-
value : str
|
31
|
-
|
32
|
-
def check_error(response):
|
33
|
-
|
34
|
-
if "error" in response:
|
35
|
-
|
36
|
-
try:
|
37
|
-
msg = response["error"]["message"]
|
38
|
-
tp = response["error"]["type"]
|
39
|
-
except:
|
40
|
-
raise ApplicationException(response["error"])
|
41
|
-
|
42
|
-
raise ApplicationException(f"{tp}: {msg}")
|
43
|
-
|
44
|
-
class Api:
|
45
|
-
|
46
|
-
def __init__(self, url="http://localhost:8088/"):
|
47
|
-
|
48
|
-
self.url = url
|
49
|
-
|
50
|
-
if not url.endswith("/"):
|
51
|
-
self.url += "/"
|
52
|
-
|
53
|
-
self.url += "api/v1/"
|
54
|
-
|
55
|
-
def flow(self, flow="0000"):
|
56
|
-
return Flow(api=self, flow=flow)
|
57
|
-
|
58
|
-
def request(self, path, request):
|
59
|
-
|
60
|
-
url = f"{self.url}{path}"
|
61
|
-
|
62
|
-
# Invoke the API, input is passed as JSON
|
63
|
-
resp = requests.post(url, json=request)
|
64
|
-
|
65
|
-
# Should be a 200 status code
|
66
|
-
if resp.status_code != 200:
|
67
|
-
raise ProtocolException(f"Status code {resp.status_code}")
|
68
|
-
|
69
|
-
try:
|
70
|
-
# Parse the response as JSON
|
71
|
-
object = resp.json()
|
72
|
-
except:
|
73
|
-
raise ProtocolException(f"Expected JSON response")
|
74
|
-
|
75
|
-
check_error(object)
|
76
|
-
|
77
|
-
return object
|
78
|
-
|
79
|
-
def config_all(self):
|
80
|
-
|
81
|
-
# The input consists of system and prompt strings
|
82
|
-
input = {
|
83
|
-
"operation": "config"
|
84
|
-
}
|
85
|
-
|
86
|
-
object = self.request("config", input)
|
87
|
-
|
88
|
-
try:
|
89
|
-
return object["config"], object["version"]
|
90
|
-
except:
|
91
|
-
raise ProtocolException(f"Response not formatted correctly")
|
92
|
-
|
93
|
-
def config_get(self, keys):
|
94
|
-
|
95
|
-
# The input consists of system and prompt strings
|
96
|
-
input = {
|
97
|
-
"operation": "get",
|
98
|
-
"keys": [
|
99
|
-
{ "type": k.type, "key": k.key }
|
100
|
-
for k in keys
|
101
|
-
]
|
102
|
-
}
|
103
|
-
|
104
|
-
object = self.request("config", input)
|
105
|
-
|
106
|
-
try:
|
107
|
-
return [
|
108
|
-
ConfigValue(
|
109
|
-
type = v["type"],
|
110
|
-
key = v["key"],
|
111
|
-
value = v["value"]
|
112
|
-
)
|
113
|
-
for v in object["values"]
|
114
|
-
]
|
115
|
-
except:
|
116
|
-
raise ProtocolException(f"Response not formatted correctly")
|
117
|
-
|
118
|
-
def config_put(self, values):
|
119
|
-
|
120
|
-
# The input consists of system and prompt strings
|
121
|
-
input = {
|
122
|
-
"operation": "put",
|
123
|
-
"values": [
|
124
|
-
{ "type": v.type, "key": v.key, "value": v.value }
|
125
|
-
for v in values
|
126
|
-
]
|
127
|
-
}
|
128
|
-
|
129
|
-
self.request("config", input)
|
130
|
-
|
131
|
-
def config_list(self, type):
|
132
|
-
|
133
|
-
# The input consists of system and prompt strings
|
134
|
-
input = {
|
135
|
-
"operation": "list",
|
136
|
-
"type": type,
|
137
|
-
}
|
11
|
+
class Flow:
|
138
12
|
|
139
|
-
|
13
|
+
def __init__(self, api):
|
14
|
+
self.api = api
|
140
15
|
|
141
|
-
def
|
16
|
+
def request(self, path=None, request=None):
|
142
17
|
|
143
|
-
|
144
|
-
|
145
|
-
"operation": "getvalues",
|
146
|
-
"type": type,
|
147
|
-
}
|
18
|
+
if request is None:
|
19
|
+
raise RuntimeError("request must be specified")
|
148
20
|
|
149
|
-
|
21
|
+
if path:
|
22
|
+
return self.api.request(f"flow/{path}", request)
|
23
|
+
else:
|
24
|
+
return self.api.request(f"flow", request)
|
150
25
|
|
151
|
-
|
152
|
-
|
153
|
-
ConfigValue(
|
154
|
-
type = v["type"],
|
155
|
-
key = v["key"],
|
156
|
-
value = v["value"]
|
157
|
-
)
|
158
|
-
for v in object["values"]
|
159
|
-
]
|
160
|
-
except:
|
161
|
-
raise ProtocolException(f"Response not formatted correctly")
|
26
|
+
def id(self, id="0000"):
|
27
|
+
return FlowInstance(api=self, id=id)
|
162
28
|
|
163
|
-
def
|
29
|
+
def list_classes(self):
|
164
30
|
|
165
31
|
# The input consists of system and prompt strings
|
166
32
|
input = {
|
167
33
|
"operation": "list-classes",
|
168
34
|
}
|
169
35
|
|
170
|
-
return self.request(
|
36
|
+
return self.request(request = input)["class-names"]
|
171
37
|
|
172
|
-
def
|
38
|
+
def get_class(self, class_name):
|
173
39
|
|
174
40
|
# The input consists of system and prompt strings
|
175
41
|
input = {
|
@@ -177,9 +43,9 @@ class Api:
|
|
177
43
|
"class-name": class_name,
|
178
44
|
}
|
179
45
|
|
180
|
-
return json.loads(self.request(
|
46
|
+
return json.loads(self.request(request = input)["class-definition"])
|
181
47
|
|
182
|
-
def
|
48
|
+
def put_class(self, class_name, definition):
|
183
49
|
|
184
50
|
# The input consists of system and prompt strings
|
185
51
|
input = {
|
@@ -188,9 +54,9 @@ class Api:
|
|
188
54
|
"class-definition": json.dumps(definition),
|
189
55
|
}
|
190
56
|
|
191
|
-
self.request(
|
57
|
+
self.request(request = input)
|
192
58
|
|
193
|
-
def
|
59
|
+
def delete_class(self, class_name):
|
194
60
|
|
195
61
|
# The input consists of system and prompt strings
|
196
62
|
input = {
|
@@ -198,18 +64,18 @@ class Api:
|
|
198
64
|
"class-name": class_name,
|
199
65
|
}
|
200
66
|
|
201
|
-
self.request(
|
67
|
+
self.request(request = input)
|
202
68
|
|
203
|
-
def
|
69
|
+
def list(self):
|
204
70
|
|
205
71
|
# The input consists of system and prompt strings
|
206
72
|
input = {
|
207
73
|
"operation": "list-flows",
|
208
74
|
}
|
209
75
|
|
210
|
-
return self.request(
|
76
|
+
return self.request(request = input)["flow-ids"]
|
211
77
|
|
212
|
-
def
|
78
|
+
def get(self, id):
|
213
79
|
|
214
80
|
# The input consists of system and prompt strings
|
215
81
|
input = {
|
@@ -217,9 +83,9 @@ class Api:
|
|
217
83
|
"flow-id": id,
|
218
84
|
}
|
219
85
|
|
220
|
-
return json.loads(self.request(
|
86
|
+
return json.loads(self.request(request = input)["flow"])
|
221
87
|
|
222
|
-
def
|
88
|
+
def start(self, class_name, id, description):
|
223
89
|
|
224
90
|
# The input consists of system and prompt strings
|
225
91
|
input = {
|
@@ -229,9 +95,9 @@ class Api:
|
|
229
95
|
"description": description,
|
230
96
|
}
|
231
97
|
|
232
|
-
self.request(
|
98
|
+
self.request(request = input)
|
233
99
|
|
234
|
-
def
|
100
|
+
def stop(self, id):
|
235
101
|
|
236
102
|
# The input consists of system and prompt strings
|
237
103
|
input = {
|
@@ -239,13 +105,17 @@ class Api:
|
|
239
105
|
"flow-id": id,
|
240
106
|
}
|
241
107
|
|
242
|
-
self.request(
|
243
|
-
|
244
|
-
class
|
108
|
+
self.request(request = input)
|
109
|
+
|
110
|
+
class FlowInstance:
|
245
111
|
|
246
|
-
def __init__(self, api,
|
112
|
+
def __init__(self, api, id):
|
247
113
|
self.api = api
|
248
|
-
self.
|
114
|
+
self.id = id
|
115
|
+
|
116
|
+
def request(self, path, request):
|
117
|
+
|
118
|
+
return self.api.request(path = f"{self.id}/{path}", request = request)
|
249
119
|
|
250
120
|
def text_completion(self, system, prompt):
|
251
121
|
|
@@ -255,8 +125,8 @@ class Flow:
|
|
255
125
|
"prompt": prompt
|
256
126
|
}
|
257
127
|
|
258
|
-
return self.
|
259
|
-
|
128
|
+
return self.request(
|
129
|
+
"service/text-completion",
|
260
130
|
input
|
261
131
|
)["response"]
|
262
132
|
|
@@ -267,8 +137,8 @@ class Flow:
|
|
267
137
|
"question": question
|
268
138
|
}
|
269
139
|
|
270
|
-
return self.
|
271
|
-
|
140
|
+
return self.request(
|
141
|
+
"service/agent",
|
272
142
|
input
|
273
143
|
)["answer"]
|
274
144
|
|
@@ -289,8 +159,8 @@ class Flow:
|
|
289
159
|
"max-path-length": max_path_length,
|
290
160
|
}
|
291
161
|
|
292
|
-
return self.
|
293
|
-
|
162
|
+
return self.request(
|
163
|
+
"service/graph-rag",
|
294
164
|
input
|
295
165
|
)["response"]
|
296
166
|
|
@@ -307,8 +177,8 @@ class Flow:
|
|
307
177
|
"doc-limit": doc_limit,
|
308
178
|
}
|
309
179
|
|
310
|
-
return self.
|
311
|
-
|
180
|
+
return self.request(
|
181
|
+
"service/document-rag",
|
312
182
|
input
|
313
183
|
)["response"]
|
314
184
|
|
@@ -319,8 +189,8 @@ class Flow:
|
|
319
189
|
"text": text
|
320
190
|
}
|
321
191
|
|
322
|
-
return self.
|
323
|
-
|
192
|
+
return self.request(
|
193
|
+
"service/embeddings",
|
324
194
|
input
|
325
195
|
)["vectors"]
|
326
196
|
|
@@ -332,8 +202,8 @@ class Flow:
|
|
332
202
|
"variables": variables
|
333
203
|
}
|
334
204
|
|
335
|
-
object = self.
|
336
|
-
|
205
|
+
object = self.request(
|
206
|
+
"service/prompt",
|
337
207
|
input
|
338
208
|
)
|
339
209
|
|
@@ -381,15 +251,11 @@ class Flow:
|
|
381
251
|
raise RuntimeError("o must be Uri or Literal")
|
382
252
|
input["o"] = { "v": str(o), "e": isinstance(o, Uri), }
|
383
253
|
|
384
|
-
object = self.
|
385
|
-
|
254
|
+
object = self.request(
|
255
|
+
"service/triples",
|
386
256
|
input
|
387
257
|
)
|
388
258
|
|
389
|
-
def to_value(x):
|
390
|
-
if x["e"]: return Uri(x["v"])
|
391
|
-
return Literal(x["v"])
|
392
|
-
|
393
259
|
return [
|
394
260
|
Triple(
|
395
261
|
s=to_value(t["s"]),
|
@@ -441,8 +307,8 @@ class Flow:
|
|
441
307
|
if collection:
|
442
308
|
input["collection"] = collection
|
443
309
|
|
444
|
-
return self.
|
445
|
-
|
310
|
+
return self.request(
|
311
|
+
"service/document-load",
|
446
312
|
input
|
447
313
|
)
|
448
314
|
|
@@ -486,8 +352,8 @@ class Flow:
|
|
486
352
|
if collection:
|
487
353
|
input["collection"] = collection
|
488
354
|
|
489
|
-
return self.
|
490
|
-
|
355
|
+
return self.request(
|
356
|
+
"service/text-load",
|
491
357
|
input
|
492
358
|
)
|
493
359
|
|
@@ -0,0 +1,259 @@
|
|
1
|
+
|
2
|
+
import datetime
|
3
|
+
import time
|
4
|
+
import base64
|
5
|
+
|
6
|
+
from . types import DocumentMetadata, ProcessingMetadata, Triple
|
7
|
+
from .. knowledge import hash, Uri, Literal
|
8
|
+
from . exceptions import *
|
9
|
+
|
10
|
+
def to_value(x):
|
11
|
+
if x["e"]: return Uri(x["v"])
|
12
|
+
return Literal(x["v"])
|
13
|
+
|
14
|
+
class Library:
|
15
|
+
|
16
|
+
def __init__(self, api):
|
17
|
+
self.api = api
|
18
|
+
|
19
|
+
def request(self, request):
|
20
|
+
return self.api.request(f"librarian", request)
|
21
|
+
|
22
|
+
def add_document(
|
23
|
+
self, document, id, metadata, user, title, comments,
|
24
|
+
kind="text/plain", tags=[],
|
25
|
+
):
|
26
|
+
|
27
|
+
if id is None:
|
28
|
+
|
29
|
+
if metadata is not None:
|
30
|
+
|
31
|
+
# Situation makes no sense. What can the metadata possibly
|
32
|
+
# mean if the caller doesn't know the document ID.
|
33
|
+
# Metadata should relate to the document by ID
|
34
|
+
raise RuntimeError("Can't specify metadata without id")
|
35
|
+
|
36
|
+
id = hash(document)
|
37
|
+
|
38
|
+
if not title: title = ""
|
39
|
+
if not comments: comments = ""
|
40
|
+
|
41
|
+
triples = []
|
42
|
+
|
43
|
+
def emit(t):
|
44
|
+
triples.append(t)
|
45
|
+
|
46
|
+
if metadata:
|
47
|
+
metadata.emit(
|
48
|
+
lambda t: triples.append({
|
49
|
+
"s": { "v": t["s"], "e": isinstance(t["s"], Uri) },
|
50
|
+
"p": { "v": t["p"], "e": isinstance(t["p"], Uri) },
|
51
|
+
"o": { "v": t["o"], "e": isinstance(t["o"], Uri) }
|
52
|
+
})
|
53
|
+
)
|
54
|
+
|
55
|
+
input = {
|
56
|
+
"operation": "add-document",
|
57
|
+
"document-metadata": {
|
58
|
+
"id": id,
|
59
|
+
"time": int(time.time()),
|
60
|
+
"kind": kind,
|
61
|
+
"title": title,
|
62
|
+
"comments": comments,
|
63
|
+
"metadata": triples,
|
64
|
+
"user": user,
|
65
|
+
"tags": tags
|
66
|
+
},
|
67
|
+
"content": base64.b64encode(document).decode("utf-8"),
|
68
|
+
}
|
69
|
+
|
70
|
+
return self.request(input)
|
71
|
+
|
72
|
+
def get_documents(self, user):
|
73
|
+
|
74
|
+
input = {
|
75
|
+
"operation": "list-documents",
|
76
|
+
"user": user,
|
77
|
+
}
|
78
|
+
|
79
|
+
object = self.request(input)
|
80
|
+
|
81
|
+
try:
|
82
|
+
return [
|
83
|
+
DocumentMetadata(
|
84
|
+
id = v["id"],
|
85
|
+
time = datetime.datetime.fromtimestamp(v["time"]),
|
86
|
+
kind = v["kind"],
|
87
|
+
title = v["title"],
|
88
|
+
comments = v.get("comments", ""),
|
89
|
+
metadata = [
|
90
|
+
Triple(
|
91
|
+
s = to_value(w["s"]),
|
92
|
+
p = to_value(w["p"]),
|
93
|
+
o = to_value(w["o"])
|
94
|
+
)
|
95
|
+
for w in v["metadata"]
|
96
|
+
],
|
97
|
+
user = v["user"],
|
98
|
+
tags = v["tags"]
|
99
|
+
)
|
100
|
+
for v in object["document-metadatas"]
|
101
|
+
]
|
102
|
+
except Exception as e:
|
103
|
+
print(e)
|
104
|
+
raise ProtocolException(f"Response not formatted correctly")
|
105
|
+
|
106
|
+
def get_document(self, user, id):
|
107
|
+
|
108
|
+
input = {
|
109
|
+
"operation": "get-document",
|
110
|
+
"user": user,
|
111
|
+
"document-id": id,
|
112
|
+
}
|
113
|
+
|
114
|
+
object = self.request(input)
|
115
|
+
doc = object["document-metadata"]
|
116
|
+
|
117
|
+
try:
|
118
|
+
DocumentMetadata(
|
119
|
+
id = doc["id"],
|
120
|
+
time = datetime.datetime.fromtimestamp(doc["time"]),
|
121
|
+
kind = doc["kind"],
|
122
|
+
title = doc["title"],
|
123
|
+
comments = doc.get("comments", ""),
|
124
|
+
metadata = [
|
125
|
+
Triple(
|
126
|
+
s = to_value(w["s"]),
|
127
|
+
p = to_value(w["p"]),
|
128
|
+
o = to_value(w["o"])
|
129
|
+
)
|
130
|
+
for w in doc["metadata"]
|
131
|
+
],
|
132
|
+
user = doc["user"],
|
133
|
+
tags = doc["tags"]
|
134
|
+
)
|
135
|
+
except Exception as e:
|
136
|
+
print(e)
|
137
|
+
raise ProtocolException(f"Response not formatted correctly")
|
138
|
+
|
139
|
+
def update_document(self, user, id, metadata):
|
140
|
+
|
141
|
+
input = {
|
142
|
+
"operation": "update-document",
|
143
|
+
"document-metadata": {
|
144
|
+
"user": user,
|
145
|
+
"document-id": id,
|
146
|
+
"time": metadata.time,
|
147
|
+
"title": metadata.title,
|
148
|
+
"comments": metadata.comments,
|
149
|
+
"metadata": [
|
150
|
+
{
|
151
|
+
"s": { "v": t["s"], "e": isinstance(t["s"], Uri) },
|
152
|
+
"p": { "v": t["p"], "e": isinstance(t["p"], Uri) },
|
153
|
+
"o": { "v": t["o"], "e": isinstance(t["o"], Uri) }
|
154
|
+
}
|
155
|
+
for t in metadata.metadata
|
156
|
+
],
|
157
|
+
"tags": metadata.tags,
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
object = self.request(input)
|
162
|
+
doc = object["document-metadata"]
|
163
|
+
|
164
|
+
try:
|
165
|
+
DocumentMetadata(
|
166
|
+
id = doc["id"],
|
167
|
+
time = datetime.datetime.fromtimestamp(doc["time"]),
|
168
|
+
kind = doc["kind"],
|
169
|
+
title = doc["title"],
|
170
|
+
comments = doc.get("comments", ""),
|
171
|
+
metadata = [
|
172
|
+
Triple(
|
173
|
+
s = to_value(w["s"]),
|
174
|
+
p = to_value(w["p"]),
|
175
|
+
o = to_value(w["o"])
|
176
|
+
)
|
177
|
+
for w in doc["metadata"]
|
178
|
+
],
|
179
|
+
user = doc["user"],
|
180
|
+
tags = doc["tags"]
|
181
|
+
)
|
182
|
+
except Exception as e:
|
183
|
+
print(e)
|
184
|
+
raise ProtocolException(f"Response not formatted correctly")
|
185
|
+
|
186
|
+
def remove_document(self, user, id):
|
187
|
+
|
188
|
+
input = {
|
189
|
+
"operation": "remove-document",
|
190
|
+
"user": user,
|
191
|
+
"document-id": id,
|
192
|
+
}
|
193
|
+
|
194
|
+
object = self.request(input)
|
195
|
+
|
196
|
+
return {}
|
197
|
+
|
198
|
+
def start_processing(
|
199
|
+
self, id, document_id, flow="0000",
|
200
|
+
user="trustgraph", collection="default", tags=[],
|
201
|
+
):
|
202
|
+
|
203
|
+
input = {
|
204
|
+
"operation": "add-processing",
|
205
|
+
"processing-metadata": {
|
206
|
+
"id": id,
|
207
|
+
"document-id": document_id,
|
208
|
+
"time": int(time.time()),
|
209
|
+
"flow": flow,
|
210
|
+
"user": user,
|
211
|
+
"collection": collection,
|
212
|
+
"tags": tags,
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
object = self.request(input)
|
217
|
+
|
218
|
+
return {}
|
219
|
+
|
220
|
+
def stop_processing(
|
221
|
+
self, id, user="trustgraph",
|
222
|
+
):
|
223
|
+
|
224
|
+
input = {
|
225
|
+
"operation": "remove-processing",
|
226
|
+
"processing-id": id,
|
227
|
+
"user": user,
|
228
|
+
}
|
229
|
+
|
230
|
+
object = self.request(input)
|
231
|
+
|
232
|
+
return {}
|
233
|
+
|
234
|
+
def get_processings(self, user="trustgraph"):
|
235
|
+
|
236
|
+
input = {
|
237
|
+
"operation": "list-processing",
|
238
|
+
"user": user,
|
239
|
+
}
|
240
|
+
|
241
|
+
object = self.request(input)
|
242
|
+
|
243
|
+
try:
|
244
|
+
return [
|
245
|
+
ProcessingMetadata(
|
246
|
+
id = v["id"],
|
247
|
+
document_id = v["document-id"],
|
248
|
+
time = datetime.datetime.fromtimestamp(v["time"]),
|
249
|
+
flow = v["flow"],
|
250
|
+
user = v["user"],
|
251
|
+
collection = v["collection"],
|
252
|
+
tags = v["tags"],
|
253
|
+
)
|
254
|
+
for v in object["processing-metadatas"]
|
255
|
+
]
|
256
|
+
except Exception as e:
|
257
|
+
print(e)
|
258
|
+
raise ProtocolException(f"Response not formatted correctly")
|
259
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
import dataclasses
|
3
|
+
import datetime
|
4
|
+
from typing import List
|
5
|
+
|
6
|
+
@dataclasses.dataclass
|
7
|
+
class Triple:
|
8
|
+
s : str
|
9
|
+
p : str
|
10
|
+
o : str
|
11
|
+
|
12
|
+
@dataclasses.dataclass
|
13
|
+
class ConfigKey:
|
14
|
+
type : str
|
15
|
+
key : str
|
16
|
+
|
17
|
+
@dataclasses.dataclass
|
18
|
+
class ConfigValue:
|
19
|
+
type : str
|
20
|
+
key : str
|
21
|
+
value : str
|
22
|
+
|
23
|
+
@dataclasses.dataclass
|
24
|
+
class DocumentMetadata:
|
25
|
+
id : str
|
26
|
+
time : datetime.datetime
|
27
|
+
kind : str
|
28
|
+
title : str
|
29
|
+
comments : str
|
30
|
+
metadata : List[Triple]
|
31
|
+
user : str
|
32
|
+
tags : List[str]
|
33
|
+
|
34
|
+
@dataclasses.dataclass
|
35
|
+
class ProcessingMetadata:
|
36
|
+
id : str
|
37
|
+
document_id : str
|
38
|
+
time : datetime.datetime
|
39
|
+
flow : str
|
40
|
+
user : str
|
41
|
+
collection : str
|
42
|
+
tags : List[str]
|
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = "0.23.11"
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: trustgraph-base
|
3
|
-
Version: 0.23.
|
3
|
+
Version: 0.23.11
|
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.23.
|
6
|
+
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.23.11.tar.gz
|
7
7
|
Author: trustgraph.ai
|
8
8
|
Author-email: security@trustgraph.ai
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
@@ -6,6 +6,11 @@ trustgraph/log_level.py
|
|
6
6
|
trustgraph/rdf.py
|
7
7
|
trustgraph/api/__init__.py
|
8
8
|
trustgraph/api/api.py
|
9
|
+
trustgraph/api/config.py
|
10
|
+
trustgraph/api/exceptions.py
|
11
|
+
trustgraph/api/flow.py
|
12
|
+
trustgraph/api/library.py
|
13
|
+
trustgraph/api/types.py
|
9
14
|
trustgraph/base/__init__.py
|
10
15
|
trustgraph/base/agent_client.py
|
11
16
|
trustgraph/base/agent_service.py
|
@@ -1 +0,0 @@
|
|
1
|
-
__version__ = "0.23.10"
|
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.23.10 → trustgraph-base-0.23.11}/trustgraph/base/document_embeddings_client.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/graph_embeddings_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
|
{trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/request_response_spec.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/text_completion_client.py
RENAMED
File without changes
|
File without changes
|
{trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/triples_query_service.py
RENAMED
File without changes
|
{trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/base/triples_store_service.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/document_embeddings_client.py
RENAMED
File without changes
|
{trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/document_rag_client.py
RENAMED
File without changes
|
File without changes
|
{trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph/clients/graph_embeddings_client.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{trustgraph-base-0.23.10 → trustgraph-base-0.23.11}/trustgraph_base.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|