trustgraph-base 1.3.19__tar.gz → 1.7.5__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.
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/PKG-INFO +2 -1
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/pyproject.toml +1 -0
- trustgraph_base-1.7.5/trustgraph/api/__init__.py +114 -0
- trustgraph_base-1.7.5/trustgraph/api/api.py +182 -0
- trustgraph_base-1.7.5/trustgraph/api/async_bulk_client.py +131 -0
- trustgraph_base-1.7.5/trustgraph/api/async_flow.py +245 -0
- trustgraph_base-1.7.5/trustgraph/api/async_metrics.py +33 -0
- trustgraph_base-1.7.5/trustgraph/api/async_socket_client.py +343 -0
- trustgraph_base-1.7.5/trustgraph/api/bulk_client.py +270 -0
- trustgraph_base-1.7.5/trustgraph/api/collection.py +94 -0
- trustgraph_base-1.7.5/trustgraph/api/exceptions.py +134 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/api/flow.py +157 -3
- trustgraph_base-1.7.5/trustgraph/api/metrics.py +27 -0
- trustgraph_base-1.7.5/trustgraph/api/socket_client.py +457 -0
- trustgraph_base-1.7.5/trustgraph/api/types.py +82 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/__init__.py +4 -2
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/async_processor.py +2 -2
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/cassandra_config.py +50 -23
- trustgraph_base-1.7.5/trustgraph/base/chunking_service.py +62 -0
- trustgraph_base-1.7.5/trustgraph/base/collection_config_handler.py +127 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/embeddings_service.py +10 -2
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/flow.py +2 -2
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/flow_processor.py +1 -1
- trustgraph_base-1.7.5/trustgraph/base/llm_service.py +228 -0
- trustgraph_base-1.3.19/trustgraph/base/setting_spec.py → trustgraph_base-1.7.5/trustgraph/base/parameter_spec.py +5 -3
- trustgraph_base-1.7.5/trustgraph/base/prompt_client.py +171 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/request_response_spec.py +0 -4
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/subscriber.py +30 -11
- trustgraph_base-1.7.5/trustgraph/base/text_completion_client.py +57 -0
- trustgraph_base-1.7.5/trustgraph/base_version.py +1 -0
- trustgraph_base-1.7.5/trustgraph/clients/llm_client.py +105 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/__init__.py +16 -2
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/__init__.py +1 -0
- trustgraph_base-1.7.5/trustgraph/messaging/translators/agent.py +70 -0
- trustgraph_base-1.7.5/trustgraph/messaging/translators/collection.py +104 -0
- trustgraph_base-1.7.5/trustgraph/messaging/translators/diagnosis.py +67 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/flow.py +10 -5
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/prompt.py +6 -3
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/retrieval.py +66 -22
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/text_completion.py +6 -3
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/rdf.py +1 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/services/__init__.py +4 -1
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/services/agent.py +9 -1
- trustgraph_base-1.7.5/trustgraph/schema/services/collection.py +55 -0
- trustgraph_base-1.7.5/trustgraph/schema/services/diagnosis.py +33 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/services/flow.py +6 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/services/llm.py +3 -1
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/services/prompt.py +7 -1
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/services/retrieval.py +6 -0
- trustgraph_base-1.7.5/trustgraph/schema/services/storage.py +42 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph_base.egg-info/PKG-INFO +2 -1
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph_base.egg-info/SOURCES.txt +16 -1
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph_base.egg-info/requires.txt +1 -0
- trustgraph_base-1.3.19/trustgraph/api/__init__.py +0 -3
- trustgraph_base-1.3.19/trustgraph/api/api.py +0 -70
- trustgraph_base-1.3.19/trustgraph/api/exceptions.py +0 -6
- trustgraph_base-1.3.19/trustgraph/api/types.py +0 -43
- trustgraph_base-1.3.19/trustgraph/base/llm_service.py +0 -139
- trustgraph_base-1.3.19/trustgraph/base/prompt_client.py +0 -100
- trustgraph_base-1.3.19/trustgraph/base/text_completion_client.py +0 -30
- trustgraph_base-1.3.19/trustgraph/base_version.py +0 -1
- trustgraph_base-1.3.19/trustgraph/clients/llm_client.py +0 -44
- trustgraph_base-1.3.19/trustgraph/messaging/translators/agent.py +0 -46
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/README.md +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/setup.cfg +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/api/config.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/api/knowledge.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/api/library.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/agent_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/agent_service.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/consumer.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/consumer_spec.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/document_embeddings_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/document_embeddings_query_service.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/document_embeddings_store_service.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/embeddings_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/graph_embeddings_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/graph_embeddings_query_service.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/graph_embeddings_store_service.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/graph_rag_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/metrics.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/producer.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/producer_spec.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/publisher.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/pubsub.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/spec.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/structured_query_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/subscriber_spec.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/tool_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/tool_service.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/triples_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/triples_query_service.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/base/triples_store_service.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/clients/__init__.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/clients/agent_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/clients/base.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/clients/config_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/clients/document_embeddings_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/clients/document_rag_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/clients/embeddings_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/clients/graph_embeddings_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/clients/graph_rag_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/clients/prompt_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/clients/triples_query_client.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/exceptions.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/knowledge/__init__.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/knowledge/defs.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/knowledge/document.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/knowledge/identifier.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/knowledge/organization.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/knowledge/publication.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/log_level.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/registry.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/base.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/config.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/document_loading.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/embeddings.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/embeddings_query.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/knowledge.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/library.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/metadata.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/nlp_query.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/objects_query.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/primitives.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/structured_query.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/tool.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/messaging/translators/triples.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/objects/__init__.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/objects/field.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/objects/object.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/__init__.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/core/__init__.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/core/metadata.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/core/primitives.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/core/topic.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/knowledge/__init__.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/knowledge/document.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/knowledge/embeddings.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/knowledge/graph.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/knowledge/knowledge.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/knowledge/nlp.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/knowledge/object.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/knowledge/rows.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/knowledge/structured.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/services/config.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/services/library.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/services/lookup.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/services/nlp_query.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/services/objects_query.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/services/query.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph/schema/services/structured_query.py +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph_base.egg-info/dependency_links.txt +0 -0
- {trustgraph_base-1.3.19 → trustgraph_base-1.7.5}/trustgraph_base.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: trustgraph-base
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.5
|
|
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
|
Author-email: "trustgraph.ai" <security@trustgraph.ai>
|
|
6
6
|
Project-URL: Homepage, https://github.com/trustgraph-ai/trustgraph
|
|
@@ -10,5 +10,6 @@ Requires-Python: >=3.8
|
|
|
10
10
|
Description-Content-Type: text/markdown
|
|
11
11
|
Requires-Dist: pulsar-client
|
|
12
12
|
Requires-Dist: prometheus-client
|
|
13
|
+
Requires-Dist: requests
|
|
13
14
|
|
|
14
15
|
See https://trustgraph.ai/
|
|
@@ -0,0 +1,114 @@
|
|
|
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 (
|
|
38
|
+
ProtocolException,
|
|
39
|
+
TrustGraphException,
|
|
40
|
+
AgentError,
|
|
41
|
+
ConfigError,
|
|
42
|
+
DocumentRagError,
|
|
43
|
+
FlowError,
|
|
44
|
+
GatewayError,
|
|
45
|
+
GraphRagError,
|
|
46
|
+
LLMError,
|
|
47
|
+
LoadError,
|
|
48
|
+
LookupError,
|
|
49
|
+
NLPQueryError,
|
|
50
|
+
ObjectsQueryError,
|
|
51
|
+
RequestError,
|
|
52
|
+
StructuredQueryError,
|
|
53
|
+
UnexpectedError,
|
|
54
|
+
# Legacy alias
|
|
55
|
+
ApplicationException,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
__all__ = [
|
|
59
|
+
# Core API
|
|
60
|
+
"Api",
|
|
61
|
+
|
|
62
|
+
# Flow clients
|
|
63
|
+
"Flow",
|
|
64
|
+
"FlowInstance",
|
|
65
|
+
"AsyncFlow",
|
|
66
|
+
"AsyncFlowInstance",
|
|
67
|
+
|
|
68
|
+
# WebSocket clients
|
|
69
|
+
"SocketClient",
|
|
70
|
+
"SocketFlowInstance",
|
|
71
|
+
"AsyncSocketClient",
|
|
72
|
+
"AsyncSocketFlowInstance",
|
|
73
|
+
|
|
74
|
+
# Bulk operation clients
|
|
75
|
+
"BulkClient",
|
|
76
|
+
"AsyncBulkClient",
|
|
77
|
+
|
|
78
|
+
# Metrics clients
|
|
79
|
+
"Metrics",
|
|
80
|
+
"AsyncMetrics",
|
|
81
|
+
|
|
82
|
+
# Types
|
|
83
|
+
"Triple",
|
|
84
|
+
"ConfigKey",
|
|
85
|
+
"ConfigValue",
|
|
86
|
+
"DocumentMetadata",
|
|
87
|
+
"ProcessingMetadata",
|
|
88
|
+
"CollectionMetadata",
|
|
89
|
+
"StreamingChunk",
|
|
90
|
+
"AgentThought",
|
|
91
|
+
"AgentObservation",
|
|
92
|
+
"AgentAnswer",
|
|
93
|
+
"RAGChunk",
|
|
94
|
+
|
|
95
|
+
# Exceptions
|
|
96
|
+
"ProtocolException",
|
|
97
|
+
"TrustGraphException",
|
|
98
|
+
"AgentError",
|
|
99
|
+
"ConfigError",
|
|
100
|
+
"DocumentRagError",
|
|
101
|
+
"FlowError",
|
|
102
|
+
"GatewayError",
|
|
103
|
+
"GraphRagError",
|
|
104
|
+
"LLMError",
|
|
105
|
+
"LoadError",
|
|
106
|
+
"LookupError",
|
|
107
|
+
"NLPQueryError",
|
|
108
|
+
"ObjectsQueryError",
|
|
109
|
+
"RequestError",
|
|
110
|
+
"StructuredQueryError",
|
|
111
|
+
"UnexpectedError",
|
|
112
|
+
"ApplicationException", # Legacy alias
|
|
113
|
+
]
|
|
114
|
+
|
|
@@ -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)
|