trustgraph-base 2.2.26__tar.gz → 2.3.0__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.
Files changed (165) hide show
  1. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/PKG-INFO +1 -1
  2. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/__init__.py +2 -0
  3. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/async_flow.py +13 -7
  4. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/async_socket_client.py +23 -8
  5. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/flow.py +32 -10
  6. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/socket_client.py +62 -20
  7. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/types.py +29 -0
  8. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/__init__.py +4 -2
  9. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/prompt_client.py +73 -14
  10. trustgraph_base-2.3.0/trustgraph/base/text_completion_client.py +80 -0
  11. trustgraph_base-2.3.0/trustgraph/base_version.py +1 -0
  12. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/agent.py +7 -0
  13. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/prompt.py +7 -0
  14. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/retrieval.py +14 -0
  15. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/text_completion.py +3 -3
  16. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/agent.py +5 -0
  17. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/llm.py +3 -3
  18. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/prompt.py +5 -0
  19. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/retrieval.py +6 -0
  20. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph_base.egg-info/PKG-INFO +1 -1
  21. trustgraph_base-2.2.26/trustgraph/base/text_completion_client.py +0 -57
  22. trustgraph_base-2.2.26/trustgraph/base_version.py +0 -1
  23. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/README.md +0 -0
  24. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/pyproject.toml +0 -0
  25. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/setup.cfg +0 -0
  26. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/api.py +0 -0
  27. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/async_bulk_client.py +0 -0
  28. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/async_metrics.py +0 -0
  29. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/bulk_client.py +0 -0
  30. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/collection.py +0 -0
  31. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/config.py +0 -0
  32. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/exceptions.py +0 -0
  33. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/explainability.py +0 -0
  34. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/knowledge.py +0 -0
  35. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/library.py +0 -0
  36. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/api/metrics.py +0 -0
  37. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/agent_client.py +0 -0
  38. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/agent_service.py +0 -0
  39. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/async_processor.py +0 -0
  40. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/backend.py +0 -0
  41. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/cassandra_config.py +0 -0
  42. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/chunking_service.py +0 -0
  43. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/collection_config_handler.py +0 -0
  44. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/consumer.py +0 -0
  45. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/consumer_spec.py +0 -0
  46. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/document_embeddings_client.py +0 -0
  47. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/document_embeddings_query_service.py +0 -0
  48. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/document_embeddings_store_service.py +0 -0
  49. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/dynamic_tool_service.py +0 -0
  50. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/embeddings_client.py +0 -0
  51. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/embeddings_service.py +0 -0
  52. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/flow.py +0 -0
  53. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/flow_processor.py +0 -0
  54. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/graph_embeddings_client.py +0 -0
  55. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/graph_embeddings_query_service.py +0 -0
  56. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/graph_embeddings_store_service.py +0 -0
  57. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/graph_rag_client.py +0 -0
  58. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/librarian_client.py +0 -0
  59. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/llm_service.py +0 -0
  60. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/logging.py +0 -0
  61. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/metrics.py +0 -0
  62. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/parameter_spec.py +0 -0
  63. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/producer.py +0 -0
  64. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/producer_spec.py +0 -0
  65. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/publisher.py +0 -0
  66. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/pubsub.py +0 -0
  67. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/pulsar_backend.py +0 -0
  68. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/rabbitmq_backend.py +0 -0
  69. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/request_response_spec.py +0 -0
  70. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/row_embeddings_query_client.py +0 -0
  71. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/serialization.py +0 -0
  72. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/spec.py +0 -0
  73. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/structured_query_client.py +0 -0
  74. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/subscriber.py +0 -0
  75. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/subscriber_spec.py +0 -0
  76. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/tool_client.py +0 -0
  77. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/tool_service.py +0 -0
  78. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/tool_service_client.py +0 -0
  79. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/triples_client.py +0 -0
  80. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/triples_query_service.py +0 -0
  81. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/base/triples_store_service.py +0 -0
  82. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/clients/__init__.py +0 -0
  83. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/clients/agent_client.py +0 -0
  84. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/clients/base.py +0 -0
  85. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/clients/config_client.py +0 -0
  86. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/clients/document_embeddings_client.py +0 -0
  87. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/clients/document_rag_client.py +0 -0
  88. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/clients/embeddings_client.py +0 -0
  89. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/clients/graph_embeddings_client.py +0 -0
  90. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/clients/graph_rag_client.py +0 -0
  91. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/clients/llm_client.py +0 -0
  92. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/clients/prompt_client.py +0 -0
  93. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/clients/row_embeddings_client.py +0 -0
  94. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/clients/triples_query_client.py +0 -0
  95. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/exceptions.py +0 -0
  96. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/knowledge/__init__.py +0 -0
  97. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/knowledge/defs.py +0 -0
  98. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/knowledge/document.py +0 -0
  99. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/knowledge/identifier.py +0 -0
  100. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/knowledge/organization.py +0 -0
  101. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/knowledge/publication.py +0 -0
  102. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/log_level.py +0 -0
  103. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/__init__.py +0 -0
  104. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/registry.py +0 -0
  105. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/__init__.py +0 -0
  106. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/base.py +0 -0
  107. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/collection.py +0 -0
  108. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/config.py +0 -0
  109. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/diagnosis.py +0 -0
  110. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/document_loading.py +0 -0
  111. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/embeddings.py +0 -0
  112. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/embeddings_query.py +0 -0
  113. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/flow.py +0 -0
  114. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/knowledge.py +0 -0
  115. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/library.py +0 -0
  116. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/metadata.py +0 -0
  117. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/nlp_query.py +0 -0
  118. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/primitives.py +0 -0
  119. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/rows_query.py +0 -0
  120. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/sparql_query.py +0 -0
  121. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/structured_query.py +0 -0
  122. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/tool.py +0 -0
  123. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/messaging/translators/triples.py +0 -0
  124. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/objects/__init__.py +0 -0
  125. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/objects/field.py +0 -0
  126. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/objects/object.py +0 -0
  127. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/provenance/__init__.py +0 -0
  128. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/provenance/agent.py +0 -0
  129. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/provenance/namespaces.py +0 -0
  130. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/provenance/triples.py +0 -0
  131. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/provenance/uris.py +0 -0
  132. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/provenance/vocabulary.py +0 -0
  133. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/rdf.py +0 -0
  134. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/__init__.py +0 -0
  135. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/core/__init__.py +0 -0
  136. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/core/metadata.py +0 -0
  137. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/core/primitives.py +0 -0
  138. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/core/topic.py +0 -0
  139. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/knowledge/__init__.py +0 -0
  140. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/knowledge/document.py +0 -0
  141. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/knowledge/embeddings.py +0 -0
  142. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/knowledge/graph.py +0 -0
  143. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/knowledge/knowledge.py +0 -0
  144. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/knowledge/nlp.py +0 -0
  145. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/knowledge/object.py +0 -0
  146. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/knowledge/rows.py +0 -0
  147. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/knowledge/structured.py +0 -0
  148. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/__init__.py +0 -0
  149. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/collection.py +0 -0
  150. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/config.py +0 -0
  151. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/diagnosis.py +0 -0
  152. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/flow.py +0 -0
  153. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/library.py +0 -0
  154. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/lookup.py +0 -0
  155. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/nlp_query.py +0 -0
  156. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/query.py +0 -0
  157. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/rows_query.py +0 -0
  158. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/sparql_query.py +0 -0
  159. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/storage.py +0 -0
  160. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/structured_query.py +0 -0
  161. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph/schema/services/tool_service.py +0 -0
  162. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph_base.egg-info/SOURCES.txt +0 -0
  163. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph_base.egg-info/dependency_links.txt +0 -0
  164. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/trustgraph_base.egg-info/requires.txt +0 -0
  165. {trustgraph_base-2.2.26 → trustgraph_base-2.3.0}/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: 2.2.26
3
+ Version: 2.3.0
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
@@ -107,6 +107,7 @@ from .types import (
107
107
  AgentObservation,
108
108
  AgentAnswer,
109
109
  RAGChunk,
110
+ TextCompletionResult,
110
111
  ProvenanceEvent,
111
112
  )
112
113
 
@@ -185,6 +186,7 @@ __all__ = [
185
186
  "AgentObservation",
186
187
  "AgentAnswer",
187
188
  "RAGChunk",
189
+ "TextCompletionResult",
188
190
  "ProvenanceEvent",
189
191
 
190
192
  # Exceptions
@@ -14,6 +14,8 @@ import aiohttp
14
14
  import json
15
15
  from typing import Optional, Dict, Any, List
16
16
 
17
+ from . types import TextCompletionResult
18
+
17
19
  from . exceptions import ProtocolException, ApplicationException
18
20
 
19
21
 
@@ -434,12 +436,11 @@ class AsyncFlowInstance:
434
436
 
435
437
  return await self.request("agent", request_data)
436
438
 
437
- async def text_completion(self, system: str, prompt: str, **kwargs: Any) -> str:
439
+ async def text_completion(self, system: str, prompt: str, **kwargs: Any) -> TextCompletionResult:
438
440
  """
439
441
  Generate text completion (non-streaming).
440
442
 
441
443
  Generates a text response from an LLM given a system prompt and user prompt.
442
- Returns the complete response text.
443
444
 
444
445
  Note: This method does not support streaming. For streaming text generation,
445
446
  use AsyncSocketFlowInstance.text_completion() instead.
@@ -450,19 +451,19 @@ class AsyncFlowInstance:
450
451
  **kwargs: Additional service-specific parameters
451
452
 
452
453
  Returns:
453
- str: Complete generated text response
454
+ TextCompletionResult: Result with text, in_token, out_token, model
454
455
 
455
456
  Example:
456
457
  ```python
457
458
  async_flow = await api.async_flow()
458
459
  flow = async_flow.id("default")
459
460
 
460
- # Generate text
461
- response = await flow.text_completion(
461
+ result = await flow.text_completion(
462
462
  system="You are a helpful assistant.",
463
463
  prompt="Explain quantum computing in simple terms."
464
464
  )
465
- print(response)
465
+ print(result.text)
466
+ print(f"Tokens: {result.in_token} in, {result.out_token} out")
466
467
  ```
467
468
  """
468
469
  request_data = {
@@ -473,7 +474,12 @@ class AsyncFlowInstance:
473
474
  request_data.update(kwargs)
474
475
 
475
476
  result = await self.request("text-completion", request_data)
476
- return result.get("response", "")
477
+ return TextCompletionResult(
478
+ text=result.get("response", ""),
479
+ in_token=result.get("in_token"),
480
+ out_token=result.get("out_token"),
481
+ model=result.get("model"),
482
+ )
477
483
 
478
484
  async def graph_rag(self, query: str, user: str, collection: str,
479
485
  max_subgraph_size: int = 1000, max_subgraph_count: int = 5,
@@ -4,7 +4,7 @@ import asyncio
4
4
  import websockets
5
5
  from typing import Optional, Dict, Any, AsyncIterator, Union
6
6
 
7
- from . types import AgentThought, AgentObservation, AgentAnswer, RAGChunk
7
+ from . types import AgentThought, AgentObservation, AgentAnswer, RAGChunk, TextCompletionResult
8
8
  from . exceptions import ProtocolException, ApplicationException
9
9
 
10
10
 
@@ -199,7 +199,10 @@ class AsyncSocketClient:
199
199
  return AgentAnswer(
200
200
  content=resp.get("content", ""),
201
201
  end_of_message=resp.get("end_of_message", False),
202
- end_of_dialog=resp.get("end_of_dialog", False)
202
+ end_of_dialog=resp.get("end_of_dialog", False),
203
+ in_token=resp.get("in_token"),
204
+ out_token=resp.get("out_token"),
205
+ model=resp.get("model"),
203
206
  )
204
207
  elif chunk_type == "action":
205
208
  return AgentThought(
@@ -211,7 +214,10 @@ class AsyncSocketClient:
211
214
  return RAGChunk(
212
215
  content=content,
213
216
  end_of_stream=resp.get("end_of_stream", False),
214
- error=None
217
+ error=None,
218
+ in_token=resp.get("in_token"),
219
+ out_token=resp.get("out_token"),
220
+ model=resp.get("model"),
215
221
  )
216
222
 
217
223
  async def aclose(self):
@@ -269,7 +275,11 @@ class AsyncSocketFlowInstance:
269
275
  return await self.client._send_request("agent", self.flow_id, request)
270
276
 
271
277
  async def text_completion(self, system: str, prompt: str, streaming: bool = False, **kwargs):
272
- """Text completion with optional streaming"""
278
+ """Text completion with optional streaming.
279
+
280
+ Non-streaming: returns a TextCompletionResult with text and token counts.
281
+ Streaming: returns an async iterator of RAGChunk (with token counts on the final chunk).
282
+ """
273
283
  request = {
274
284
  "system": system,
275
285
  "prompt": prompt,
@@ -281,13 +291,18 @@ class AsyncSocketFlowInstance:
281
291
  return self._text_completion_streaming(request)
282
292
  else:
283
293
  result = await self.client._send_request("text-completion", self.flow_id, request)
284
- return result.get("response", "")
294
+ return TextCompletionResult(
295
+ text=result.get("response", ""),
296
+ in_token=result.get("in_token"),
297
+ out_token=result.get("out_token"),
298
+ model=result.get("model"),
299
+ )
285
300
 
286
301
  async def _text_completion_streaming(self, request):
287
- """Helper for streaming text completion"""
302
+ """Helper for streaming text completion. Yields RAGChunk objects."""
288
303
  async for chunk in self.client._send_request_streaming("text-completion", self.flow_id, request):
289
- if hasattr(chunk, 'content'):
290
- yield chunk.content
304
+ if isinstance(chunk, RAGChunk):
305
+ yield chunk
291
306
 
292
307
  async def graph_rag(self, query: str, user: str, collection: str,
293
308
  max_subgraph_size: int = 1000, max_subgraph_count: int = 5,
@@ -11,7 +11,7 @@ import base64
11
11
 
12
12
  from .. knowledge import hash, Uri, Literal, QuotedTriple
13
13
  from .. schema import IRI, LITERAL, TRIPLE
14
- from . types import Triple
14
+ from . types import Triple, TextCompletionResult
15
15
  from . exceptions import ProtocolException
16
16
 
17
17
 
@@ -360,16 +360,17 @@ class FlowInstance:
360
360
  prompt: User prompt/question
361
361
 
362
362
  Returns:
363
- str: Generated response text
363
+ TextCompletionResult: Result with text, in_token, out_token, model
364
364
 
365
365
  Example:
366
366
  ```python
367
367
  flow = api.flow().id("default")
368
- response = flow.text_completion(
368
+ result = flow.text_completion(
369
369
  system="You are a helpful assistant",
370
370
  prompt="What is quantum computing?"
371
371
  )
372
- print(response)
372
+ print(result.text)
373
+ print(f"Tokens: {result.in_token} in, {result.out_token} out")
373
374
  ```
374
375
  """
375
376
 
@@ -379,10 +380,17 @@ class FlowInstance:
379
380
  "prompt": prompt
380
381
  }
381
382
 
382
- return self.request(
383
+ result = self.request(
383
384
  "service/text-completion",
384
385
  input
385
- )["response"]
386
+ )
387
+
388
+ return TextCompletionResult(
389
+ text=result.get("response", ""),
390
+ in_token=result.get("in_token"),
391
+ out_token=result.get("out_token"),
392
+ model=result.get("model"),
393
+ )
386
394
 
387
395
  def agent(self, question, user="trustgraph", state=None, group=None, history=None):
388
396
  """
@@ -498,10 +506,17 @@ class FlowInstance:
498
506
  "edge-limit": edge_limit,
499
507
  }
500
508
 
501
- return self.request(
509
+ result = self.request(
502
510
  "service/graph-rag",
503
511
  input
504
- )["response"]
512
+ )
513
+
514
+ return TextCompletionResult(
515
+ text=result.get("response", ""),
516
+ in_token=result.get("in_token"),
517
+ out_token=result.get("out_token"),
518
+ model=result.get("model"),
519
+ )
505
520
 
506
521
  def document_rag(
507
522
  self, query, user="trustgraph", collection="default",
@@ -543,10 +558,17 @@ class FlowInstance:
543
558
  "doc-limit": doc_limit,
544
559
  }
545
560
 
546
- return self.request(
561
+ result = self.request(
547
562
  "service/document-rag",
548
563
  input
549
- )["response"]
564
+ )
565
+
566
+ return TextCompletionResult(
567
+ text=result.get("response", ""),
568
+ in_token=result.get("in_token"),
569
+ out_token=result.get("out_token"),
570
+ model=result.get("model"),
571
+ )
550
572
 
551
573
  def embeddings(self, texts):
552
574
  """
@@ -14,7 +14,7 @@ import websockets
14
14
  from typing import Optional, Dict, Any, Iterator, Union, List
15
15
  from threading import Lock
16
16
 
17
- from . types import AgentThought, AgentObservation, AgentAnswer, RAGChunk, StreamingChunk, ProvenanceEvent
17
+ from . types import AgentThought, AgentObservation, AgentAnswer, RAGChunk, StreamingChunk, ProvenanceEvent, TextCompletionResult
18
18
  from . exceptions import ProtocolException, raise_from_error_dict
19
19
 
20
20
 
@@ -393,6 +393,9 @@ class SocketClient:
393
393
  end_of_message=resp.get("end_of_message", False),
394
394
  end_of_dialog=resp.get("end_of_dialog", False),
395
395
  message_id=resp.get("message_id", ""),
396
+ in_token=resp.get("in_token"),
397
+ out_token=resp.get("out_token"),
398
+ model=resp.get("model"),
396
399
  )
397
400
  elif chunk_type == "action":
398
401
  return AgentThought(
@@ -404,7 +407,10 @@ class SocketClient:
404
407
  return RAGChunk(
405
408
  content=content,
406
409
  end_of_stream=resp.get("end_of_stream", False),
407
- error=None
410
+ error=None,
411
+ in_token=resp.get("in_token"),
412
+ out_token=resp.get("out_token"),
413
+ model=resp.get("model"),
408
414
  )
409
415
 
410
416
  def _build_provenance_event(self, resp: Dict[str, Any]) -> ProvenanceEvent:
@@ -543,8 +549,12 @@ class SocketFlowInstance:
543
549
  streaming=True, include_provenance=True
544
550
  )
545
551
 
546
- def text_completion(self, system: str, prompt: str, streaming: bool = False, **kwargs) -> Union[str, Iterator[str]]:
547
- """Execute text completion with optional streaming."""
552
+ def text_completion(self, system: str, prompt: str, streaming: bool = False, **kwargs) -> Union[TextCompletionResult, Iterator[RAGChunk]]:
553
+ """Execute text completion with optional streaming.
554
+
555
+ Non-streaming: returns a TextCompletionResult with text and token counts.
556
+ Streaming: returns an iterator of RAGChunk (with token counts on the final chunk).
557
+ """
548
558
  request = {
549
559
  "system": system,
550
560
  "prompt": prompt,
@@ -557,12 +567,17 @@ class SocketFlowInstance:
557
567
  if streaming:
558
568
  return self._text_completion_generator(result)
559
569
  else:
560
- return result.get("response", "")
570
+ return TextCompletionResult(
571
+ text=result.get("response", ""),
572
+ in_token=result.get("in_token"),
573
+ out_token=result.get("out_token"),
574
+ model=result.get("model"),
575
+ )
561
576
 
562
- def _text_completion_generator(self, result: Iterator[StreamingChunk]) -> Iterator[str]:
577
+ def _text_completion_generator(self, result: Iterator[StreamingChunk]) -> Iterator[RAGChunk]:
563
578
  for chunk in result:
564
- if hasattr(chunk, 'content'):
565
- yield chunk.content
579
+ if isinstance(chunk, RAGChunk):
580
+ yield chunk
566
581
 
567
582
  def graph_rag(
568
583
  self,
@@ -577,8 +592,12 @@ class SocketFlowInstance:
577
592
  edge_limit: int = 25,
578
593
  streaming: bool = False,
579
594
  **kwargs: Any
580
- ) -> Union[str, Iterator[str]]:
581
- """Execute graph-based RAG query with optional streaming."""
595
+ ) -> Union[TextCompletionResult, Iterator[RAGChunk]]:
596
+ """Execute graph-based RAG query with optional streaming.
597
+
598
+ Non-streaming: returns a TextCompletionResult with text and token counts.
599
+ Streaming: returns an iterator of RAGChunk (with token counts on the final chunk).
600
+ """
582
601
  request = {
583
602
  "query": query,
584
603
  "user": user,
@@ -598,7 +617,12 @@ class SocketFlowInstance:
598
617
  if streaming:
599
618
  return self._rag_generator(result)
600
619
  else:
601
- return result.get("response", "")
620
+ return TextCompletionResult(
621
+ text=result.get("response", ""),
622
+ in_token=result.get("in_token"),
623
+ out_token=result.get("out_token"),
624
+ model=result.get("model"),
625
+ )
602
626
 
603
627
  def graph_rag_explain(
604
628
  self,
@@ -642,8 +666,12 @@ class SocketFlowInstance:
642
666
  doc_limit: int = 10,
643
667
  streaming: bool = False,
644
668
  **kwargs: Any
645
- ) -> Union[str, Iterator[str]]:
646
- """Execute document-based RAG query with optional streaming."""
669
+ ) -> Union[TextCompletionResult, Iterator[RAGChunk]]:
670
+ """Execute document-based RAG query with optional streaming.
671
+
672
+ Non-streaming: returns a TextCompletionResult with text and token counts.
673
+ Streaming: returns an iterator of RAGChunk (with token counts on the final chunk).
674
+ """
647
675
  request = {
648
676
  "query": query,
649
677
  "user": user,
@@ -658,7 +686,12 @@ class SocketFlowInstance:
658
686
  if streaming:
659
687
  return self._rag_generator(result)
660
688
  else:
661
- return result.get("response", "")
689
+ return TextCompletionResult(
690
+ text=result.get("response", ""),
691
+ in_token=result.get("in_token"),
692
+ out_token=result.get("out_token"),
693
+ model=result.get("model"),
694
+ )
662
695
 
663
696
  def document_rag_explain(
664
697
  self,
@@ -684,10 +717,10 @@ class SocketFlowInstance:
684
717
  streaming=True, include_provenance=True
685
718
  )
686
719
 
687
- def _rag_generator(self, result: Iterator[StreamingChunk]) -> Iterator[str]:
720
+ def _rag_generator(self, result: Iterator[StreamingChunk]) -> Iterator[RAGChunk]:
688
721
  for chunk in result:
689
- if hasattr(chunk, 'content'):
690
- yield chunk.content
722
+ if isinstance(chunk, RAGChunk):
723
+ yield chunk
691
724
 
692
725
  def prompt(
693
726
  self,
@@ -695,8 +728,12 @@ class SocketFlowInstance:
695
728
  variables: Dict[str, str],
696
729
  streaming: bool = False,
697
730
  **kwargs: Any
698
- ) -> Union[str, Iterator[str]]:
699
- """Execute a prompt template with optional streaming."""
731
+ ) -> Union[TextCompletionResult, Iterator[RAGChunk]]:
732
+ """Execute a prompt template with optional streaming.
733
+
734
+ Non-streaming: returns a TextCompletionResult with text and token counts.
735
+ Streaming: returns an iterator of RAGChunk (with token counts on the final chunk).
736
+ """
700
737
  request = {
701
738
  "id": id,
702
739
  "variables": variables,
@@ -709,7 +746,12 @@ class SocketFlowInstance:
709
746
  if streaming:
710
747
  return self._rag_generator(result)
711
748
  else:
712
- return result.get("response", "")
749
+ return TextCompletionResult(
750
+ text=result.get("text", result.get("response", "")),
751
+ in_token=result.get("in_token"),
752
+ out_token=result.get("out_token"),
753
+ model=result.get("model"),
754
+ )
713
755
 
714
756
  def graph_embeddings_query(
715
757
  self,
@@ -189,6 +189,9 @@ class AgentAnswer(StreamingChunk):
189
189
  chunk_type: str = "final-answer"
190
190
  end_of_dialog: bool = False
191
191
  message_id: str = ""
192
+ in_token: Optional[int] = None
193
+ out_token: Optional[int] = None
194
+ model: Optional[str] = None
192
195
 
193
196
  @dataclasses.dataclass
194
197
  class RAGChunk(StreamingChunk):
@@ -202,11 +205,37 @@ class RAGChunk(StreamingChunk):
202
205
  content: Generated text content
203
206
  end_of_stream: True if this is the final chunk of the stream
204
207
  error: Optional error information if an error occurred
208
+ in_token: Input token count (populated on the final chunk, 0 otherwise)
209
+ out_token: Output token count (populated on the final chunk, 0 otherwise)
210
+ model: Model identifier (populated on the final chunk, empty otherwise)
205
211
  chunk_type: Always "rag"
206
212
  """
207
213
  chunk_type: str = "rag"
208
214
  end_of_stream: bool = False
209
215
  error: Optional[Dict[str, str]] = None
216
+ in_token: Optional[int] = None
217
+ out_token: Optional[int] = None
218
+ model: Optional[str] = None
219
+
220
+ @dataclasses.dataclass
221
+ class TextCompletionResult:
222
+ """
223
+ Result from a text completion request.
224
+
225
+ Returned by text_completion() in both streaming and non-streaming modes.
226
+ In streaming mode, text is None (chunks are delivered via the iterator).
227
+ In non-streaming mode, text contains the complete response.
228
+
229
+ Attributes:
230
+ text: Complete response text (None in streaming mode)
231
+ in_token: Input token count (None if not available)
232
+ out_token: Output token count (None if not available)
233
+ model: Model identifier (None if not available)
234
+ """
235
+ text: Optional[str]
236
+ in_token: Optional[int] = None
237
+ out_token: Optional[int] = None
238
+ model: Optional[str] = None
210
239
 
211
240
  @dataclasses.dataclass
212
241
  class ProvenanceEvent:
@@ -18,8 +18,10 @@ from . librarian_client import LibrarianClient
18
18
  from . chunking_service import ChunkingService
19
19
  from . embeddings_service import EmbeddingsService
20
20
  from . embeddings_client import EmbeddingsClientSpec
21
- from . text_completion_client import TextCompletionClientSpec
22
- from . prompt_client import PromptClientSpec
21
+ from . text_completion_client import (
22
+ TextCompletionClientSpec, TextCompletionClient, TextCompletionResult,
23
+ )
24
+ from . prompt_client import PromptClientSpec, PromptClient, PromptResult
23
25
  from . triples_store_service import TriplesStoreService
24
26
  from . graph_embeddings_store_service import GraphEmbeddingsStoreService
25
27
  from . document_embeddings_store_service import DocumentEmbeddingsStoreService
@@ -1,10 +1,22 @@
1
1
 
2
2
  import json
3
3
  import asyncio
4
+ from dataclasses import dataclass
5
+ from typing import Optional, Any
4
6
 
5
7
  from . request_response_spec import RequestResponse, RequestResponseSpec
6
8
  from .. schema import PromptRequest, PromptResponse
7
9
 
10
+ @dataclass
11
+ class PromptResult:
12
+ response_type: str # "text", "json", or "jsonl"
13
+ text: Optional[str] = None # populated for "text"
14
+ object: Any = None # populated for "json"
15
+ objects: Optional[list] = None # populated for "jsonl"
16
+ in_token: Optional[int] = None
17
+ out_token: Optional[int] = None
18
+ model: Optional[str] = None
19
+
8
20
  class PromptClient(RequestResponse):
9
21
 
10
22
  async def prompt(self, id, variables, timeout=600, streaming=False, chunk_callback=None):
@@ -26,17 +38,40 @@ class PromptClient(RequestResponse):
26
38
  if resp.error:
27
39
  raise RuntimeError(resp.error.message)
28
40
 
29
- if resp.text: return resp.text
30
-
31
- return json.loads(resp.object)
41
+ if resp.text:
42
+ return PromptResult(
43
+ response_type="text",
44
+ text=resp.text,
45
+ in_token=resp.in_token,
46
+ out_token=resp.out_token,
47
+ model=resp.model,
48
+ )
49
+
50
+ parsed = json.loads(resp.object)
51
+
52
+ if isinstance(parsed, list):
53
+ return PromptResult(
54
+ response_type="jsonl",
55
+ objects=parsed,
56
+ in_token=resp.in_token,
57
+ out_token=resp.out_token,
58
+ model=resp.model,
59
+ )
60
+
61
+ return PromptResult(
62
+ response_type="json",
63
+ object=parsed,
64
+ in_token=resp.in_token,
65
+ out_token=resp.out_token,
66
+ model=resp.model,
67
+ )
32
68
 
33
69
  else:
34
70
 
35
- last_text = ""
36
- last_object = None
71
+ last_resp = None
37
72
 
38
73
  async def forward_chunks(resp):
39
- nonlocal last_text, last_object
74
+ nonlocal last_resp
40
75
 
41
76
  if resp.error:
42
77
  raise RuntimeError(resp.error.message)
@@ -44,14 +79,13 @@ class PromptClient(RequestResponse):
44
79
  end_stream = getattr(resp, 'end_of_stream', False)
45
80
 
46
81
  if resp.text is not None:
47
- last_text = resp.text
48
82
  if chunk_callback:
49
83
  if asyncio.iscoroutinefunction(chunk_callback):
50
84
  await chunk_callback(resp.text, end_stream)
51
85
  else:
52
86
  chunk_callback(resp.text, end_stream)
53
- elif resp.object:
54
- last_object = resp.object
87
+
88
+ last_resp = resp
55
89
 
56
90
  return end_stream
57
91
 
@@ -70,10 +104,36 @@ class PromptClient(RequestResponse):
70
104
  timeout=timeout
71
105
  )
72
106
 
73
- if last_text:
74
- return last_text
75
-
76
- return json.loads(last_object) if last_object else None
107
+ if last_resp is None:
108
+ return PromptResult(response_type="text")
109
+
110
+ if last_resp.object:
111
+ parsed = json.loads(last_resp.object)
112
+
113
+ if isinstance(parsed, list):
114
+ return PromptResult(
115
+ response_type="jsonl",
116
+ objects=parsed,
117
+ in_token=last_resp.in_token,
118
+ out_token=last_resp.out_token,
119
+ model=last_resp.model,
120
+ )
121
+
122
+ return PromptResult(
123
+ response_type="json",
124
+ object=parsed,
125
+ in_token=last_resp.in_token,
126
+ out_token=last_resp.out_token,
127
+ model=last_resp.model,
128
+ )
129
+
130
+ return PromptResult(
131
+ response_type="text",
132
+ text=last_resp.text,
133
+ in_token=last_resp.in_token,
134
+ out_token=last_resp.out_token,
135
+ model=last_resp.model,
136
+ )
77
137
 
78
138
  async def extract_definitions(self, text, timeout=600):
79
139
  return await self.prompt(
@@ -152,4 +212,3 @@ class PromptClientSpec(RequestResponseSpec):
152
212
  response_schema = PromptResponse,
153
213
  impl = PromptClient,
154
214
  )
155
-
@@ -0,0 +1,80 @@
1
+
2
+ from dataclasses import dataclass
3
+ from typing import Optional
4
+
5
+ from . request_response_spec import RequestResponse, RequestResponseSpec
6
+ from .. schema import TextCompletionRequest, TextCompletionResponse
7
+
8
+ @dataclass
9
+ class TextCompletionResult:
10
+ text: Optional[str]
11
+ in_token: Optional[int] = None
12
+ out_token: Optional[int] = None
13
+ model: Optional[str] = None
14
+
15
+ class TextCompletionClient(RequestResponse):
16
+
17
+ async def text_completion(self, system, prompt, timeout=600):
18
+
19
+ resp = await self.request(
20
+ TextCompletionRequest(
21
+ system = system, prompt = prompt, streaming = False
22
+ ),
23
+ timeout=timeout
24
+ )
25
+
26
+ if resp.error:
27
+ raise RuntimeError(resp.error.message)
28
+
29
+ return TextCompletionResult(
30
+ text = resp.response,
31
+ in_token = resp.in_token,
32
+ out_token = resp.out_token,
33
+ model = resp.model,
34
+ )
35
+
36
+ async def text_completion_stream(
37
+ self, system, prompt, handler, timeout=600,
38
+ ):
39
+ """
40
+ Streaming text completion. `handler` is an async callable invoked
41
+ once per chunk with the chunk's TextCompletionResponse. Returns a
42
+ TextCompletionResult with text=None and token counts / model taken
43
+ from the end_of_stream message.
44
+ """
45
+
46
+ async def on_chunk(resp):
47
+
48
+ if resp.error:
49
+ raise RuntimeError(resp.error.message)
50
+
51
+ await handler(resp)
52
+
53
+ return getattr(resp, "end_of_stream", False)
54
+
55
+ final = await self.request(
56
+ TextCompletionRequest(
57
+ system = system, prompt = prompt, streaming = True
58
+ ),
59
+ recipient=on_chunk,
60
+ timeout=timeout,
61
+ )
62
+
63
+ return TextCompletionResult(
64
+ text = None,
65
+ in_token = final.in_token,
66
+ out_token = final.out_token,
67
+ model = final.model,
68
+ )
69
+
70
+ class TextCompletionClientSpec(RequestResponseSpec):
71
+ def __init__(
72
+ self, request_name, response_name,
73
+ ):
74
+ super(TextCompletionClientSpec, self).__init__(
75
+ request_name = request_name,
76
+ request_schema = TextCompletionRequest,
77
+ response_name = response_name,
78
+ response_schema = TextCompletionResponse,
79
+ impl = TextCompletionClient,
80
+ )