cwyodmodules 0.3.45__py3-none-any.whl → 0.3.47__py3-none-any.whl
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.
- cwyodmodules/batch/utilities/helpers/config/config_helper.py +353 -362
- cwyodmodules/batch/utilities/helpers/config/default.json +1 -2
- cwyodmodules/batch/utilities/helpers/env_helper.py +4 -5
- cwyodmodules/mgmt_config.py +181 -132
- {cwyodmodules-0.3.45.dist-info → cwyodmodules-0.3.47.dist-info}/METADATA +2 -2
- {cwyodmodules-0.3.45.dist-info → cwyodmodules-0.3.47.dist-info}/RECORD +9 -10
- cwyodmodules/batch/utilities/helpers/secret_helper.py +0 -79
- {cwyodmodules-0.3.45.dist-info → cwyodmodules-0.3.47.dist-info}/WHEEL +0 -0
- {cwyodmodules-0.3.45.dist-info → cwyodmodules-0.3.47.dist-info}/licenses/LICENSE +0 -0
- {cwyodmodules-0.3.45.dist-info → cwyodmodules-0.3.47.dist-info}/top_level.txt +0 -0
@@ -1,362 +1,353 @@
|
|
1
|
-
import os
|
2
|
-
import json
|
3
|
-
import functools
|
4
|
-
from string import Template
|
5
|
-
|
6
|
-
from ..azure_blob_storage_client import AzureBlobStorageClient
|
7
|
-
from ...document_chunking.chunking_strategy import ChunkingStrategy, ChunkingSettings
|
8
|
-
from ...document_loading import LoadingSettings, LoadingStrategy
|
9
|
-
from .embedding_config import EmbeddingConfig
|
10
|
-
from ...orchestrator.orchestration_strategy import OrchestrationStrategy
|
11
|
-
from ...orchestrator import OrchestrationSettings
|
12
|
-
from ..env_helper import EnvHelper
|
13
|
-
from .assistant_strategy import AssistantStrategy
|
14
|
-
from .conversation_flow import ConversationFlow
|
15
|
-
from .database_type import DatabaseType
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
self.
|
32
|
-
self.
|
33
|
-
self.
|
34
|
-
self.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
self.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
self.
|
59
|
-
self.
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
"
|
69
|
-
"
|
70
|
-
"
|
71
|
-
"
|
72
|
-
"
|
73
|
-
"
|
74
|
-
"
|
75
|
-
"
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
def
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
self.
|
117
|
-
self.
|
118
|
-
self.
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
self.
|
124
|
-
self.
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
self.
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
self.
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
if config["prompts"].get("
|
186
|
-
config["prompts"]["
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
)
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
if document_processor["document_type"] not in file_types
|
355
|
-
]
|
356
|
-
ConfigHelper._default_config["document_processors"] = document_processors
|
357
|
-
|
358
|
-
@staticmethod
|
359
|
-
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
|
360
|
-
def delete_config():
|
361
|
-
blob_client = AzureBlobStorageClient(container_name=CONFIG_CONTAINER_NAME)
|
362
|
-
blob_client.delete_file(CONFIG_FILE_NAME)
|
1
|
+
import os
|
2
|
+
import json
|
3
|
+
import functools
|
4
|
+
from string import Template
|
5
|
+
|
6
|
+
from ..azure_blob_storage_client import AzureBlobStorageClient
|
7
|
+
from ...document_chunking.chunking_strategy import ChunkingStrategy, ChunkingSettings
|
8
|
+
from ...document_loading import LoadingSettings, LoadingStrategy
|
9
|
+
from .embedding_config import EmbeddingConfig
|
10
|
+
from ...orchestrator.orchestration_strategy import OrchestrationStrategy
|
11
|
+
from ...orchestrator import OrchestrationSettings
|
12
|
+
from ..env_helper import EnvHelper
|
13
|
+
from .assistant_strategy import AssistantStrategy
|
14
|
+
from .conversation_flow import ConversationFlow
|
15
|
+
from .database_type import DatabaseType
|
16
|
+
|
17
|
+
CONFIG_CONTAINER_NAME = "config"
|
18
|
+
CONFIG_FILE_NAME = "active.json"
|
19
|
+
ADVANCED_IMAGE_PROCESSING_FILE_TYPES = ["jpeg", "jpg", "png", "tiff", "bmp"]
|
20
|
+
|
21
|
+
from mgmt_config import logger
|
22
|
+
env_helper: EnvHelper = EnvHelper()
|
23
|
+
log_execution = env_helper.LOG_EXECUTION
|
24
|
+
log_args = env_helper.LOG_ARGS
|
25
|
+
log_result = env_helper.LOG_RESULT
|
26
|
+
|
27
|
+
|
28
|
+
class Config:
|
29
|
+
def __init__(self, config: dict):
|
30
|
+
self.prompts = Prompts(config["prompts"])
|
31
|
+
self.messages = Messages(config["messages"])
|
32
|
+
self.example = Example(config["example"])
|
33
|
+
self.logging = Logging(config["logging"])
|
34
|
+
self.document_processors = [
|
35
|
+
EmbeddingConfig(
|
36
|
+
document_type=c["document_type"],
|
37
|
+
chunking=ChunkingSettings(c["chunking"]),
|
38
|
+
loading=LoadingSettings(c["loading"]),
|
39
|
+
use_advanced_image_processing=c.get(
|
40
|
+
"use_advanced_image_processing", False
|
41
|
+
),
|
42
|
+
)
|
43
|
+
for c in config["document_processors"]
|
44
|
+
]
|
45
|
+
self.env_helper = EnvHelper()
|
46
|
+
self.default_orchestration_settings = {
|
47
|
+
"strategy": self.env_helper.ORCHESTRATION_STRATEGY
|
48
|
+
}
|
49
|
+
self.orchestrator = OrchestrationSettings(
|
50
|
+
config.get("orchestrator", self.default_orchestration_settings)
|
51
|
+
)
|
52
|
+
self.integrated_vectorization_config = (
|
53
|
+
IntegratedVectorizationConfig(config["integrated_vectorization_config"])
|
54
|
+
if self.env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION
|
55
|
+
else None
|
56
|
+
)
|
57
|
+
self.enable_chat_history = config["enable_chat_history"]
|
58
|
+
self.database_type = config.get("database_type", self.env_helper.DATABASE_TYPE)
|
59
|
+
self.conversational_flow = config.get(
|
60
|
+
"conversational_flow", self.env_helper.CONVERSATION_FLOW
|
61
|
+
)
|
62
|
+
|
63
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
|
64
|
+
def get_available_document_types(self) -> list[str]:
|
65
|
+
document_types = {
|
66
|
+
"txt",
|
67
|
+
"pdf",
|
68
|
+
"url",
|
69
|
+
"html",
|
70
|
+
"htm",
|
71
|
+
"md",
|
72
|
+
"jpeg",
|
73
|
+
"jpg",
|
74
|
+
"png",
|
75
|
+
"docx",
|
76
|
+
}
|
77
|
+
if self.env_helper.USE_ADVANCED_IMAGE_PROCESSING:
|
78
|
+
document_types.update(ADVANCED_IMAGE_PROCESSING_FILE_TYPES)
|
79
|
+
|
80
|
+
return sorted(document_types)
|
81
|
+
|
82
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
|
83
|
+
def get_advanced_image_processing_image_types(self):
|
84
|
+
return ADVANCED_IMAGE_PROCESSING_FILE_TYPES
|
85
|
+
|
86
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
|
87
|
+
def get_available_chunking_strategies(self):
|
88
|
+
return [c.value for c in ChunkingStrategy]
|
89
|
+
|
90
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
|
91
|
+
def get_available_loading_strategies(self):
|
92
|
+
return [c.value for c in LoadingStrategy]
|
93
|
+
|
94
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
|
95
|
+
def get_available_orchestration_strategies(self):
|
96
|
+
return [c.value for c in OrchestrationStrategy]
|
97
|
+
|
98
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
|
99
|
+
def get_available_ai_assistant_types(self):
|
100
|
+
return [c.value for c in AssistantStrategy]
|
101
|
+
|
102
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
|
103
|
+
def get_available_conversational_flows(self):
|
104
|
+
return [c.value for c in ConversationFlow]
|
105
|
+
|
106
|
+
|
107
|
+
# TODO: Change to AnsweringChain or something, Prompts is not a good name
|
108
|
+
class Prompts:
|
109
|
+
def __init__(self, prompts: dict):
|
110
|
+
self.condense_question_prompt = prompts["condense_question_prompt"]
|
111
|
+
self.answering_system_prompt = prompts["answering_system_prompt"]
|
112
|
+
self.answering_user_prompt = prompts["answering_user_prompt"]
|
113
|
+
self.post_answering_prompt = prompts["post_answering_prompt"]
|
114
|
+
self.use_on_your_data_format = prompts["use_on_your_data_format"]
|
115
|
+
self.enable_post_answering_prompt = prompts["enable_post_answering_prompt"]
|
116
|
+
self.enable_content_safety = prompts["enable_content_safety"]
|
117
|
+
self.ai_assistant_type = prompts["ai_assistant_type"]
|
118
|
+
self.conversational_flow = prompts["conversational_flow"]
|
119
|
+
|
120
|
+
|
121
|
+
class Example:
|
122
|
+
def __init__(self, example: dict):
|
123
|
+
self.documents = example["documents"]
|
124
|
+
self.user_question = example["user_question"]
|
125
|
+
self.answer = example["answer"]
|
126
|
+
|
127
|
+
|
128
|
+
class Messages:
|
129
|
+
def __init__(self, messages: dict):
|
130
|
+
self.post_answering_filter = messages["post_answering_filter"]
|
131
|
+
|
132
|
+
|
133
|
+
class Logging:
|
134
|
+
def __init__(self, logging: dict):
|
135
|
+
self.log_user_interactions = (
|
136
|
+
str(logging["log_user_interactions"]).lower() == "true"
|
137
|
+
)
|
138
|
+
self.log_tokens = str(logging["log_tokens"]).lower() == "true"
|
139
|
+
|
140
|
+
|
141
|
+
class IntegratedVectorizationConfig:
|
142
|
+
def __init__(self, integrated_vectorization_config: dict):
|
143
|
+
self.max_page_length = integrated_vectorization_config["max_page_length"]
|
144
|
+
self.page_overlap_length = integrated_vectorization_config[
|
145
|
+
"page_overlap_length"
|
146
|
+
]
|
147
|
+
|
148
|
+
|
149
|
+
class ConfigHelper:
|
150
|
+
_default_config = None
|
151
|
+
|
152
|
+
@staticmethod
|
153
|
+
@logger.trace_function(log_execution=log_execution, log_args=False, log_result=False)
|
154
|
+
def _set_new_config_properties(config: dict, default_config: dict):
|
155
|
+
"""
|
156
|
+
Function used to set newer properties that will not be present in older configs.
|
157
|
+
The function mutates the config object.
|
158
|
+
"""
|
159
|
+
if config["prompts"].get("answering_system_prompt") is None:
|
160
|
+
config["prompts"]["answering_system_prompt"] = default_config["prompts"][
|
161
|
+
"answering_system_prompt"
|
162
|
+
]
|
163
|
+
|
164
|
+
prompt_modified = (
|
165
|
+
config["prompts"].get("answering_prompt")
|
166
|
+
!= default_config["prompts"]["answering_prompt"]
|
167
|
+
)
|
168
|
+
|
169
|
+
if config["prompts"].get("answering_user_prompt") is None:
|
170
|
+
if prompt_modified:
|
171
|
+
config["prompts"]["answering_user_prompt"] = config["prompts"].get(
|
172
|
+
"answering_prompt"
|
173
|
+
)
|
174
|
+
else:
|
175
|
+
config["prompts"]["answering_user_prompt"] = default_config["prompts"][
|
176
|
+
"answering_user_prompt"
|
177
|
+
]
|
178
|
+
|
179
|
+
if config["prompts"].get("use_on_your_data_format") is None:
|
180
|
+
config["prompts"]["use_on_your_data_format"] = not prompt_modified
|
181
|
+
|
182
|
+
if config.get("example") is None:
|
183
|
+
config["example"] = default_config["example"]
|
184
|
+
|
185
|
+
if config["prompts"].get("ai_assistant_type") is None:
|
186
|
+
config["prompts"]["ai_assistant_type"] = default_config["prompts"][
|
187
|
+
"ai_assistant_type"
|
188
|
+
]
|
189
|
+
|
190
|
+
if config.get("integrated_vectorization_config") is None:
|
191
|
+
config["integrated_vectorization_config"] = default_config[
|
192
|
+
"integrated_vectorization_config"
|
193
|
+
]
|
194
|
+
|
195
|
+
if config["prompts"].get("conversational_flow") is None:
|
196
|
+
config["prompts"]["conversational_flow"] = default_config["prompts"][
|
197
|
+
"conversational_flow"
|
198
|
+
]
|
199
|
+
if config.get("enable_chat_history") is None:
|
200
|
+
config["enable_chat_history"] = default_config["enable_chat_history"]
|
201
|
+
|
202
|
+
@staticmethod
|
203
|
+
@functools.cache
|
204
|
+
@logger.trace_function(log_execution=log_execution, log_args=False, log_result=False)
|
205
|
+
def get_active_config_or_default():
|
206
|
+
logger.info("Method get_active_config_or_default started")
|
207
|
+
env_helper = EnvHelper()
|
208
|
+
config = ConfigHelper.get_default_config()
|
209
|
+
if env_helper.LOAD_CONFIG_FROM_BLOB_STORAGE:
|
210
|
+
logger.info("Loading configuration from Blob Storage")
|
211
|
+
blob_client = AzureBlobStorageClient(container_name=CONFIG_CONTAINER_NAME)
|
212
|
+
|
213
|
+
if blob_client.file_exists(CONFIG_FILE_NAME):
|
214
|
+
logger.info("Configuration file found in Blob Storage")
|
215
|
+
default_config = config
|
216
|
+
config_file = blob_client.download_file(CONFIG_FILE_NAME)
|
217
|
+
config = json.loads(config_file)
|
218
|
+
|
219
|
+
ConfigHelper._set_new_config_properties(config, default_config)
|
220
|
+
else:
|
221
|
+
logger.info(
|
222
|
+
"Configuration file not found in Blob Storage, using default configuration"
|
223
|
+
)
|
224
|
+
|
225
|
+
logger.info("Method get_active_config_or_default ended")
|
226
|
+
return Config(config)
|
227
|
+
|
228
|
+
@staticmethod
|
229
|
+
@functools.cache
|
230
|
+
@logger.trace_function(log_execution=log_execution, log_args=False, log_result=False)
|
231
|
+
def get_default_assistant_prompt():
|
232
|
+
config = ConfigHelper.get_default_config()
|
233
|
+
return config["prompts"]["answering_user_prompt"]
|
234
|
+
|
235
|
+
@staticmethod
|
236
|
+
@logger.trace_function(log_execution=log_execution, log_args=False, log_result=log_result)
|
237
|
+
def save_config_as_active(config):
|
238
|
+
ConfigHelper.validate_config(config)
|
239
|
+
blob_client = AzureBlobStorageClient(container_name=CONFIG_CONTAINER_NAME)
|
240
|
+
blob_client = blob_client.upload_file(
|
241
|
+
json.dumps(config, indent=2),
|
242
|
+
CONFIG_FILE_NAME,
|
243
|
+
content_type="application/json",
|
244
|
+
)
|
245
|
+
ConfigHelper.get_active_config_or_default.cache_clear()
|
246
|
+
|
247
|
+
@staticmethod
|
248
|
+
@logger.trace_function(log_execution=log_execution, log_args=False, log_result=log_result)
|
249
|
+
def validate_config(config: dict):
|
250
|
+
for document_processor in config.get("document_processors"):
|
251
|
+
document_type = document_processor.get("document_type")
|
252
|
+
unsupported_advanced_image_processing_file_type = (
|
253
|
+
document_type not in ADVANCED_IMAGE_PROCESSING_FILE_TYPES
|
254
|
+
)
|
255
|
+
if (
|
256
|
+
document_processor.get("use_advanced_image_processing")
|
257
|
+
and unsupported_advanced_image_processing_file_type
|
258
|
+
):
|
259
|
+
raise Exception(
|
260
|
+
f"Advanced image processing has not been enabled for document type {document_type}, as only {ADVANCED_IMAGE_PROCESSING_FILE_TYPES} file types are supported."
|
261
|
+
)
|
262
|
+
|
263
|
+
@staticmethod
|
264
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=False)
|
265
|
+
def get_default_config():
|
266
|
+
if ConfigHelper._default_config is None:
|
267
|
+
env_helper = EnvHelper()
|
268
|
+
|
269
|
+
config_file_path = os.path.join(os.path.dirname(__file__), "default.json")
|
270
|
+
logger.info("Loading default config from %s", config_file_path)
|
271
|
+
with open(config_file_path, encoding="utf-8") as f:
|
272
|
+
ConfigHelper._default_config = json.loads(
|
273
|
+
Template(f.read()).substitute(
|
274
|
+
ORCHESTRATION_STRATEGY=env_helper.ORCHESTRATION_STRATEGY,
|
275
|
+
LOG_USER_INTERACTIONS=(
|
276
|
+
False
|
277
|
+
if env_helper.DATABASE_TYPE == DatabaseType.POSTGRESQL.value
|
278
|
+
else True
|
279
|
+
),
|
280
|
+
LOG_TOKENS=(
|
281
|
+
False
|
282
|
+
if env_helper.DATABASE_TYPE == DatabaseType.POSTGRESQL.value
|
283
|
+
else True
|
284
|
+
),
|
285
|
+
CONVERSATION_FLOW=env_helper.CONVERSATION_FLOW,
|
286
|
+
DATABASE_TYPE=env_helper.DATABASE_TYPE,
|
287
|
+
)
|
288
|
+
)
|
289
|
+
if env_helper.USE_ADVANCED_IMAGE_PROCESSING:
|
290
|
+
ConfigHelper._append_advanced_image_processors()
|
291
|
+
|
292
|
+
return ConfigHelper._default_config
|
293
|
+
|
294
|
+
@staticmethod
|
295
|
+
@functools.cache
|
296
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=False)
|
297
|
+
def get_default_contract_assistant():
|
298
|
+
contract_file_path = os.path.join(
|
299
|
+
os.path.dirname(__file__), "default_contract_assistant_prompt.txt"
|
300
|
+
)
|
301
|
+
contract_assistant = ""
|
302
|
+
with open(contract_file_path, encoding="utf-8") as f:
|
303
|
+
contract_assistant = f.readlines()
|
304
|
+
|
305
|
+
return "".join([str(elem) for elem in contract_assistant])
|
306
|
+
|
307
|
+
@staticmethod
|
308
|
+
@functools.cache
|
309
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=False)
|
310
|
+
def get_default_employee_assistant():
|
311
|
+
employee_file_path = os.path.join(
|
312
|
+
os.path.dirname(__file__), "default_employee_assistant_prompt.txt"
|
313
|
+
)
|
314
|
+
employee_assistant = ""
|
315
|
+
with open(employee_file_path, encoding="utf-8") as f:
|
316
|
+
employee_assistant = f.readlines()
|
317
|
+
|
318
|
+
return "".join([str(elem) for elem in employee_assistant])
|
319
|
+
|
320
|
+
@staticmethod
|
321
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
|
322
|
+
def clear_config():
|
323
|
+
ConfigHelper._default_config = None
|
324
|
+
ConfigHelper.get_active_config_or_default.cache_clear()
|
325
|
+
|
326
|
+
@staticmethod
|
327
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
|
328
|
+
def _append_advanced_image_processors():
|
329
|
+
image_file_types = ["jpeg", "jpg", "png", "tiff", "bmp"]
|
330
|
+
ConfigHelper._remove_processors_for_file_types(image_file_types)
|
331
|
+
ConfigHelper._default_config["document_processors"].extend(
|
332
|
+
[
|
333
|
+
{"document_type": file_type, "use_advanced_image_processing": True}
|
334
|
+
for file_type in image_file_types
|
335
|
+
]
|
336
|
+
)
|
337
|
+
|
338
|
+
@staticmethod
|
339
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
|
340
|
+
def _remove_processors_for_file_types(file_types: list[str]):
|
341
|
+
document_processors = ConfigHelper._default_config["document_processors"]
|
342
|
+
document_processors = [
|
343
|
+
document_processor
|
344
|
+
for document_processor in document_processors
|
345
|
+
if document_processor["document_type"] not in file_types
|
346
|
+
]
|
347
|
+
ConfigHelper._default_config["document_processors"] = document_processors
|
348
|
+
|
349
|
+
@staticmethod
|
350
|
+
@logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
|
351
|
+
def delete_config():
|
352
|
+
blob_client = AzureBlobStorageClient(container_name=CONFIG_CONTAINER_NAME)
|
353
|
+
blob_client.delete_file(CONFIG_FILE_NAME)
|
@@ -6,9 +6,8 @@ import threading
|
|
6
6
|
from ..orchestrator.orchestration_strategy import OrchestrationStrategy
|
7
7
|
from ..helpers.config.conversation_flow import ConversationFlow
|
8
8
|
from ..helpers.config.database_type import DatabaseType
|
9
|
-
from ..helpers.secret_helper import SecretHelper
|
10
9
|
|
11
|
-
from mgmt_config import logger, identity
|
10
|
+
from mgmt_config import logger, identity, keyvault, create_keyvault_client
|
12
11
|
|
13
12
|
|
14
13
|
|
@@ -33,10 +32,10 @@ class EnvHelper:
|
|
33
32
|
# Wrapper for Azure Key Vault
|
34
33
|
os.environ["APPLICATIONINSIGHTS_ENABLED"] = "true"
|
35
34
|
|
36
|
-
self.secretHelper =
|
35
|
+
self.secretHelper = keyvault
|
37
36
|
|
38
|
-
self.secretHelperHead =
|
39
|
-
|
37
|
+
self.secretHelperHead = create_keyvault_client(
|
38
|
+
vault_url=os.environ["head_key_vault_uri"]
|
40
39
|
)
|
41
40
|
|
42
41
|
# self.secretHelper = SecretHelper(
|
cwyodmodules/mgmt_config.py
CHANGED
@@ -1,132 +1,181 @@
|
|
1
|
-
"""
|
2
|
-
Azure Project Management Configuration Template
|
3
|
-
|
4
|
-
This template provides standardized configuration for Azure logging
|
5
|
-
management across projects. It creates singleton instances of
|
6
|
-
AzureIdentity that can be imported and used
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
from
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
"
|
44
|
-
"
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"
|
48
|
-
}
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
#
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
#
|
62
|
-
|
63
|
-
|
64
|
-
#
|
65
|
-
|
66
|
-
|
67
|
-
#
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
1
|
+
"""
|
2
|
+
Azure Project Management Configuration Template
|
3
|
+
|
4
|
+
This template provides standardized configuration for Azure logging, identity,
|
5
|
+
and KeyVault management across projects. It creates singleton instances of
|
6
|
+
AzureLogger, AzureIdentity, and AzureKeyVault that can be imported and used
|
7
|
+
throughout your application.
|
8
|
+
|
9
|
+
Usage:
|
10
|
+
from mgmt_config import logger, identity, keyvault
|
11
|
+
|
12
|
+
logger.info("Application started")
|
13
|
+
credential = identity.get_credential()
|
14
|
+
secret = keyvault.get_secret("my-secret") if keyvault else None
|
15
|
+
"""
|
16
|
+
|
17
|
+
import os
|
18
|
+
from typing import Optional, Dict, Any
|
19
|
+
from azpaddypy.mgmt.logging import create_app_logger
|
20
|
+
from azpaddypy.mgmt.identity import create_azure_identity
|
21
|
+
from azpaddypy.resources.keyvault import create_azure_keyvault, AzureKeyVault
|
22
|
+
|
23
|
+
# =============================================================================
|
24
|
+
# SERVICE CONFIGURATION
|
25
|
+
# =============================================================================
|
26
|
+
|
27
|
+
# Service identity - customize these for your project
|
28
|
+
SERVICE_NAME = os.getenv("SERVICE_NAME", "cwyodmodules-pacakge")
|
29
|
+
SERVICE_VERSION = os.getenv("SERVICE_VERSION", "1.0.0")
|
30
|
+
|
31
|
+
# =============================================================================
|
32
|
+
# LOGGING CONFIGURATION
|
33
|
+
# =============================================================================
|
34
|
+
|
35
|
+
# Enable console output (useful for local development)
|
36
|
+
LOGGER_ENABLE_CONSOLE = os.getenv("LOGGER_ENABLE_CONSOLE", "true").lower() == "true"
|
37
|
+
|
38
|
+
# Application Insights connection string (optional, will use environment variable if not set)
|
39
|
+
LOGGER_CONNECTION_STRING = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
|
40
|
+
|
41
|
+
# Configure which Azure SDK components to instrument
|
42
|
+
LOGGER_INSTRUMENTATION_OPTIONS = {
|
43
|
+
"azure_sdk": {"enabled": True},
|
44
|
+
"django": {"enabled": False},
|
45
|
+
"fastapi": {"enabled": False},
|
46
|
+
"flask": {"enabled": True},
|
47
|
+
"psycopg2": {"enabled": True},
|
48
|
+
"requests": {"enabled": True},
|
49
|
+
"urllib": {"enabled": True},
|
50
|
+
"urllib3": {"enabled": True},
|
51
|
+
}
|
52
|
+
|
53
|
+
# =============================================================================
|
54
|
+
# IDENTITY CONFIGURATION
|
55
|
+
# =============================================================================
|
56
|
+
|
57
|
+
# Token caching settings
|
58
|
+
IDENTITY_ENABLE_TOKEN_CACHE = os.getenv("IDENTITY_ENABLE_TOKEN_CACHE", "true").lower() == "true"
|
59
|
+
IDENTITY_ALLOW_UNENCRYPTED_STORAGE = os.getenv("IDENTITY_ALLOW_UNENCRYPTED_STORAGE", "true").lower() == "true"
|
60
|
+
|
61
|
+
# Custom credential options (None means use defaults)
|
62
|
+
IDENTITY_CUSTOM_CREDENTIAL_OPTIONS: Optional[Dict[str, Any]] = None
|
63
|
+
|
64
|
+
# Connection string for identity logging (uses same as logger by default)
|
65
|
+
IDENTITY_CONNECTION_STRING = LOGGER_CONNECTION_STRING
|
66
|
+
|
67
|
+
# =============================================================================
|
68
|
+
# KEYVAULT CONFIGURATION
|
69
|
+
# =============================================================================
|
70
|
+
|
71
|
+
# KeyVault URL (optional, will be None if not configured)
|
72
|
+
KEYVAULT_URL = os.getenv("key_vault_uri")
|
73
|
+
|
74
|
+
# KeyVault client enablement settings
|
75
|
+
KEYVAULT_ENABLE_SECRETS = os.getenv("KEYVAULT_ENABLE_SECRETS", "true").lower() == "true"
|
76
|
+
KEYVAULT_ENABLE_KEYS = os.getenv("KEYVAULT_ENABLE_KEYS", "false").lower() == "true"
|
77
|
+
KEYVAULT_ENABLE_CERTIFICATES = os.getenv("KEYVAULT_ENABLE_CERTIFICATES", "false").lower() == "true"
|
78
|
+
|
79
|
+
# Connection string for KeyVault logging (uses same as logger by default)
|
80
|
+
KEYVAULT_CONNECTION_STRING = LOGGER_CONNECTION_STRING
|
81
|
+
|
82
|
+
# =============================================================================
|
83
|
+
# INITIALIZE SERVICES
|
84
|
+
# =============================================================================
|
85
|
+
|
86
|
+
# Create logger instance
|
87
|
+
logger = create_app_logger(
|
88
|
+
service_name=SERVICE_NAME,
|
89
|
+
service_version=SERVICE_VERSION,
|
90
|
+
connection_string=LOGGER_CONNECTION_STRING,
|
91
|
+
enable_console_logging=LOGGER_ENABLE_CONSOLE,
|
92
|
+
instrumentation_options=LOGGER_INSTRUMENTATION_OPTIONS,
|
93
|
+
)
|
94
|
+
|
95
|
+
# Create identity instance with shared logger
|
96
|
+
identity = create_azure_identity(
|
97
|
+
service_name=SERVICE_NAME,
|
98
|
+
service_version=SERVICE_VERSION,
|
99
|
+
enable_token_cache=IDENTITY_ENABLE_TOKEN_CACHE,
|
100
|
+
allow_unencrypted_storage=IDENTITY_ALLOW_UNENCRYPTED_STORAGE,
|
101
|
+
custom_credential_options=IDENTITY_CUSTOM_CREDENTIAL_OPTIONS,
|
102
|
+
connection_string=IDENTITY_CONNECTION_STRING,
|
103
|
+
logger=logger,
|
104
|
+
)
|
105
|
+
|
106
|
+
# Create KeyVault instance with shared logger and identity (only if URL is configured)
|
107
|
+
keyvault = None
|
108
|
+
if KEYVAULT_URL:
|
109
|
+
keyvault = create_azure_keyvault(
|
110
|
+
vault_url=KEYVAULT_URL,
|
111
|
+
azure_identity=identity,
|
112
|
+
service_name=SERVICE_NAME,
|
113
|
+
service_version=SERVICE_VERSION,
|
114
|
+
logger=logger,
|
115
|
+
connection_string=KEYVAULT_CONNECTION_STRING,
|
116
|
+
enable_secrets=KEYVAULT_ENABLE_SECRETS,
|
117
|
+
enable_keys=KEYVAULT_ENABLE_KEYS,
|
118
|
+
enable_certificates=KEYVAULT_ENABLE_CERTIFICATES,
|
119
|
+
)
|
120
|
+
|
121
|
+
def create_keyvault_client(vault_url: str) -> Optional[AzureKeyVault]:
|
122
|
+
"""Creates a secondary KeyVault client for a different vault."""
|
123
|
+
if not vault_url:
|
124
|
+
return None
|
125
|
+
return create_azure_keyvault(
|
126
|
+
vault_url=vault_url,
|
127
|
+
azure_identity=identity,
|
128
|
+
service_name=SERVICE_NAME,
|
129
|
+
service_version=SERVICE_VERSION,
|
130
|
+
logger=logger,
|
131
|
+
connection_string=KEYVAULT_CONNECTION_STRING,
|
132
|
+
enable_secrets=KEYVAULT_ENABLE_SECRETS,
|
133
|
+
enable_keys=KEYVAULT_ENABLE_KEYS,
|
134
|
+
enable_certificates=KEYVAULT_ENABLE_CERTIFICATES,
|
135
|
+
)
|
136
|
+
|
137
|
+
# =============================================================================
|
138
|
+
# VALIDATION & STARTUP
|
139
|
+
# =============================================================================
|
140
|
+
|
141
|
+
# Validate critical configuration
|
142
|
+
if SERVICE_NAME == "your-service-name":
|
143
|
+
logger.warning(
|
144
|
+
"SERVICE_NAME is not configured. Please set SERVICE_NAME environment variable or update this template.",
|
145
|
+
extra={"configuration_issue": "service_name_not_set"}
|
146
|
+
)
|
147
|
+
|
148
|
+
if not LOGGER_CONNECTION_STRING:
|
149
|
+
logger.info(
|
150
|
+
"No Application Insights connection string configured. Telemetry will be disabled.",
|
151
|
+
extra={"telemetry_status": "disabled"}
|
152
|
+
)
|
153
|
+
|
154
|
+
if not KEYVAULT_URL:
|
155
|
+
logger.info(
|
156
|
+
"No KeyVault URL configured. KeyVault operations will be disabled.",
|
157
|
+
extra={"keyvault_status": "disabled"}
|
158
|
+
)
|
159
|
+
|
160
|
+
# Log successful initialization
|
161
|
+
logger.info(
|
162
|
+
f"Management configuration initialized for service '{SERVICE_NAME}' v{SERVICE_VERSION}",
|
163
|
+
extra={
|
164
|
+
"service_name": SERVICE_NAME,
|
165
|
+
"service_version": SERVICE_VERSION,
|
166
|
+
"console_logging": LOGGER_ENABLE_CONSOLE,
|
167
|
+
"token_cache_enabled": IDENTITY_ENABLE_TOKEN_CACHE,
|
168
|
+
"telemetry_enabled": bool(LOGGER_CONNECTION_STRING),
|
169
|
+
"keyvault_enabled": bool(KEYVAULT_URL),
|
170
|
+
"keyvault_secrets_enabled": KEYVAULT_ENABLE_SECRETS,
|
171
|
+
"keyvault_keys_enabled": KEYVAULT_ENABLE_KEYS,
|
172
|
+
"keyvault_certificates_enabled": KEYVAULT_ENABLE_CERTIFICATES,
|
173
|
+
}
|
174
|
+
)
|
175
|
+
|
176
|
+
# =============================================================================
|
177
|
+
# EXPORTS
|
178
|
+
# =============================================================================
|
179
|
+
|
180
|
+
# Export logger, identity, and keyvault for use in applications
|
181
|
+
__all__ = ["logger", "identity", "keyvault", "create_keyvault_client"]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: cwyodmodules
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.47
|
4
4
|
Summary: Add your description here
|
5
5
|
Author-email: Patrik <patrikhartl@gmail.com>
|
6
6
|
Classifier: Operating System :: OS Independent
|
@@ -40,7 +40,7 @@ Requires-Dist: azure-search-documents==11.6.0b4
|
|
40
40
|
Requires-Dist: semantic-kernel==1.3.0
|
41
41
|
Requires-Dist: pydantic==2.7.4
|
42
42
|
Requires-Dist: pandas>=2.2.3
|
43
|
-
Requires-Dist: azpaddypy>=0.3.
|
43
|
+
Requires-Dist: azpaddypy>=0.3.5
|
44
44
|
Dynamic: license-file
|
45
45
|
|
46
46
|
# paddypy
|
@@ -1,5 +1,5 @@
|
|
1
1
|
cwyodmodules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
cwyodmodules/mgmt_config.py,sha256=
|
2
|
+
cwyodmodules/mgmt_config.py,sha256=YFVPC_Q3enDDf3tw9mQ4dWeGfvtCnxsEkIFu0616C4w,7163
|
3
3
|
cwyodmodules/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
cwyodmodules/api/chat_history.py,sha256=bVXFmhTHIfEiHv_nBrfizO-cQRHhKgrdcZ07OD1b0Tw,20683
|
5
5
|
cwyodmodules/batch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -37,17 +37,16 @@ cwyodmodules/batch/utilities/helpers/azure_postgres_helper_light_rag.py,sha256=M
|
|
37
37
|
cwyodmodules/batch/utilities/helpers/azure_search_helper.py,sha256=vIIMEck1wPg9oRlWweE2gSZ1nUYc_tmEe4QeFlsrwKk,11314
|
38
38
|
cwyodmodules/batch/utilities/helpers/document_chunking_helper.py,sha256=2MZOjW-fHXgYijP3m9O-nizOlk96Yg0axyxT0K6fTnM,725
|
39
39
|
cwyodmodules/batch/utilities/helpers/document_loading_helper.py,sha256=2HBEl3vW-_PKbX5pPntTC_R5eToTk2Qb-q3M4Mt6hCU,603
|
40
|
-
cwyodmodules/batch/utilities/helpers/env_helper.py,sha256=
|
40
|
+
cwyodmodules/batch/utilities/helpers/env_helper.py,sha256=avZCU8eZOjrhGLu8LcjQr_kjoLzkL_75UemCGQTINxY,15827
|
41
41
|
cwyodmodules/batch/utilities/helpers/lightrag_helper.py,sha256=7lb9JMm5IohsO73LWo5bWmlzWCGYNsx_fYl-aFdwATQ,3845
|
42
42
|
cwyodmodules/batch/utilities/helpers/llm_helper.py,sha256=lHLYrUidtaemmKrVbWoo7oIvwluUoPUk16U5lV-YIX8,8282
|
43
43
|
cwyodmodules/batch/utilities/helpers/orchestrator_helper.py,sha256=mCcZyMFG0otnw9gzWd-PYocHmDdFDVg-RT9oDPiDZPk,897
|
44
|
-
cwyodmodules/batch/utilities/helpers/secret_helper.py,sha256=KacIc2hHpWtgButUnR3sFC9StLS36HjYvNpTmf2f4gc,2834
|
45
44
|
cwyodmodules/batch/utilities/helpers/config/agent_mode.py,sha256=8XMbu8dwMXva_xxeZNDlwOjDaZwIcwc-xJK1-QsaJ3w,82
|
46
45
|
cwyodmodules/batch/utilities/helpers/config/assistant_strategy.py,sha256=uT8h646zEURU9x8oDOH7pWoZKb0Mw6dA2nJtA2M-ufg,171
|
47
|
-
cwyodmodules/batch/utilities/helpers/config/config_helper.py,sha256=
|
46
|
+
cwyodmodules/batch/utilities/helpers/config/config_helper.py,sha256=26na6YrLqRLhdSZxTSlOnJOkIcPbTcbFVuPEQTPT3WY,14908
|
48
47
|
cwyodmodules/batch/utilities/helpers/config/conversation_flow.py,sha256=4nP8a-I-sME5-2unzWWBNpTzWdfpfc5_EAYU6Pn6LAQ,94
|
49
48
|
cwyodmodules/batch/utilities/helpers/config/database_type.py,sha256=Zmmlh1NAKDdd-2ei478boncRKcx8v3lDkPf4kO2j4ss,132
|
50
|
-
cwyodmodules/batch/utilities/helpers/config/default.json,sha256=
|
49
|
+
cwyodmodules/batch/utilities/helpers/config/default.json,sha256=865avujlLpO2to1dlh7yXfs0F57noJNrld2zwVYirwM,15406
|
51
50
|
cwyodmodules/batch/utilities/helpers/config/default_contract_assistant_prompt.txt,sha256=X39WGcxzQPIvqG7NpAMPsgmSwSyMEoK1DVWiuEHEHRg,3210
|
52
51
|
cwyodmodules/batch/utilities/helpers/config/default_employee_assistant_prompt.txt,sha256=toQFo0wXYrEK7zAItAS9rbtyhT6DJZKBhiL6C9VPUQk,3942
|
53
52
|
cwyodmodules/batch/utilities/helpers/config/embedding_config.py,sha256=9pCJxpsouln9dngjVHaKGFYP14PrwmSts_UFDytSiVk,950
|
@@ -110,8 +109,8 @@ cwyodmodules/graphrag/query/generate.py,sha256=BZiB6iw7PkIovw-CyYFogMHnDxK0Qu_4u
|
|
110
109
|
cwyodmodules/graphrag/query/graph_search.py,sha256=95h3ecSWx4864XgKABtG0fh3Nk8HkqJVzoCrO8daJ-Y,7724
|
111
110
|
cwyodmodules/graphrag/query/types.py,sha256=1Iq1dp4I4a56_cuFjOZ0NTgd0A2_MpVFznp_czgt6cI,617
|
112
111
|
cwyodmodules/graphrag/query/vector_search.py,sha256=9Gwu9LPjtoAYUU8WKqCvbCHAIg3dpk71reoYd1scLnQ,1807
|
113
|
-
cwyodmodules-0.3.
|
114
|
-
cwyodmodules-0.3.
|
115
|
-
cwyodmodules-0.3.
|
116
|
-
cwyodmodules-0.3.
|
117
|
-
cwyodmodules-0.3.
|
112
|
+
cwyodmodules-0.3.47.dist-info/licenses/LICENSE,sha256=UqBDTipijsSW2ZSOXyTZnMsXmLoEHTgNEM0tL4g-Sso,1150
|
113
|
+
cwyodmodules-0.3.47.dist-info/METADATA,sha256=YSDKlXiAglRuJPkC06tOr1GIB9zXKgRfGgMTKl-cFWE,2002
|
114
|
+
cwyodmodules-0.3.47.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
115
|
+
cwyodmodules-0.3.47.dist-info/top_level.txt,sha256=99RENLbkdRX-qpJvsxZ5AfmTL5s6shSaKOWYpz1vwzg,13
|
116
|
+
cwyodmodules-0.3.47.dist-info/RECORD,,
|
@@ -1,79 +0,0 @@
|
|
1
|
-
from azure.keyvault.secrets import SecretClient
|
2
|
-
from mgmt_config import logger, identity
|
3
|
-
|
4
|
-
|
5
|
-
class SecretHelper:
|
6
|
-
def __init__(self, keyvault_uri) -> None:
|
7
|
-
"""
|
8
|
-
Initializes an instance of the SecretHelper class.
|
9
|
-
|
10
|
-
The constructor sets the USE_KEY_VAULT attribute based on the value of the USE_KEY_VAULT environment variable.
|
11
|
-
If USE_KEY_VAULT is set to "true" (case-insensitive), it initializes a SecretClient object using the
|
12
|
-
AZURE_KEY_VAULT_ENDPOINT environment variable and the DefaultAzureCredential.
|
13
|
-
|
14
|
-
Args:
|
15
|
-
None
|
16
|
-
|
17
|
-
Returns:
|
18
|
-
None
|
19
|
-
"""
|
20
|
-
self.USE_KEY_VAULT = True
|
21
|
-
self.secret_client = None
|
22
|
-
if self.USE_KEY_VAULT:
|
23
|
-
credential = identity.get_credential()
|
24
|
-
self.secret_client = SecretClient(
|
25
|
-
vault_url=keyvault_uri,
|
26
|
-
credential=credential,
|
27
|
-
connection_verify=True,
|
28
|
-
)
|
29
|
-
|
30
|
-
@logger.trace_function(log_execution=True, log_args=False, log_result=False)
|
31
|
-
def get_secret(self, secret_name: str) -> str:
|
32
|
-
"""
|
33
|
-
Retrieves the value of a secret from the environment variables or Azure Key Vault.
|
34
|
-
|
35
|
-
Args:
|
36
|
-
secret_name (str): The name of the secret or "".
|
37
|
-
|
38
|
-
Returns:
|
39
|
-
str: The value of the secret.
|
40
|
-
|
41
|
-
Raises:
|
42
|
-
None
|
43
|
-
|
44
|
-
"""
|
45
|
-
secret_value = self.secret_client.get_secret(name=secret_name).value
|
46
|
-
return secret_value
|
47
|
-
|
48
|
-
@logger.trace_function(log_execution=True, log_args=False, log_result=False)
|
49
|
-
def set_secret(self, secret_name: str, secret_value: str) -> None:
|
50
|
-
"""
|
51
|
-
Sets the value of a secret in Azure Key Vault only if it doesn't exist or has a different value.
|
52
|
-
|
53
|
-
Args:
|
54
|
-
secret_name (str): The name of the secret.
|
55
|
-
secret_value (str): The value to be stored.
|
56
|
-
|
57
|
-
Returns:
|
58
|
-
None
|
59
|
-
|
60
|
-
Raises:
|
61
|
-
None
|
62
|
-
"""
|
63
|
-
try:
|
64
|
-
current_secret = self.secret_client.get_secret(name=secret_name)
|
65
|
-
if current_secret.value != secret_value:
|
66
|
-
self.secret_client.set_secret(name=secret_name, value=secret_value)
|
67
|
-
else:
|
68
|
-
logger.warning(
|
69
|
-
f"Secret {secret_name} already has the same value, skipping update"
|
70
|
-
)
|
71
|
-
except Exception:
|
72
|
-
self.secret_client.set_secret(name=secret_name, value=secret_value)
|
73
|
-
logger.warning(f"Secret {secret_name} has been created")
|
74
|
-
|
75
|
-
|
76
|
-
@logger.trace_function(log_execution=True, log_args=False, log_result=False)
|
77
|
-
def get_secret_from_json(self, secret_name: str) -> str:
|
78
|
-
secret_value = self.secret_client.get_secret(secret_name).value
|
79
|
-
return secret_value
|
File without changes
|
File without changes
|
File without changes
|