trustgraph-base 0.23.17__tar.gz → 1.7.1__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-base might be problematic. Click here for more details.

Files changed (160) hide show
  1. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/PKG-INFO +7 -7
  2. trustgraph_base-1.7.1/pyproject.toml +29 -0
  3. trustgraph_base-1.7.1/trustgraph/api/__init__.py +80 -0
  4. trustgraph_base-1.7.1/trustgraph/api/api.py +182 -0
  5. trustgraph_base-1.7.1/trustgraph/api/async_bulk_client.py +131 -0
  6. trustgraph_base-1.7.1/trustgraph/api/async_flow.py +245 -0
  7. trustgraph_base-1.7.1/trustgraph/api/async_metrics.py +33 -0
  8. trustgraph_base-1.7.1/trustgraph/api/async_socket_client.py +335 -0
  9. trustgraph_base-1.7.1/trustgraph/api/bulk_client.py +270 -0
  10. trustgraph_base-1.7.1/trustgraph/api/collection.py +98 -0
  11. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/api/config.py +19 -2
  12. trustgraph_base-1.7.1/trustgraph/api/flow.py +657 -0
  13. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/api/knowledge.py +26 -0
  14. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/api/library.py +8 -5
  15. trustgraph_base-1.7.1/trustgraph/api/metrics.py +27 -0
  16. trustgraph_base-1.7.1/trustgraph/api/socket_client.py +445 -0
  17. trustgraph_base-1.7.1/trustgraph/api/types.py +83 -0
  18. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/__init__.py +7 -2
  19. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/agent_client.py +8 -10
  20. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/agent_service.py +6 -2
  21. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/async_processor.py +36 -14
  22. trustgraph_base-1.7.1/trustgraph/base/cassandra_config.py +134 -0
  23. trustgraph_base-1.7.1/trustgraph/base/chunking_service.py +62 -0
  24. trustgraph_base-1.7.1/trustgraph/base/consumer.py +238 -0
  25. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/consumer_spec.py +3 -1
  26. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/document_embeddings_client.py +7 -2
  27. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/document_embeddings_query_service.py +12 -7
  28. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/document_embeddings_store_service.py +6 -1
  29. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/embeddings_service.py +33 -8
  30. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/flow.py +2 -2
  31. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/flow_processor.py +11 -7
  32. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/graph_embeddings_client.py +6 -1
  33. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/graph_embeddings_query_service.py +10 -5
  34. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/graph_embeddings_store_service.py +6 -1
  35. trustgraph_base-1.7.1/trustgraph/base/llm_service.py +228 -0
  36. trustgraph-base-0.23.17/trustgraph/base/setting_spec.py → trustgraph_base-1.7.1/trustgraph/base/parameter_spec.py +5 -3
  37. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/producer.py +8 -4
  38. trustgraph_base-1.7.1/trustgraph/base/prompt_client.py +171 -0
  39. trustgraph_base-1.7.1/trustgraph/base/publisher.py +123 -0
  40. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/pubsub.py +7 -7
  41. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/request_response_spec.py +11 -7
  42. trustgraph_base-1.7.1/trustgraph/base/structured_query_client.py +35 -0
  43. trustgraph_base-1.7.1/trustgraph/base/subscriber.py +286 -0
  44. trustgraph_base-1.7.1/trustgraph/base/text_completion_client.py +57 -0
  45. trustgraph_base-1.7.1/trustgraph/base/tool_client.py +40 -0
  46. trustgraph_base-1.7.1/trustgraph/base/tool_service.py +125 -0
  47. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/triples_query_service.py +10 -5
  48. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/triples_store_service.py +7 -1
  49. trustgraph_base-1.7.1/trustgraph/base_version.py +1 -0
  50. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/clients/document_embeddings_client.py +1 -1
  51. trustgraph_base-1.7.1/trustgraph/clients/llm_client.py +105 -0
  52. trustgraph_base-1.7.1/trustgraph/messaging/__init__.py +147 -0
  53. trustgraph_base-1.7.1/trustgraph/messaging/registry.py +51 -0
  54. trustgraph_base-1.7.1/trustgraph/messaging/translators/__init__.py +21 -0
  55. trustgraph_base-1.7.1/trustgraph/messaging/translators/agent.py +70 -0
  56. trustgraph_base-1.7.1/trustgraph/messaging/translators/base.py +43 -0
  57. trustgraph_base-1.7.1/trustgraph/messaging/translators/collection.py +114 -0
  58. trustgraph_base-1.7.1/trustgraph/messaging/translators/config.py +101 -0
  59. trustgraph_base-1.7.1/trustgraph/messaging/translators/diagnosis.py +67 -0
  60. trustgraph_base-1.7.1/trustgraph/messaging/translators/document_loading.py +191 -0
  61. trustgraph_base-1.7.1/trustgraph/messaging/translators/embeddings.py +33 -0
  62. trustgraph_base-1.7.1/trustgraph/messaging/translators/embeddings_query.py +94 -0
  63. trustgraph_base-1.7.1/trustgraph/messaging/translators/flow.py +64 -0
  64. trustgraph_base-1.7.1/trustgraph/messaging/translators/knowledge.py +183 -0
  65. trustgraph_base-1.7.1/trustgraph/messaging/translators/library.py +124 -0
  66. trustgraph_base-1.7.1/trustgraph/messaging/translators/metadata.py +81 -0
  67. trustgraph_base-1.7.1/trustgraph/messaging/translators/nlp_query.py +47 -0
  68. trustgraph_base-1.7.1/trustgraph/messaging/translators/objects_query.py +79 -0
  69. trustgraph_base-1.7.1/trustgraph/messaging/translators/primitives.py +140 -0
  70. trustgraph_base-1.7.1/trustgraph/messaging/translators/prompt.py +57 -0
  71. trustgraph_base-1.7.1/trustgraph/messaging/translators/retrieval.py +125 -0
  72. trustgraph_base-1.7.1/trustgraph/messaging/translators/structured_query.py +60 -0
  73. trustgraph_base-1.7.1/trustgraph/messaging/translators/text_completion.py +45 -0
  74. trustgraph_base-1.7.1/trustgraph/messaging/translators/tool.py +51 -0
  75. trustgraph_base-1.7.1/trustgraph/messaging/translators/triples.py +60 -0
  76. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/rdf.py +1 -0
  77. trustgraph_base-1.7.1/trustgraph/schema/__init__.py +10 -0
  78. trustgraph_base-1.7.1/trustgraph/schema/core/__init__.py +3 -0
  79. {trustgraph-base-0.23.17/trustgraph/schema → trustgraph_base-1.7.1/trustgraph/schema/core}/metadata.py +1 -1
  80. trustgraph-base-0.23.17/trustgraph/schema/types.py → trustgraph_base-1.7.1/trustgraph/schema/core/primitives.py +5 -1
  81. trustgraph_base-1.7.1/trustgraph/schema/knowledge/__init__.py +8 -0
  82. trustgraph_base-1.7.1/trustgraph/schema/knowledge/document.py +29 -0
  83. trustgraph-base-0.23.17/trustgraph/schema/graph.py → trustgraph_base-1.7.1/trustgraph/schema/knowledge/embeddings.py +26 -41
  84. trustgraph_base-1.7.1/trustgraph/schema/knowledge/graph.py +28 -0
  85. {trustgraph-base-0.23.17/trustgraph/schema → trustgraph_base-1.7.1/trustgraph/schema/knowledge}/knowledge.py +15 -7
  86. trustgraph_base-1.7.1/trustgraph/schema/knowledge/nlp.py +26 -0
  87. trustgraph_base-1.7.1/trustgraph/schema/knowledge/object.py +17 -0
  88. trustgraph_base-1.7.1/trustgraph/schema/knowledge/rows.py +16 -0
  89. trustgraph_base-1.7.1/trustgraph/schema/knowledge/structured.py +17 -0
  90. trustgraph_base-1.7.1/trustgraph/schema/services/__init__.py +15 -0
  91. trustgraph_base-1.7.1/trustgraph/schema/services/agent.py +40 -0
  92. trustgraph_base-1.7.1/trustgraph/schema/services/collection.py +59 -0
  93. {trustgraph-base-0.23.17/trustgraph/schema → trustgraph_base-1.7.1/trustgraph/schema/services}/config.py +2 -2
  94. trustgraph_base-1.7.1/trustgraph/schema/services/diagnosis.py +33 -0
  95. trustgraph-base-0.23.17/trustgraph/schema/flows.py → trustgraph_base-1.7.1/trustgraph/schema/services/flow.py +8 -2
  96. {trustgraph-base-0.23.17/trustgraph/schema → trustgraph_base-1.7.1/trustgraph/schema/services}/library.py +4 -5
  97. trustgraph-base-0.23.17/trustgraph/schema/models.py → trustgraph_base-1.7.1/trustgraph/schema/services/llm.py +24 -3
  98. {trustgraph-base-0.23.17/trustgraph/schema → trustgraph_base-1.7.1/trustgraph/schema/services}/lookup.py +3 -3
  99. trustgraph_base-1.7.1/trustgraph/schema/services/nlp_query.py +21 -0
  100. trustgraph_base-1.7.1/trustgraph/schema/services/objects_query.py +28 -0
  101. {trustgraph-base-0.23.17/trustgraph/schema → trustgraph_base-1.7.1/trustgraph/schema/services}/prompt.py +9 -24
  102. trustgraph_base-1.7.1/trustgraph/schema/services/query.py +55 -0
  103. {trustgraph-base-0.23.17/trustgraph/schema → trustgraph_base-1.7.1/trustgraph/schema/services}/retrieval.py +8 -2
  104. trustgraph_base-1.7.1/trustgraph/schema/services/storage.py +42 -0
  105. trustgraph_base-1.7.1/trustgraph/schema/services/structured_query.py +20 -0
  106. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph_base.egg-info/PKG-INFO +7 -7
  107. trustgraph_base-1.7.1/trustgraph_base.egg-info/SOURCES.txt +140 -0
  108. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph_base.egg-info/requires.txt +2 -1
  109. trustgraph-base-0.23.17/setup.py +0 -42
  110. trustgraph-base-0.23.17/trustgraph/api/__init__.py +0 -3
  111. trustgraph-base-0.23.17/trustgraph/api/api.py +0 -73
  112. trustgraph-base-0.23.17/trustgraph/api/flow.py +0 -360
  113. trustgraph-base-0.23.17/trustgraph/api/types.py +0 -43
  114. trustgraph-base-0.23.17/trustgraph/base/consumer.py +0 -197
  115. trustgraph-base-0.23.17/trustgraph/base/llm_service.py +0 -119
  116. trustgraph-base-0.23.17/trustgraph/base/prompt_client.py +0 -93
  117. trustgraph-base-0.23.17/trustgraph/base/publisher.py +0 -75
  118. trustgraph-base-0.23.17/trustgraph/base/subscriber.py +0 -174
  119. trustgraph-base-0.23.17/trustgraph/base/text_completion_client.py +0 -30
  120. trustgraph-base-0.23.17/trustgraph/base_version.py +0 -1
  121. trustgraph-base-0.23.17/trustgraph/clients/llm_client.py +0 -44
  122. trustgraph-base-0.23.17/trustgraph/schema/__init__.py +0 -17
  123. trustgraph-base-0.23.17/trustgraph/schema/agent.py +0 -30
  124. trustgraph-base-0.23.17/trustgraph/schema/documents.py +0 -56
  125. trustgraph-base-0.23.17/trustgraph/schema/object.py +0 -31
  126. trustgraph-base-0.23.17/trustgraph_base.egg-info/SOURCES.txt +0 -89
  127. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/README.md +0 -0
  128. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/setup.cfg +0 -0
  129. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/api/exceptions.py +0 -0
  130. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/embeddings_client.py +0 -0
  131. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/graph_rag_client.py +0 -0
  132. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/metrics.py +0 -0
  133. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/producer_spec.py +0 -0
  134. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/spec.py +0 -0
  135. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/subscriber_spec.py +0 -0
  136. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/base/triples_client.py +0 -0
  137. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/clients/__init__.py +0 -0
  138. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/clients/agent_client.py +0 -0
  139. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/clients/base.py +0 -0
  140. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/clients/config_client.py +0 -0
  141. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/clients/document_rag_client.py +0 -0
  142. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/clients/embeddings_client.py +0 -0
  143. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/clients/graph_embeddings_client.py +0 -0
  144. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/clients/graph_rag_client.py +0 -0
  145. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/clients/prompt_client.py +0 -0
  146. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/clients/triples_query_client.py +0 -0
  147. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/exceptions.py +0 -0
  148. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/knowledge/__init__.py +0 -0
  149. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/knowledge/defs.py +0 -0
  150. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/knowledge/document.py +0 -0
  151. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/knowledge/identifier.py +0 -0
  152. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/knowledge/organization.py +0 -0
  153. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/knowledge/publication.py +0 -0
  154. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/log_level.py +0 -0
  155. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/objects/__init__.py +0 -0
  156. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/objects/field.py +0 -0
  157. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph/objects/object.py +0 -0
  158. {trustgraph-base-0.23.17/trustgraph/schema → trustgraph_base-1.7.1/trustgraph/schema/core}/topic.py +0 -0
  159. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph_base.egg-info/dependency_links.txt +0 -0
  160. {trustgraph-base-0.23.17 → trustgraph_base-1.7.1}/trustgraph_base.egg-info/top_level.txt +0 -0
@@ -1,15 +1,15 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: trustgraph-base
3
- Version: 0.23.17
3
+ Version: 1.7.1
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
- Home-page: https://github.com/trustgraph-ai/trustgraph
6
- Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.23.17.tar.gz
7
- Author: trustgraph.ai
8
- Author-email: security@trustgraph.ai
5
+ Author-email: "trustgraph.ai" <security@trustgraph.ai>
6
+ Project-URL: Homepage, https://github.com/trustgraph-ai/trustgraph
9
7
  Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
11
8
  Classifier: Operating System :: OS Independent
12
9
  Requires-Python: >=3.8
13
10
  Description-Content-Type: text/markdown
11
+ Requires-Dist: pulsar-client
12
+ Requires-Dist: prometheus-client
13
+ Requires-Dist: requests
14
14
 
15
15
  See https://trustgraph.ai/
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "trustgraph-base"
7
+ dynamic = ["version"]
8
+ authors = [{name = "trustgraph.ai", email = "security@trustgraph.ai"}]
9
+ description = "TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline."
10
+ readme = "README.md"
11
+ requires-python = ">=3.8"
12
+ dependencies = [
13
+ "pulsar-client",
14
+ "prometheus-client",
15
+ "requests",
16
+ ]
17
+ classifiers = [
18
+ "Programming Language :: Python :: 3",
19
+ "Operating System :: OS Independent",
20
+ ]
21
+
22
+ [project.urls]
23
+ Homepage = "https://github.com/trustgraph-ai/trustgraph"
24
+
25
+ [tool.setuptools.packages.find]
26
+ include = ["trustgraph*"]
27
+
28
+ [tool.setuptools.dynamic]
29
+ version = {attr = "trustgraph.base_version.__version__"}
@@ -0,0 +1,80 @@
1
+
2
+ # Core API
3
+ from .api import Api
4
+
5
+ # Flow clients
6
+ from .flow import Flow, FlowInstance
7
+ from .async_flow import AsyncFlow, AsyncFlowInstance
8
+
9
+ # WebSocket clients
10
+ from .socket_client import SocketClient, SocketFlowInstance
11
+ from .async_socket_client import AsyncSocketClient, AsyncSocketFlowInstance
12
+
13
+ # Bulk operation clients
14
+ from .bulk_client import BulkClient
15
+ from .async_bulk_client import AsyncBulkClient
16
+
17
+ # Metrics clients
18
+ from .metrics import Metrics
19
+ from .async_metrics import AsyncMetrics
20
+
21
+ # Types
22
+ from .types import (
23
+ Triple,
24
+ ConfigKey,
25
+ ConfigValue,
26
+ DocumentMetadata,
27
+ ProcessingMetadata,
28
+ CollectionMetadata,
29
+ StreamingChunk,
30
+ AgentThought,
31
+ AgentObservation,
32
+ AgentAnswer,
33
+ RAGChunk,
34
+ )
35
+
36
+ # Exceptions
37
+ from .exceptions import ProtocolException, ApplicationException
38
+
39
+ __all__ = [
40
+ # Core API
41
+ "Api",
42
+
43
+ # Flow clients
44
+ "Flow",
45
+ "FlowInstance",
46
+ "AsyncFlow",
47
+ "AsyncFlowInstance",
48
+
49
+ # WebSocket clients
50
+ "SocketClient",
51
+ "SocketFlowInstance",
52
+ "AsyncSocketClient",
53
+ "AsyncSocketFlowInstance",
54
+
55
+ # Bulk operation clients
56
+ "BulkClient",
57
+ "AsyncBulkClient",
58
+
59
+ # Metrics clients
60
+ "Metrics",
61
+ "AsyncMetrics",
62
+
63
+ # Types
64
+ "Triple",
65
+ "ConfigKey",
66
+ "ConfigValue",
67
+ "DocumentMetadata",
68
+ "ProcessingMetadata",
69
+ "CollectionMetadata",
70
+ "StreamingChunk",
71
+ "AgentThought",
72
+ "AgentObservation",
73
+ "AgentAnswer",
74
+ "RAGChunk",
75
+
76
+ # Exceptions
77
+ "ProtocolException",
78
+ "ApplicationException",
79
+ ]
80
+
@@ -0,0 +1,182 @@
1
+
2
+ import requests
3
+ import json
4
+ import base64
5
+ import time
6
+ from typing import Optional
7
+
8
+ from . library import Library
9
+ from . flow import Flow
10
+ from . config import Config
11
+ from . knowledge import Knowledge
12
+ from . collection import Collection
13
+ from . exceptions import *
14
+ from . types import *
15
+
16
+ def check_error(response):
17
+
18
+ if "error" in response:
19
+
20
+ try:
21
+ msg = response["error"]["message"]
22
+ tp = response["error"]["type"]
23
+ except:
24
+ raise ApplicationException(response["error"])
25
+
26
+ raise ApplicationException(f"{tp}: {msg}")
27
+
28
+ class Api:
29
+
30
+ def __init__(self, url="http://localhost:8088/", timeout=60, token: Optional[str] = None):
31
+
32
+ self.url = url
33
+
34
+ if not url.endswith("/"):
35
+ self.url += "/"
36
+
37
+ self.url += "api/v1/"
38
+
39
+ self.timeout = timeout
40
+ self.token = token
41
+
42
+ # Lazy initialization for new clients
43
+ self._socket_client = None
44
+ self._bulk_client = None
45
+ self._async_flow = None
46
+ self._async_socket_client = None
47
+ self._async_bulk_client = None
48
+ self._metrics = None
49
+ self._async_metrics = None
50
+
51
+ def flow(self):
52
+ return Flow(api=self)
53
+
54
+ def config(self):
55
+ return Config(api=self)
56
+
57
+ def knowledge(self):
58
+ return Knowledge(api=self)
59
+
60
+ def request(self, path, request):
61
+
62
+ url = f"{self.url}{path}"
63
+
64
+ headers = {}
65
+ if self.token:
66
+ headers["Authorization"] = f"Bearer {self.token}"
67
+
68
+ # Invoke the API, input is passed as JSON
69
+ resp = requests.post(url, json=request, timeout=self.timeout, headers=headers)
70
+
71
+ # Should be a 200 status code
72
+ if resp.status_code != 200:
73
+ raise ProtocolException(f"Status code {resp.status_code}")
74
+
75
+ try:
76
+ # Parse the response as JSON
77
+ object = resp.json()
78
+ except:
79
+ raise ProtocolException(f"Expected JSON response")
80
+
81
+ check_error(object)
82
+
83
+ return object
84
+
85
+ def library(self):
86
+ return Library(self)
87
+
88
+ def collection(self):
89
+ return Collection(self)
90
+
91
+ # New synchronous methods
92
+ def socket(self):
93
+ """Synchronous WebSocket-based interface for streaming operations"""
94
+ if self._socket_client is None:
95
+ from . socket_client import SocketClient
96
+ # Extract base URL (remove api/v1/ suffix)
97
+ base_url = self.url.rsplit("api/v1/", 1)[0].rstrip("/")
98
+ self._socket_client = SocketClient(base_url, self.timeout, self.token)
99
+ return self._socket_client
100
+
101
+ def bulk(self):
102
+ """Synchronous bulk operations interface for import/export"""
103
+ if self._bulk_client is None:
104
+ from . bulk_client import BulkClient
105
+ # Extract base URL (remove api/v1/ suffix)
106
+ base_url = self.url.rsplit("api/v1/", 1)[0].rstrip("/")
107
+ self._bulk_client = BulkClient(base_url, self.timeout, self.token)
108
+ return self._bulk_client
109
+
110
+ def metrics(self):
111
+ """Synchronous metrics interface"""
112
+ if self._metrics is None:
113
+ from . metrics import Metrics
114
+ # Extract base URL (remove api/v1/ suffix)
115
+ base_url = self.url.rsplit("api/v1/", 1)[0].rstrip("/")
116
+ self._metrics = Metrics(base_url, self.timeout, self.token)
117
+ return self._metrics
118
+
119
+ # New asynchronous methods
120
+ def async_flow(self):
121
+ """Asynchronous REST-based flow interface"""
122
+ if self._async_flow is None:
123
+ from . async_flow import AsyncFlow
124
+ self._async_flow = AsyncFlow(self.url, self.timeout, self.token)
125
+ return self._async_flow
126
+
127
+ def async_socket(self):
128
+ """Asynchronous WebSocket-based interface for streaming operations"""
129
+ if self._async_socket_client is None:
130
+ from . async_socket_client import AsyncSocketClient
131
+ # Extract base URL (remove api/v1/ suffix)
132
+ base_url = self.url.rsplit("api/v1/", 1)[0].rstrip("/")
133
+ self._async_socket_client = AsyncSocketClient(base_url, self.timeout, self.token)
134
+ return self._async_socket_client
135
+
136
+ def async_bulk(self):
137
+ """Asynchronous bulk operations interface for import/export"""
138
+ if self._async_bulk_client is None:
139
+ from . async_bulk_client import AsyncBulkClient
140
+ # Extract base URL (remove api/v1/ suffix)
141
+ base_url = self.url.rsplit("api/v1/", 1)[0].rstrip("/")
142
+ self._async_bulk_client = AsyncBulkClient(base_url, self.timeout, self.token)
143
+ return self._async_bulk_client
144
+
145
+ def async_metrics(self):
146
+ """Asynchronous metrics interface"""
147
+ if self._async_metrics is None:
148
+ from . async_metrics import AsyncMetrics
149
+ # Extract base URL (remove api/v1/ suffix)
150
+ base_url = self.url.rsplit("api/v1/", 1)[0].rstrip("/")
151
+ self._async_metrics = AsyncMetrics(base_url, self.timeout, self.token)
152
+ return self._async_metrics
153
+
154
+ # Resource management
155
+ def close(self):
156
+ """Close all synchronous connections"""
157
+ if self._socket_client:
158
+ self._socket_client.close()
159
+ if self._bulk_client:
160
+ self._bulk_client.close()
161
+
162
+ async def aclose(self):
163
+ """Close all asynchronous connections"""
164
+ if self._async_socket_client:
165
+ await self._async_socket_client.aclose()
166
+ if self._async_bulk_client:
167
+ await self._async_bulk_client.aclose()
168
+ if self._async_flow:
169
+ await self._async_flow.aclose()
170
+
171
+ # Context manager support
172
+ def __enter__(self):
173
+ return self
174
+
175
+ def __exit__(self, *args):
176
+ self.close()
177
+
178
+ async def __aenter__(self):
179
+ return self
180
+
181
+ async def __aexit__(self, *args):
182
+ await self.aclose()
@@ -0,0 +1,131 @@
1
+
2
+ import json
3
+ import websockets
4
+ from typing import Optional, AsyncIterator, Dict, Any, Iterator
5
+
6
+ from . types import Triple
7
+
8
+
9
+ class AsyncBulkClient:
10
+ """Asynchronous bulk operations client"""
11
+
12
+ def __init__(self, url: str, timeout: int, token: Optional[str]) -> None:
13
+ self.url: str = self._convert_to_ws_url(url)
14
+ self.timeout: int = timeout
15
+ self.token: Optional[str] = token
16
+
17
+ def _convert_to_ws_url(self, url: str) -> str:
18
+ """Convert HTTP URL to WebSocket URL"""
19
+ if url.startswith("http://"):
20
+ return url.replace("http://", "ws://", 1)
21
+ elif url.startswith("https://"):
22
+ return url.replace("https://", "wss://", 1)
23
+ elif url.startswith("ws://") or url.startswith("wss://"):
24
+ return url
25
+ else:
26
+ return f"ws://{url}"
27
+
28
+ async def import_triples(self, flow: str, triples: AsyncIterator[Triple], **kwargs: Any) -> None:
29
+ """Bulk import triples via WebSocket"""
30
+ ws_url = f"{self.url}/api/v1/flow/{flow}/import/triples"
31
+ if self.token:
32
+ ws_url = f"{ws_url}?token={self.token}"
33
+
34
+ async with websockets.connect(ws_url, ping_interval=20, ping_timeout=self.timeout) as websocket:
35
+ async for triple in triples:
36
+ message = {
37
+ "s": triple.s,
38
+ "p": triple.p,
39
+ "o": triple.o
40
+ }
41
+ await websocket.send(json.dumps(message))
42
+
43
+ async def export_triples(self, flow: str, **kwargs: Any) -> AsyncIterator[Triple]:
44
+ """Bulk export triples via WebSocket"""
45
+ ws_url = f"{self.url}/api/v1/flow/{flow}/export/triples"
46
+ if self.token:
47
+ ws_url = f"{ws_url}?token={self.token}"
48
+
49
+ async with websockets.connect(ws_url, ping_interval=20, ping_timeout=self.timeout) as websocket:
50
+ async for raw_message in websocket:
51
+ data = json.loads(raw_message)
52
+ yield Triple(
53
+ s=data.get("s", ""),
54
+ p=data.get("p", ""),
55
+ o=data.get("o", "")
56
+ )
57
+
58
+ async def import_graph_embeddings(self, flow: str, embeddings: AsyncIterator[Dict[str, Any]], **kwargs: Any) -> None:
59
+ """Bulk import graph embeddings via WebSocket"""
60
+ ws_url = f"{self.url}/api/v1/flow/{flow}/import/graph-embeddings"
61
+ if self.token:
62
+ ws_url = f"{ws_url}?token={self.token}"
63
+
64
+ async with websockets.connect(ws_url, ping_interval=20, ping_timeout=self.timeout) as websocket:
65
+ async for embedding in embeddings:
66
+ await websocket.send(json.dumps(embedding))
67
+
68
+ async def export_graph_embeddings(self, flow: str, **kwargs: Any) -> AsyncIterator[Dict[str, Any]]:
69
+ """Bulk export graph embeddings via WebSocket"""
70
+ ws_url = f"{self.url}/api/v1/flow/{flow}/export/graph-embeddings"
71
+ if self.token:
72
+ ws_url = f"{ws_url}?token={self.token}"
73
+
74
+ async with websockets.connect(ws_url, ping_interval=20, ping_timeout=self.timeout) as websocket:
75
+ async for raw_message in websocket:
76
+ yield json.loads(raw_message)
77
+
78
+ async def import_document_embeddings(self, flow: str, embeddings: AsyncIterator[Dict[str, Any]], **kwargs: Any) -> None:
79
+ """Bulk import document embeddings via WebSocket"""
80
+ ws_url = f"{self.url}/api/v1/flow/{flow}/import/document-embeddings"
81
+ if self.token:
82
+ ws_url = f"{ws_url}?token={self.token}"
83
+
84
+ async with websockets.connect(ws_url, ping_interval=20, ping_timeout=self.timeout) as websocket:
85
+ async for embedding in embeddings:
86
+ await websocket.send(json.dumps(embedding))
87
+
88
+ async def export_document_embeddings(self, flow: str, **kwargs: Any) -> AsyncIterator[Dict[str, Any]]:
89
+ """Bulk export document embeddings via WebSocket"""
90
+ ws_url = f"{self.url}/api/v1/flow/{flow}/export/document-embeddings"
91
+ if self.token:
92
+ ws_url = f"{ws_url}?token={self.token}"
93
+
94
+ async with websockets.connect(ws_url, ping_interval=20, ping_timeout=self.timeout) as websocket:
95
+ async for raw_message in websocket:
96
+ yield json.loads(raw_message)
97
+
98
+ async def import_entity_contexts(self, flow: str, contexts: AsyncIterator[Dict[str, Any]], **kwargs: Any) -> None:
99
+ """Bulk import entity contexts via WebSocket"""
100
+ ws_url = f"{self.url}/api/v1/flow/{flow}/import/entity-contexts"
101
+ if self.token:
102
+ ws_url = f"{ws_url}?token={self.token}"
103
+
104
+ async with websockets.connect(ws_url, ping_interval=20, ping_timeout=self.timeout) as websocket:
105
+ async for context in contexts:
106
+ await websocket.send(json.dumps(context))
107
+
108
+ async def export_entity_contexts(self, flow: str, **kwargs: Any) -> AsyncIterator[Dict[str, Any]]:
109
+ """Bulk export entity contexts via WebSocket"""
110
+ ws_url = f"{self.url}/api/v1/flow/{flow}/export/entity-contexts"
111
+ if self.token:
112
+ ws_url = f"{ws_url}?token={self.token}"
113
+
114
+ async with websockets.connect(ws_url, ping_interval=20, ping_timeout=self.timeout) as websocket:
115
+ async for raw_message in websocket:
116
+ yield json.loads(raw_message)
117
+
118
+ async def import_objects(self, flow: str, objects: AsyncIterator[Dict[str, Any]], **kwargs: Any) -> None:
119
+ """Bulk import objects via WebSocket"""
120
+ ws_url = f"{self.url}/api/v1/flow/{flow}/import/objects"
121
+ if self.token:
122
+ ws_url = f"{ws_url}?token={self.token}"
123
+
124
+ async with websockets.connect(ws_url, ping_interval=20, ping_timeout=self.timeout) as websocket:
125
+ async for obj in objects:
126
+ await websocket.send(json.dumps(obj))
127
+
128
+ async def aclose(self) -> None:
129
+ """Close connections"""
130
+ # Cleanup handled by context managers
131
+ pass
@@ -0,0 +1,245 @@
1
+
2
+ import aiohttp
3
+ import json
4
+ from typing import Optional, Dict, Any, List
5
+
6
+ from . exceptions import ProtocolException, ApplicationException
7
+
8
+
9
+ def check_error(response):
10
+ if "error" in response:
11
+ try:
12
+ msg = response["error"]["message"]
13
+ tp = response["error"]["type"]
14
+ except:
15
+ raise ApplicationException(response["error"])
16
+
17
+ raise ApplicationException(f"{tp}: {msg}")
18
+
19
+
20
+ class AsyncFlow:
21
+ """Asynchronous REST-based flow interface"""
22
+
23
+ def __init__(self, url: str, timeout: int, token: Optional[str]) -> None:
24
+ self.url: str = url
25
+ self.timeout: int = timeout
26
+ self.token: Optional[str] = token
27
+
28
+ async def request(self, path: str, request_data: Dict[str, Any]) -> Dict[str, Any]:
29
+ """Make async HTTP request to Gateway API"""
30
+ url = f"{self.url}{path}"
31
+
32
+ headers = {"Content-Type": "application/json"}
33
+ if self.token:
34
+ headers["Authorization"] = f"Bearer {self.token}"
35
+
36
+ timeout = aiohttp.ClientTimeout(total=self.timeout)
37
+
38
+ async with aiohttp.ClientSession(timeout=timeout) as session:
39
+ async with session.post(url, json=request_data, headers=headers) as resp:
40
+ if resp.status != 200:
41
+ raise ProtocolException(f"Status code {resp.status}")
42
+
43
+ try:
44
+ obj = await resp.json()
45
+ except:
46
+ raise ProtocolException(f"Expected JSON response")
47
+
48
+ check_error(obj)
49
+ return obj
50
+
51
+ async def list(self) -> List[str]:
52
+ """List all flows"""
53
+ result = await self.request("flow", {"operation": "list-flows"})
54
+ return result.get("flow-ids", [])
55
+
56
+ async def get(self, id: str) -> Dict[str, Any]:
57
+ """Get flow definition"""
58
+ result = await self.request("flow", {
59
+ "operation": "get-flow",
60
+ "flow-id": id
61
+ })
62
+ return json.loads(result.get("flow", "{}"))
63
+
64
+ async def start(self, class_name: str, id: str, description: str, parameters: Optional[Dict] = None):
65
+ """Start a flow"""
66
+ request_data = {
67
+ "operation": "start-flow",
68
+ "flow-id": id,
69
+ "class-name": class_name,
70
+ "description": description
71
+ }
72
+ if parameters:
73
+ request_data["parameters"] = json.dumps(parameters)
74
+
75
+ await self.request("flow", request_data)
76
+
77
+ async def stop(self, id: str):
78
+ """Stop a flow"""
79
+ await self.request("flow", {
80
+ "operation": "stop-flow",
81
+ "flow-id": id
82
+ })
83
+
84
+ async def list_classes(self) -> List[str]:
85
+ """List flow classes"""
86
+ result = await self.request("flow", {"operation": "list-classes"})
87
+ return result.get("class-names", [])
88
+
89
+ async def get_class(self, class_name: str) -> Dict[str, Any]:
90
+ """Get flow class definition"""
91
+ result = await self.request("flow", {
92
+ "operation": "get-class",
93
+ "class-name": class_name
94
+ })
95
+ return json.loads(result.get("class-definition", "{}"))
96
+
97
+ async def put_class(self, class_name: str, definition: Dict[str, Any]):
98
+ """Create/update flow class"""
99
+ await self.request("flow", {
100
+ "operation": "put-class",
101
+ "class-name": class_name,
102
+ "class-definition": json.dumps(definition)
103
+ })
104
+
105
+ async def delete_class(self, class_name: str):
106
+ """Delete flow class"""
107
+ await self.request("flow", {
108
+ "operation": "delete-class",
109
+ "class-name": class_name
110
+ })
111
+
112
+ def id(self, flow_id: str):
113
+ """Get async flow instance"""
114
+ return AsyncFlowInstance(self, flow_id)
115
+
116
+ async def aclose(self) -> None:
117
+ """Close connection (cleanup handled by aiohttp session)"""
118
+ pass
119
+
120
+
121
+ class AsyncFlowInstance:
122
+ """Asynchronous REST flow instance"""
123
+
124
+ def __init__(self, flow: AsyncFlow, flow_id: str):
125
+ self.flow = flow
126
+ self.flow_id = flow_id
127
+
128
+ async def request(self, service: str, request_data: Dict[str, Any]) -> Dict[str, Any]:
129
+ """Make request to flow-scoped service"""
130
+ return await self.flow.request(f"flow/{self.flow_id}/service/{service}", request_data)
131
+
132
+ async def agent(self, question: str, user: str, state: Optional[Dict] = None,
133
+ group: Optional[str] = None, history: Optional[List] = None, **kwargs: Any) -> Dict[str, Any]:
134
+ """Execute agent (non-streaming, use async_socket for streaming)"""
135
+ request_data = {
136
+ "question": question,
137
+ "user": user,
138
+ "streaming": False # REST doesn't support streaming
139
+ }
140
+ if state is not None:
141
+ request_data["state"] = state
142
+ if group is not None:
143
+ request_data["group"] = group
144
+ if history is not None:
145
+ request_data["history"] = history
146
+ request_data.update(kwargs)
147
+
148
+ return await self.request("agent", request_data)
149
+
150
+ async def text_completion(self, system: str, prompt: str, **kwargs: Any) -> str:
151
+ """Text completion (non-streaming, use async_socket for streaming)"""
152
+ request_data = {
153
+ "system": system,
154
+ "prompt": prompt,
155
+ "streaming": False
156
+ }
157
+ request_data.update(kwargs)
158
+
159
+ result = await self.request("text-completion", request_data)
160
+ return result.get("response", "")
161
+
162
+ async def graph_rag(self, question: str, user: str, collection: str,
163
+ max_subgraph_size: int = 1000, max_subgraph_count: int = 5,
164
+ max_entity_distance: int = 3, **kwargs: Any) -> str:
165
+ """Graph RAG (non-streaming, use async_socket for streaming)"""
166
+ request_data = {
167
+ "question": question,
168
+ "user": user,
169
+ "collection": collection,
170
+ "max-subgraph-size": max_subgraph_size,
171
+ "max-subgraph-count": max_subgraph_count,
172
+ "max-entity-distance": max_entity_distance,
173
+ "streaming": False
174
+ }
175
+ request_data.update(kwargs)
176
+
177
+ result = await self.request("graph-rag", request_data)
178
+ return result.get("response", "")
179
+
180
+ async def document_rag(self, question: str, user: str, collection: str,
181
+ doc_limit: int = 10, **kwargs: Any) -> str:
182
+ """Document RAG (non-streaming, use async_socket for streaming)"""
183
+ request_data = {
184
+ "question": question,
185
+ "user": user,
186
+ "collection": collection,
187
+ "doc-limit": doc_limit,
188
+ "streaming": False
189
+ }
190
+ request_data.update(kwargs)
191
+
192
+ result = await self.request("document-rag", request_data)
193
+ return result.get("response", "")
194
+
195
+ async def graph_embeddings_query(self, text: str, user: str, collection: str, limit: int = 10, **kwargs: Any):
196
+ """Query graph embeddings for semantic search"""
197
+ request_data = {
198
+ "text": text,
199
+ "user": user,
200
+ "collection": collection,
201
+ "limit": limit
202
+ }
203
+ request_data.update(kwargs)
204
+
205
+ return await self.request("graph-embeddings", request_data)
206
+
207
+ async def embeddings(self, text: str, **kwargs: Any):
208
+ """Generate text embeddings"""
209
+ request_data = {"text": text}
210
+ request_data.update(kwargs)
211
+
212
+ return await self.request("embeddings", request_data)
213
+
214
+ async def triples_query(self, s=None, p=None, o=None, user=None, collection=None, limit=100, **kwargs: Any):
215
+ """Triple pattern query"""
216
+ request_data = {"limit": limit}
217
+ if s is not None:
218
+ request_data["s"] = str(s)
219
+ if p is not None:
220
+ request_data["p"] = str(p)
221
+ if o is not None:
222
+ request_data["o"] = str(o)
223
+ if user is not None:
224
+ request_data["user"] = user
225
+ if collection is not None:
226
+ request_data["collection"] = collection
227
+ request_data.update(kwargs)
228
+
229
+ return await self.request("triples", request_data)
230
+
231
+ async def objects_query(self, query: str, user: str, collection: str, variables: Optional[Dict] = None,
232
+ operation_name: Optional[str] = None, **kwargs: Any):
233
+ """GraphQL query"""
234
+ request_data = {
235
+ "query": query,
236
+ "user": user,
237
+ "collection": collection
238
+ }
239
+ if variables:
240
+ request_data["variables"] = variables
241
+ if operation_name:
242
+ request_data["operationName"] = operation_name
243
+ request_data.update(kwargs)
244
+
245
+ return await self.request("objects", request_data)