quantumflow-sdk 0.2.0__tar.gz → 0.2.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.
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/PKG-INFO +1 -1
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/pyproject.toml +1 -1
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/__init__.py +1 -1
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/integrations/__init__.py +14 -0
- quantumflow_sdk-0.2.1/src/quantumflow/integrations/openai_functions.py +578 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow_sdk.egg-info/PKG-INFO +1 -1
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow_sdk.egg-info/SOURCES.txt +1 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/README.md +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/setup.cfg +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/api/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/api/auth.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/api/main.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/api/models.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/api/routes/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/api/routes/auth_routes.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/api/routes/teleport_routes.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/db/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/db/crud.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/db/database.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/db/models.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/compression/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/compression/amplitude_amplification.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/compression/qft_compression.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/compression/token_compression.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/cryptography/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/cryptography/qkd.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/cryptography/qrng.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/machine_learning/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/machine_learning/qnn.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/machine_learning/qsvm.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/machine_learning/vqe.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/optimization/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/optimization/grover.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/optimization/qaoa.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/optimization/quantum_annealing.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/utility/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/utility/circuit_optimizer.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/utility/error_correction.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/api/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/api/routes/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/api/routes/billing_routes.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/api/routes/workflow_routes.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/backends/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/backends/base_backend.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/backends/braket_backend.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/backends/ibm_backend.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/backends/simulator_backend.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/billing/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/billing/models.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/billing/stripe_service.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/core/__init__.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/core/entanglement.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/core/memory.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/core/quantum_backprop.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/core/quantum_compressor.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/core/teleportation.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/core/workflow.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/integrations/autogen_tools.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/integrations/crewai_agents.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/integrations/crewai_tools.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/integrations/langchain_memory.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/integrations/langchain_tools.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/integrations/mcp_server.py +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow_sdk.egg-info/dependency_links.txt +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow_sdk.egg-info/entry_points.txt +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow_sdk.egg-info/requires.txt +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow_sdk.egg-info/top_level.txt +0 -0
- {quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/tests/test_quantum_compressor.py +0 -0
|
@@ -2,12 +2,21 @@
|
|
|
2
2
|
QuantumFlow Integrations.
|
|
3
3
|
|
|
4
4
|
Provides integration with popular AI agent frameworks:
|
|
5
|
+
- OpenAI: Function calling for GPT-4/GPT-3.5-turbo
|
|
5
6
|
- LangChain: Tools, Memory, and Chains
|
|
6
7
|
- CrewAI: Tools and Agents
|
|
7
8
|
- AutoGen: Agents and Function Tools
|
|
8
9
|
- MCP: Model Context Protocol Server
|
|
9
10
|
"""
|
|
10
11
|
|
|
12
|
+
# OpenAI Integration
|
|
13
|
+
from quantumflow.integrations.openai_functions import (
|
|
14
|
+
get_quantum_functions as get_openai_functions,
|
|
15
|
+
get_quantum_tools as get_openai_tools,
|
|
16
|
+
execute_quantum_function,
|
|
17
|
+
QuantumAssistant,
|
|
18
|
+
)
|
|
19
|
+
|
|
11
20
|
# LangChain Integration
|
|
12
21
|
from quantumflow.integrations.langchain_tools import (
|
|
13
22
|
QuantumCompressTool,
|
|
@@ -64,6 +73,11 @@ from quantumflow.integrations.mcp_server import (
|
|
|
64
73
|
)
|
|
65
74
|
|
|
66
75
|
__all__ = [
|
|
76
|
+
# OpenAI Functions
|
|
77
|
+
"get_openai_functions",
|
|
78
|
+
"get_openai_tools",
|
|
79
|
+
"execute_quantum_function",
|
|
80
|
+
"QuantumAssistant",
|
|
67
81
|
# LangChain Tools
|
|
68
82
|
"QuantumCompressTool",
|
|
69
83
|
"QuantumGradientTool",
|
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
"""
|
|
2
|
+
OpenAI Function Calling Integration for QuantumFlow.
|
|
3
|
+
|
|
4
|
+
Provides function definitions and execution handlers compatible with
|
|
5
|
+
OpenAI's function calling API (GPT-4, GPT-3.5-turbo).
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
from openai import OpenAI
|
|
9
|
+
from quantumflow.integrations.openai_functions import (
|
|
10
|
+
get_quantum_functions,
|
|
11
|
+
execute_quantum_function,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
client = OpenAI()
|
|
15
|
+
functions = get_quantum_functions()
|
|
16
|
+
|
|
17
|
+
response = client.chat.completions.create(
|
|
18
|
+
model="gpt-4",
|
|
19
|
+
messages=[{"role": "user", "content": "Compress these tokens: 100, 200, 150"}],
|
|
20
|
+
functions=functions,
|
|
21
|
+
function_call="auto",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# Execute the function call
|
|
25
|
+
if response.choices[0].message.function_call:
|
|
26
|
+
result = execute_quantum_function(
|
|
27
|
+
response.choices[0].message.function_call.name,
|
|
28
|
+
json.loads(response.choices[0].message.function_call.arguments)
|
|
29
|
+
)
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
import json
|
|
33
|
+
from typing import Any, Dict, List, Optional, Callable
|
|
34
|
+
from dataclasses import dataclass
|
|
35
|
+
|
|
36
|
+
from quantumflow.core.quantum_compressor import QuantumCompressor
|
|
37
|
+
from quantumflow.core.quantum_backprop import QuantumBackprop
|
|
38
|
+
from quantumflow.core.teleportation import QuantumTeleporter, QKDExchange, SecureMessenger
|
|
39
|
+
from quantumflow.core.entanglement import Entangler
|
|
40
|
+
from quantumflow.core.memory import QuantumMemory
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# OpenAI Function Definitions
|
|
44
|
+
QUANTUM_FUNCTIONS: List[Dict[str, Any]] = [
|
|
45
|
+
{
|
|
46
|
+
"name": "quantum_compress",
|
|
47
|
+
"description": "Compress a list of token values using quantum amplitude encoding. Achieves ~53% compression while preserving semantic information.",
|
|
48
|
+
"parameters": {
|
|
49
|
+
"type": "object",
|
|
50
|
+
"properties": {
|
|
51
|
+
"tokens": {
|
|
52
|
+
"type": "array",
|
|
53
|
+
"items": {"type": "number"},
|
|
54
|
+
"description": "List of token values (integers or floats) to compress",
|
|
55
|
+
},
|
|
56
|
+
"backend": {
|
|
57
|
+
"type": "string",
|
|
58
|
+
"enum": ["simulator", "ibm", "aws"],
|
|
59
|
+
"description": "Quantum backend to use. Default: simulator",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
"required": ["tokens"],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"name": "quantum_decompress",
|
|
67
|
+
"description": "Decompress previously quantum-compressed data back to original tokens.",
|
|
68
|
+
"parameters": {
|
|
69
|
+
"type": "object",
|
|
70
|
+
"properties": {
|
|
71
|
+
"compressed_state": {
|
|
72
|
+
"type": "array",
|
|
73
|
+
"items": {"type": "number"},
|
|
74
|
+
"description": "The compressed quantum state amplitudes",
|
|
75
|
+
},
|
|
76
|
+
"n_qubits": {
|
|
77
|
+
"type": "integer",
|
|
78
|
+
"description": "Number of qubits used in compression",
|
|
79
|
+
},
|
|
80
|
+
"original_length": {
|
|
81
|
+
"type": "integer",
|
|
82
|
+
"description": "Original number of tokens",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
"required": ["compressed_state", "n_qubits", "original_length"],
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"name": "quantum_gradient",
|
|
90
|
+
"description": "Compute gradients using quantum backpropagation via teleportation protocol. Achieves 97.78% gradient similarity with classical methods.",
|
|
91
|
+
"parameters": {
|
|
92
|
+
"type": "object",
|
|
93
|
+
"properties": {
|
|
94
|
+
"weights": {
|
|
95
|
+
"type": "array",
|
|
96
|
+
"items": {"type": "number"},
|
|
97
|
+
"description": "Neural network weights to compute gradients for",
|
|
98
|
+
},
|
|
99
|
+
"loss_value": {
|
|
100
|
+
"type": "number",
|
|
101
|
+
"description": "Current loss value",
|
|
102
|
+
},
|
|
103
|
+
"learning_rate": {
|
|
104
|
+
"type": "number",
|
|
105
|
+
"description": "Learning rate for gradient computation. Default: 0.01",
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
"required": ["weights", "loss_value"],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"name": "quantum_entangle",
|
|
113
|
+
"description": "Create quantum entanglement between data points for correlation analysis.",
|
|
114
|
+
"parameters": {
|
|
115
|
+
"type": "object",
|
|
116
|
+
"properties": {
|
|
117
|
+
"data_a": {
|
|
118
|
+
"type": "array",
|
|
119
|
+
"items": {"type": "number"},
|
|
120
|
+
"description": "First data array",
|
|
121
|
+
},
|
|
122
|
+
"data_b": {
|
|
123
|
+
"type": "array",
|
|
124
|
+
"items": {"type": "number"},
|
|
125
|
+
"description": "Second data array",
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
"required": ["data_a", "data_b"],
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"name": "quantum_teleport",
|
|
133
|
+
"description": "Teleport quantum state information using entangled Bell pairs.",
|
|
134
|
+
"parameters": {
|
|
135
|
+
"type": "object",
|
|
136
|
+
"properties": {
|
|
137
|
+
"state": {
|
|
138
|
+
"type": "array",
|
|
139
|
+
"items": {"type": "number"},
|
|
140
|
+
"description": "Quantum state amplitudes to teleport",
|
|
141
|
+
},
|
|
142
|
+
"n_pairs": {
|
|
143
|
+
"type": "integer",
|
|
144
|
+
"description": "Number of Bell pairs to use. Default: 10",
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
"required": ["state"],
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "qkd_exchange",
|
|
152
|
+
"description": "Perform BB84 quantum key distribution for unconditionally secure key exchange.",
|
|
153
|
+
"parameters": {
|
|
154
|
+
"type": "object",
|
|
155
|
+
"properties": {
|
|
156
|
+
"key_length": {
|
|
157
|
+
"type": "integer",
|
|
158
|
+
"description": "Desired key length in bits. Default: 256",
|
|
159
|
+
},
|
|
160
|
+
"error_threshold": {
|
|
161
|
+
"type": "number",
|
|
162
|
+
"description": "Maximum acceptable error rate. Default: 0.11",
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
"required": [],
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"name": "secure_message",
|
|
170
|
+
"description": "Send a message using quantum-secure encryption with QKD-generated keys.",
|
|
171
|
+
"parameters": {
|
|
172
|
+
"type": "object",
|
|
173
|
+
"properties": {
|
|
174
|
+
"message": {
|
|
175
|
+
"type": "string",
|
|
176
|
+
"description": "The message to encrypt and send",
|
|
177
|
+
},
|
|
178
|
+
"key_length": {
|
|
179
|
+
"type": "integer",
|
|
180
|
+
"description": "Key length for encryption. Default: 256",
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
"required": ["message"],
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"name": "quantum_memory_store",
|
|
188
|
+
"description": "Store data in quantum memory with O(log n) space complexity.",
|
|
189
|
+
"parameters": {
|
|
190
|
+
"type": "object",
|
|
191
|
+
"properties": {
|
|
192
|
+
"key": {
|
|
193
|
+
"type": "string",
|
|
194
|
+
"description": "Storage key identifier",
|
|
195
|
+
},
|
|
196
|
+
"data": {
|
|
197
|
+
"type": "array",
|
|
198
|
+
"items": {"type": "number"},
|
|
199
|
+
"description": "Data to store",
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
"required": ["key", "data"],
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"name": "quantum_memory_retrieve",
|
|
207
|
+
"description": "Retrieve data from quantum memory.",
|
|
208
|
+
"parameters": {
|
|
209
|
+
"type": "object",
|
|
210
|
+
"properties": {
|
|
211
|
+
"key": {
|
|
212
|
+
"type": "string",
|
|
213
|
+
"description": "Storage key identifier",
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
"required": ["key"],
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
]
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
# Singleton instances for stateful operations
|
|
223
|
+
_compressor: Optional[QuantumCompressor] = None
|
|
224
|
+
_backprop: Optional[QuantumBackprop] = None
|
|
225
|
+
_teleporter: Optional[QuantumTeleporter] = None
|
|
226
|
+
_qkd: Optional[QKDExchange] = None
|
|
227
|
+
_messenger: Optional[SecureMessenger] = None
|
|
228
|
+
_entangler: Optional[Entangler] = None
|
|
229
|
+
_memory: Optional[QuantumMemory] = None
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _get_compressor(backend: str = "simulator") -> QuantumCompressor:
|
|
233
|
+
global _compressor
|
|
234
|
+
if _compressor is None:
|
|
235
|
+
_compressor = QuantumCompressor(backend=backend)
|
|
236
|
+
return _compressor
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def _get_backprop() -> QuantumBackprop:
|
|
240
|
+
global _backprop
|
|
241
|
+
if _backprop is None:
|
|
242
|
+
_backprop = QuantumBackprop()
|
|
243
|
+
return _backprop
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def _get_teleporter() -> QuantumTeleporter:
|
|
247
|
+
global _teleporter
|
|
248
|
+
if _teleporter is None:
|
|
249
|
+
_teleporter = QuantumTeleporter()
|
|
250
|
+
return _teleporter
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _get_qkd() -> QKDExchange:
|
|
254
|
+
global _qkd
|
|
255
|
+
if _qkd is None:
|
|
256
|
+
_qkd = QKDExchange()
|
|
257
|
+
return _qkd
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def _get_messenger() -> SecureMessenger:
|
|
261
|
+
global _messenger
|
|
262
|
+
if _messenger is None:
|
|
263
|
+
_messenger = SecureMessenger()
|
|
264
|
+
return _messenger
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def _get_entangler() -> Entangler:
|
|
268
|
+
global _entangler
|
|
269
|
+
if _entangler is None:
|
|
270
|
+
_entangler = Entangler()
|
|
271
|
+
return _entangler
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _get_memory() -> QuantumMemory:
|
|
275
|
+
global _memory
|
|
276
|
+
if _memory is None:
|
|
277
|
+
_memory = QuantumMemory()
|
|
278
|
+
return _memory
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def get_quantum_functions() -> List[Dict[str, Any]]:
|
|
282
|
+
"""
|
|
283
|
+
Get the list of quantum function definitions for OpenAI's function calling API.
|
|
284
|
+
|
|
285
|
+
Returns:
|
|
286
|
+
List of function definitions compatible with OpenAI's API.
|
|
287
|
+
|
|
288
|
+
Example:
|
|
289
|
+
from openai import OpenAI
|
|
290
|
+
from quantumflow.integrations.openai_functions import get_quantum_functions
|
|
291
|
+
|
|
292
|
+
client = OpenAI()
|
|
293
|
+
response = client.chat.completions.create(
|
|
294
|
+
model="gpt-4",
|
|
295
|
+
messages=[...],
|
|
296
|
+
functions=get_quantum_functions(),
|
|
297
|
+
function_call="auto",
|
|
298
|
+
)
|
|
299
|
+
"""
|
|
300
|
+
return QUANTUM_FUNCTIONS.copy()
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def get_quantum_tools() -> List[Dict[str, Any]]:
|
|
304
|
+
"""
|
|
305
|
+
Get the list of quantum tools for OpenAI's tools API (newer format).
|
|
306
|
+
|
|
307
|
+
Returns:
|
|
308
|
+
List of tool definitions compatible with OpenAI's tools API.
|
|
309
|
+
|
|
310
|
+
Example:
|
|
311
|
+
from openai import OpenAI
|
|
312
|
+
from quantumflow.integrations.openai_functions import get_quantum_tools
|
|
313
|
+
|
|
314
|
+
client = OpenAI()
|
|
315
|
+
response = client.chat.completions.create(
|
|
316
|
+
model="gpt-4-turbo",
|
|
317
|
+
messages=[...],
|
|
318
|
+
tools=get_quantum_tools(),
|
|
319
|
+
tool_choice="auto",
|
|
320
|
+
)
|
|
321
|
+
"""
|
|
322
|
+
return [
|
|
323
|
+
{"type": "function", "function": func}
|
|
324
|
+
for func in QUANTUM_FUNCTIONS
|
|
325
|
+
]
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def execute_quantum_function(name: str, arguments: Dict[str, Any]) -> Dict[str, Any]:
|
|
329
|
+
"""
|
|
330
|
+
Execute a quantum function by name with the given arguments.
|
|
331
|
+
|
|
332
|
+
Args:
|
|
333
|
+
name: The function name to execute.
|
|
334
|
+
arguments: Dictionary of function arguments.
|
|
335
|
+
|
|
336
|
+
Returns:
|
|
337
|
+
Dictionary containing the function result.
|
|
338
|
+
|
|
339
|
+
Raises:
|
|
340
|
+
ValueError: If the function name is not recognized.
|
|
341
|
+
|
|
342
|
+
Example:
|
|
343
|
+
result = execute_quantum_function(
|
|
344
|
+
"quantum_compress",
|
|
345
|
+
{"tokens": [100, 200, 150, 175]}
|
|
346
|
+
)
|
|
347
|
+
"""
|
|
348
|
+
handlers: Dict[str, Callable] = {
|
|
349
|
+
"quantum_compress": _handle_compress,
|
|
350
|
+
"quantum_decompress": _handle_decompress,
|
|
351
|
+
"quantum_gradient": _handle_gradient,
|
|
352
|
+
"quantum_entangle": _handle_entangle,
|
|
353
|
+
"quantum_teleport": _handle_teleport,
|
|
354
|
+
"qkd_exchange": _handle_qkd,
|
|
355
|
+
"secure_message": _handle_secure_message,
|
|
356
|
+
"quantum_memory_store": _handle_memory_store,
|
|
357
|
+
"quantum_memory_retrieve": _handle_memory_retrieve,
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if name not in handlers:
|
|
361
|
+
raise ValueError(f"Unknown quantum function: {name}")
|
|
362
|
+
|
|
363
|
+
return handlers[name](arguments)
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def _handle_compress(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
367
|
+
tokens = args["tokens"]
|
|
368
|
+
backend = args.get("backend", "simulator")
|
|
369
|
+
compressor = _get_compressor(backend)
|
|
370
|
+
result = compressor.compress(tokens)
|
|
371
|
+
return {
|
|
372
|
+
"success": True,
|
|
373
|
+
"compressed_state": result.amplitudes.tolist() if hasattr(result.amplitudes, 'tolist') else list(result.amplitudes),
|
|
374
|
+
"n_qubits": result.n_qubits,
|
|
375
|
+
"original_length": len(tokens),
|
|
376
|
+
"compression_percentage": result.compression_percentage,
|
|
377
|
+
"fidelity": result.fidelity,
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def _handle_decompress(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
382
|
+
compressor = _get_compressor()
|
|
383
|
+
result = compressor.decompress(
|
|
384
|
+
compressed_state=args["compressed_state"],
|
|
385
|
+
n_qubits=args["n_qubits"],
|
|
386
|
+
original_length=args["original_length"],
|
|
387
|
+
)
|
|
388
|
+
return {
|
|
389
|
+
"success": True,
|
|
390
|
+
"tokens": result.tolist() if hasattr(result, 'tolist') else list(result),
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
def _handle_gradient(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
395
|
+
backprop = _get_backprop()
|
|
396
|
+
weights = args["weights"]
|
|
397
|
+
loss = args["loss_value"]
|
|
398
|
+
lr = args.get("learning_rate", 0.01)
|
|
399
|
+
result = backprop.compute_gradients(weights, loss, learning_rate=lr)
|
|
400
|
+
return {
|
|
401
|
+
"success": True,
|
|
402
|
+
"gradients": result.gradients.tolist() if hasattr(result.gradients, 'tolist') else list(result.gradients),
|
|
403
|
+
"similarity": result.similarity,
|
|
404
|
+
"teleportation_fidelity": result.fidelity,
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
def _handle_entangle(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
409
|
+
entangler = _get_entangler()
|
|
410
|
+
result = entangler.entangle(args["data_a"], args["data_b"])
|
|
411
|
+
return {
|
|
412
|
+
"success": True,
|
|
413
|
+
"correlation": result.correlation,
|
|
414
|
+
"bell_state": result.bell_state,
|
|
415
|
+
"fidelity": result.fidelity,
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def _handle_teleport(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
420
|
+
teleporter = _get_teleporter()
|
|
421
|
+
n_pairs = args.get("n_pairs", 10)
|
|
422
|
+
result = teleporter.teleport(args["state"], n_pairs=n_pairs)
|
|
423
|
+
return {
|
|
424
|
+
"success": True,
|
|
425
|
+
"teleported_state": result.state.tolist() if hasattr(result.state, 'tolist') else list(result.state),
|
|
426
|
+
"fidelity": result.fidelity,
|
|
427
|
+
"bell_pairs_used": n_pairs,
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
def _handle_qkd(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
432
|
+
qkd = _get_qkd()
|
|
433
|
+
key_length = args.get("key_length", 256)
|
|
434
|
+
error_threshold = args.get("error_threshold", 0.11)
|
|
435
|
+
result = qkd.exchange(key_length=key_length, error_threshold=error_threshold)
|
|
436
|
+
return {
|
|
437
|
+
"success": True,
|
|
438
|
+
"key": result.key,
|
|
439
|
+
"key_length": len(result.key),
|
|
440
|
+
"error_rate": result.error_rate,
|
|
441
|
+
"secure": result.secure,
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
def _handle_secure_message(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
446
|
+
messenger = _get_messenger()
|
|
447
|
+
message = args["message"]
|
|
448
|
+
key_length = args.get("key_length", 256)
|
|
449
|
+
result = messenger.send_message(message, key_length=key_length)
|
|
450
|
+
return {
|
|
451
|
+
"success": True,
|
|
452
|
+
"encrypted": result.encrypted,
|
|
453
|
+
"message_hash": result.message_hash,
|
|
454
|
+
"key_id": result.key_id,
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def _handle_memory_store(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
459
|
+
memory = _get_memory()
|
|
460
|
+
key = args["key"]
|
|
461
|
+
data = args["data"]
|
|
462
|
+
memory.store(key, data)
|
|
463
|
+
return {
|
|
464
|
+
"success": True,
|
|
465
|
+
"key": key,
|
|
466
|
+
"stored_length": len(data),
|
|
467
|
+
"quantum_bits_used": memory.get_usage(key),
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
def _handle_memory_retrieve(args: Dict[str, Any]) -> Dict[str, Any]:
|
|
472
|
+
memory = _get_memory()
|
|
473
|
+
key = args["key"]
|
|
474
|
+
data = memory.retrieve(key)
|
|
475
|
+
if data is None:
|
|
476
|
+
return {
|
|
477
|
+
"success": False,
|
|
478
|
+
"error": f"Key '{key}' not found in quantum memory",
|
|
479
|
+
}
|
|
480
|
+
return {
|
|
481
|
+
"success": True,
|
|
482
|
+
"key": key,
|
|
483
|
+
"data": data.tolist() if hasattr(data, 'tolist') else list(data),
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
@dataclass
|
|
488
|
+
class QuantumAssistant:
|
|
489
|
+
"""
|
|
490
|
+
A helper class for integrating QuantumFlow with OpenAI's chat completions.
|
|
491
|
+
|
|
492
|
+
Example:
|
|
493
|
+
from openai import OpenAI
|
|
494
|
+
from quantumflow.integrations.openai_functions import QuantumAssistant
|
|
495
|
+
|
|
496
|
+
client = OpenAI()
|
|
497
|
+
assistant = QuantumAssistant(client)
|
|
498
|
+
|
|
499
|
+
# Chat with quantum capabilities
|
|
500
|
+
response = assistant.chat("Compress these tokens: 100, 200, 150, 175")
|
|
501
|
+
print(response)
|
|
502
|
+
"""
|
|
503
|
+
|
|
504
|
+
client: Any # OpenAI client
|
|
505
|
+
model: str = "gpt-4"
|
|
506
|
+
messages: List[Dict[str, str]] = None
|
|
507
|
+
|
|
508
|
+
def __post_init__(self):
|
|
509
|
+
if self.messages is None:
|
|
510
|
+
self.messages = [
|
|
511
|
+
{
|
|
512
|
+
"role": "system",
|
|
513
|
+
"content": (
|
|
514
|
+
"You are a quantum computing assistant with access to QuantumFlow tools. "
|
|
515
|
+
"You can compress tokens, compute quantum gradients, perform quantum key distribution, "
|
|
516
|
+
"send secure messages, and manage quantum memory. Use these tools to help users "
|
|
517
|
+
"leverage quantum computing capabilities."
|
|
518
|
+
),
|
|
519
|
+
}
|
|
520
|
+
]
|
|
521
|
+
|
|
522
|
+
def chat(self, user_message: str) -> str:
|
|
523
|
+
"""
|
|
524
|
+
Send a message and get a response, automatically handling function calls.
|
|
525
|
+
|
|
526
|
+
Args:
|
|
527
|
+
user_message: The user's message.
|
|
528
|
+
|
|
529
|
+
Returns:
|
|
530
|
+
The assistant's response text.
|
|
531
|
+
"""
|
|
532
|
+
self.messages.append({"role": "user", "content": user_message})
|
|
533
|
+
|
|
534
|
+
response = self.client.chat.completions.create(
|
|
535
|
+
model=self.model,
|
|
536
|
+
messages=self.messages,
|
|
537
|
+
tools=get_quantum_tools(),
|
|
538
|
+
tool_choice="auto",
|
|
539
|
+
)
|
|
540
|
+
|
|
541
|
+
message = response.choices[0].message
|
|
542
|
+
|
|
543
|
+
# Handle tool calls
|
|
544
|
+
while message.tool_calls:
|
|
545
|
+
self.messages.append(message)
|
|
546
|
+
|
|
547
|
+
for tool_call in message.tool_calls:
|
|
548
|
+
function_name = tool_call.function.name
|
|
549
|
+
arguments = json.loads(tool_call.function.arguments)
|
|
550
|
+
|
|
551
|
+
try:
|
|
552
|
+
result = execute_quantum_function(function_name, arguments)
|
|
553
|
+
tool_response = json.dumps(result)
|
|
554
|
+
except Exception as e:
|
|
555
|
+
tool_response = json.dumps({"error": str(e)})
|
|
556
|
+
|
|
557
|
+
self.messages.append({
|
|
558
|
+
"role": "tool",
|
|
559
|
+
"tool_call_id": tool_call.id,
|
|
560
|
+
"content": tool_response,
|
|
561
|
+
})
|
|
562
|
+
|
|
563
|
+
# Get next response
|
|
564
|
+
response = self.client.chat.completions.create(
|
|
565
|
+
model=self.model,
|
|
566
|
+
messages=self.messages,
|
|
567
|
+
tools=get_quantum_tools(),
|
|
568
|
+
tool_choice="auto",
|
|
569
|
+
)
|
|
570
|
+
message = response.choices[0].message
|
|
571
|
+
|
|
572
|
+
# Final response
|
|
573
|
+
self.messages.append({"role": "assistant", "content": message.content})
|
|
574
|
+
return message.content
|
|
575
|
+
|
|
576
|
+
def reset(self):
|
|
577
|
+
"""Reset the conversation history."""
|
|
578
|
+
self.__post_init__()
|
|
@@ -57,6 +57,7 @@ src/quantumflow/integrations/crewai_tools.py
|
|
|
57
57
|
src/quantumflow/integrations/langchain_memory.py
|
|
58
58
|
src/quantumflow/integrations/langchain_tools.py
|
|
59
59
|
src/quantumflow/integrations/mcp_server.py
|
|
60
|
+
src/quantumflow/integrations/openai_functions.py
|
|
60
61
|
src/quantumflow_sdk.egg-info/PKG-INFO
|
|
61
62
|
src/quantumflow_sdk.egg-info/SOURCES.txt
|
|
62
63
|
src/quantumflow_sdk.egg-info/dependency_links.txt
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/compression/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/cryptography/__init__.py
RENAMED
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/cryptography/qkd.py
RENAMED
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/cryptography/qrng.py
RENAMED
|
File without changes
|
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/machine_learning/qnn.py
RENAMED
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/machine_learning/qsvm.py
RENAMED
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/machine_learning/vqe.py
RENAMED
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/optimization/__init__.py
RENAMED
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/optimization/grover.py
RENAMED
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/optimization/qaoa.py
RENAMED
|
File without changes
|
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/algorithms/utility/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/api/routes/billing_routes.py
RENAMED
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/api/routes/workflow_routes.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/backends/simulator_backend.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/integrations/autogen_tools.py
RENAMED
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/integrations/crewai_agents.py
RENAMED
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/integrations/crewai_tools.py
RENAMED
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/integrations/langchain_memory.py
RENAMED
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow/integrations/langchain_tools.py
RENAMED
|
File without changes
|
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow_sdk.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{quantumflow_sdk-0.2.0 → quantumflow_sdk-0.2.1}/src/quantumflow_sdk.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|