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.
@@ -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
- from .agent_mode import AgentMode
17
-
18
- CONFIG_CONTAINER_NAME = "config"
19
- CONFIG_FILE_NAME = "active.json"
20
- ADVANCED_IMAGE_PROCESSING_FILE_TYPES = ["jpeg", "jpg", "png", "tiff", "bmp"]
21
-
22
- from mgmt_config import logger
23
- env_helper: EnvHelper = EnvHelper()
24
- log_execution = env_helper.LOG_EXECUTION
25
- log_args = env_helper.LOG_ARGS
26
- log_result = env_helper.LOG_RESULT
27
-
28
-
29
- class Config:
30
- def __init__(self, config: dict):
31
- self.prompts = Prompts(config["prompts"])
32
- self.messages = Messages(config["messages"])
33
- self.example = Example(config["example"])
34
- self.logging = Logging(config["logging"])
35
- self.document_processors = [
36
- EmbeddingConfig(
37
- document_type=c["document_type"],
38
- chunking=ChunkingSettings(c["chunking"]),
39
- loading=LoadingSettings(c["loading"]),
40
- use_advanced_image_processing=c.get(
41
- "use_advanced_image_processing", False
42
- ),
43
- )
44
- for c in config["document_processors"]
45
- ]
46
- self.env_helper = EnvHelper()
47
- self.default_orchestration_settings = {
48
- "strategy": self.env_helper.ORCHESTRATION_STRATEGY
49
- }
50
- self.orchestrator = OrchestrationSettings(
51
- config.get("orchestrator", self.default_orchestration_settings)
52
- )
53
- self.integrated_vectorization_config = (
54
- IntegratedVectorizationConfig(config["integrated_vectorization_config"])
55
- if self.env_helper.AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION
56
- else None
57
- )
58
- self.enable_chat_history = config["enable_chat_history"]
59
- self.database_type = config.get("database_type", self.env_helper.DATABASE_TYPE)
60
- self.conversational_flow = config.get(
61
- "conversational_flow", self.env_helper.CONVERSATION_FLOW
62
- )
63
- self.agent_mode = config.get("agent_mode", AgentMode.NORMAL.value)
64
-
65
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
66
- def get_available_document_types(self) -> list[str]:
67
- document_types = {
68
- "txt",
69
- "pdf",
70
- "url",
71
- "html",
72
- "htm",
73
- "md",
74
- "jpeg",
75
- "jpg",
76
- "png",
77
- "docx",
78
- }
79
- if self.env_helper.USE_ADVANCED_IMAGE_PROCESSING:
80
- document_types.update(ADVANCED_IMAGE_PROCESSING_FILE_TYPES)
81
-
82
- return sorted(document_types)
83
-
84
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
85
- def get_advanced_image_processing_image_types(self):
86
- return ADVANCED_IMAGE_PROCESSING_FILE_TYPES
87
-
88
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
89
- def get_available_chunking_strategies(self):
90
- return [c.value for c in ChunkingStrategy]
91
-
92
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
93
- def get_available_loading_strategies(self):
94
- return [c.value for c in LoadingStrategy]
95
-
96
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
97
- def get_available_orchestration_strategies(self):
98
- return [c.value for c in OrchestrationStrategy]
99
-
100
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
101
- def get_available_ai_assistant_types(self):
102
- return [c.value for c in AssistantStrategy]
103
-
104
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
105
- def get_available_conversational_flows(self):
106
- return [c.value for c in ConversationFlow]
107
-
108
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
109
- def get_available_agent_modes(self):
110
- return [c.value for c in AgentMode]
111
-
112
-
113
- # TODO: Change to AnsweringChain or something, Prompts is not a good name
114
- class Prompts:
115
- def __init__(self, prompts: dict):
116
- self.condense_question_prompt = prompts["condense_question_prompt"]
117
- self.answering_system_prompt = prompts["answering_system_prompt"]
118
- self.answering_user_prompt = prompts["answering_user_prompt"]
119
- self.post_answering_prompt = prompts["post_answering_prompt"]
120
- self.use_on_your_data_format = prompts["use_on_your_data_format"]
121
- self.enable_post_answering_prompt = prompts["enable_post_answering_prompt"]
122
- self.enable_content_safety = prompts["enable_content_safety"]
123
- self.ai_assistant_type = prompts["ai_assistant_type"]
124
- self.conversational_flow = prompts["conversational_flow"]
125
-
126
-
127
- class Example:
128
- def __init__(self, example: dict):
129
- self.documents = example["documents"]
130
- self.user_question = example["user_question"]
131
- self.answer = example["answer"]
132
-
133
-
134
- class Messages:
135
- def __init__(self, messages: dict):
136
- self.post_answering_filter = messages["post_answering_filter"]
137
-
138
-
139
- class Logging:
140
- def __init__(self, logging: dict):
141
- self.log_user_interactions = (
142
- str(logging["log_user_interactions"]).lower() == "true"
143
- )
144
- self.log_tokens = str(logging["log_tokens"]).lower() == "true"
145
-
146
-
147
- class IntegratedVectorizationConfig:
148
- def __init__(self, integrated_vectorization_config: dict):
149
- self.max_page_length = integrated_vectorization_config["max_page_length"]
150
- self.page_overlap_length = integrated_vectorization_config[
151
- "page_overlap_length"
152
- ]
153
-
154
-
155
- class ConfigHelper:
156
- _default_config = None
157
-
158
- @staticmethod
159
- @logger.trace_function(log_execution=log_execution, log_args=False, log_result=False)
160
- def _set_new_config_properties(config: dict, default_config: dict):
161
- """
162
- Function used to set newer properties that will not be present in older configs.
163
- The function mutates the config object.
164
- """
165
- if config["prompts"].get("answering_system_prompt") is None:
166
- config["prompts"]["answering_system_prompt"] = default_config["prompts"][
167
- "answering_system_prompt"
168
- ]
169
-
170
- prompt_modified = (
171
- config["prompts"].get("answering_prompt")
172
- != default_config["prompts"]["answering_prompt"]
173
- )
174
-
175
- if config["prompts"].get("answering_user_prompt") is None:
176
- if prompt_modified:
177
- config["prompts"]["answering_user_prompt"] = config["prompts"].get(
178
- "answering_prompt"
179
- )
180
- else:
181
- config["prompts"]["answering_user_prompt"] = default_config["prompts"][
182
- "answering_user_prompt"
183
- ]
184
-
185
- if config["prompts"].get("use_on_your_data_format") is None:
186
- config["prompts"]["use_on_your_data_format"] = not prompt_modified
187
-
188
- if config.get("example") is None:
189
- config["example"] = default_config["example"]
190
-
191
- if config["prompts"].get("ai_assistant_type") is None:
192
- config["prompts"]["ai_assistant_type"] = default_config["prompts"][
193
- "ai_assistant_type"
194
- ]
195
-
196
- if config.get("integrated_vectorization_config") is None:
197
- config["integrated_vectorization_config"] = default_config[
198
- "integrated_vectorization_config"
199
- ]
200
-
201
- if config["prompts"].get("conversational_flow") is None:
202
- config["prompts"]["conversational_flow"] = default_config["prompts"][
203
- "conversational_flow"
204
- ]
205
- if config.get("enable_chat_history") is None:
206
- config["enable_chat_history"] = default_config["enable_chat_history"]
207
-
208
- if config.get("agent_mode") is None:
209
- config["agent_mode"] = default_config["agent_mode"]
210
-
211
- @staticmethod
212
- @functools.cache
213
- @logger.trace_function(log_execution=log_execution, log_args=False, log_result=False)
214
- def get_active_config_or_default():
215
- logger.info("Method get_active_config_or_default started")
216
- env_helper = EnvHelper()
217
- config = ConfigHelper.get_default_config()
218
- if env_helper.LOAD_CONFIG_FROM_BLOB_STORAGE:
219
- logger.info("Loading configuration from Blob Storage")
220
- blob_client = AzureBlobStorageClient(container_name=CONFIG_CONTAINER_NAME)
221
-
222
- if blob_client.file_exists(CONFIG_FILE_NAME):
223
- logger.info("Configuration file found in Blob Storage")
224
- default_config = config
225
- config_file = blob_client.download_file(CONFIG_FILE_NAME)
226
- config = json.loads(config_file)
227
-
228
- ConfigHelper._set_new_config_properties(config, default_config)
229
- else:
230
- logger.info(
231
- "Configuration file not found in Blob Storage, using default configuration"
232
- )
233
-
234
- logger.info("Method get_active_config_or_default ended")
235
- return Config(config)
236
-
237
- @staticmethod
238
- @functools.cache
239
- @logger.trace_function(log_execution=log_execution, log_args=False, log_result=False)
240
- def get_default_assistant_prompt():
241
- config = ConfigHelper.get_default_config()
242
- return config["prompts"]["answering_user_prompt"]
243
-
244
- @staticmethod
245
- @logger.trace_function(log_execution=log_execution, log_args=False, log_result=log_result)
246
- def save_config_as_active(config):
247
- ConfigHelper.validate_config(config)
248
- blob_client = AzureBlobStorageClient(container_name=CONFIG_CONTAINER_NAME)
249
- blob_client = blob_client.upload_file(
250
- json.dumps(config, indent=2),
251
- CONFIG_FILE_NAME,
252
- content_type="application/json",
253
- )
254
- ConfigHelper.get_active_config_or_default.cache_clear()
255
-
256
- @staticmethod
257
- @logger.trace_function(log_execution=log_execution, log_args=False, log_result=log_result)
258
- def validate_config(config: dict):
259
- for document_processor in config.get("document_processors"):
260
- document_type = document_processor.get("document_type")
261
- unsupported_advanced_image_processing_file_type = (
262
- document_type not in ADVANCED_IMAGE_PROCESSING_FILE_TYPES
263
- )
264
- if (
265
- document_processor.get("use_advanced_image_processing")
266
- and unsupported_advanced_image_processing_file_type
267
- ):
268
- raise Exception(
269
- f"Advanced image processing has not been enabled for document type {document_type}, as only {ADVANCED_IMAGE_PROCESSING_FILE_TYPES} file types are supported."
270
- )
271
-
272
- @staticmethod
273
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=False)
274
- def get_default_config():
275
- if ConfigHelper._default_config is None:
276
- env_helper = EnvHelper()
277
-
278
- config_file_path = os.path.join(os.path.dirname(__file__), "default.json")
279
- logger.info("Loading default config from %s", config_file_path)
280
- with open(config_file_path, encoding="utf-8") as f:
281
- ConfigHelper._default_config = json.loads(
282
- Template(f.read()).substitute(
283
- ORCHESTRATION_STRATEGY=env_helper.ORCHESTRATION_STRATEGY,
284
- LOG_USER_INTERACTIONS=(
285
- False
286
- if env_helper.DATABASE_TYPE == DatabaseType.POSTGRESQL.value
287
- else True
288
- ),
289
- LOG_TOKENS=(
290
- False
291
- if env_helper.DATABASE_TYPE == DatabaseType.POSTGRESQL.value
292
- else True
293
- ),
294
- CONVERSATION_FLOW=env_helper.CONVERSATION_FLOW,
295
- DATABASE_TYPE=env_helper.DATABASE_TYPE,
296
- )
297
- )
298
- if env_helper.USE_ADVANCED_IMAGE_PROCESSING:
299
- ConfigHelper._append_advanced_image_processors()
300
-
301
- return ConfigHelper._default_config
302
-
303
- @staticmethod
304
- @functools.cache
305
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=False)
306
- def get_default_contract_assistant():
307
- contract_file_path = os.path.join(
308
- os.path.dirname(__file__), "default_contract_assistant_prompt.txt"
309
- )
310
- contract_assistant = ""
311
- with open(contract_file_path, encoding="utf-8") as f:
312
- contract_assistant = f.readlines()
313
-
314
- return "".join([str(elem) for elem in contract_assistant])
315
-
316
- @staticmethod
317
- @functools.cache
318
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=False)
319
- def get_default_employee_assistant():
320
- employee_file_path = os.path.join(
321
- os.path.dirname(__file__), "default_employee_assistant_prompt.txt"
322
- )
323
- employee_assistant = ""
324
- with open(employee_file_path, encoding="utf-8") as f:
325
- employee_assistant = f.readlines()
326
-
327
- return "".join([str(elem) for elem in employee_assistant])
328
-
329
- @staticmethod
330
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
331
- def clear_config():
332
- ConfigHelper._default_config = None
333
- ConfigHelper.get_active_config_or_default.cache_clear()
334
-
335
- @staticmethod
336
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
337
- def _append_advanced_image_processors():
338
- image_file_types = ["jpeg", "jpg", "png", "tiff", "bmp"]
339
- ConfigHelper._remove_processors_for_file_types(image_file_types)
340
- ConfigHelper._default_config["document_processors"].extend(
341
- [
342
- {"document_type": file_type, "use_advanced_image_processing": True}
343
- for file_type in image_file_types
344
- ]
345
- )
346
-
347
- @staticmethod
348
- @logger.trace_function(log_execution=log_execution, log_args=log_args, log_result=log_result)
349
- def _remove_processors_for_file_types(file_types: list[str]):
350
- document_processors = ConfigHelper._default_config["document_processors"]
351
- document_processors = [
352
- document_processor
353
- for document_processor in document_processors
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)
@@ -143,6 +143,5 @@
143
143
  "strategy": "${ORCHESTRATION_STRATEGY}"
144
144
  },
145
145
  "enable_chat_history": true,
146
- "database_type": "${DATABASE_TYPE}",
147
- "agent_mode": "off"
146
+ "database_type": "${DATABASE_TYPE}"
148
147
  }
@@ -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 = SecretHelper(keyvault_uri=os.environ["key_vault_uri"])
35
+ self.secretHelper = keyvault
37
36
 
38
- self.secretHelperHead = SecretHelper(
39
- keyvault_uri=os.environ["head_key_vault_uri"]
37
+ self.secretHelperHead = create_keyvault_client(
38
+ vault_url=os.environ["head_key_vault_uri"]
40
39
  )
41
40
 
42
41
  # self.secretHelper = SecretHelper(
@@ -1,132 +1,181 @@
1
- """
2
- Azure Project Management Configuration Template
3
-
4
- This template provides standardized configuration for Azure logging and identity
5
- management across projects. It creates singleton instances of AzureLogger and
6
- AzureIdentity that can be imported and used throughout your application.
7
-
8
- Usage:
9
- from mgmt_config import logger, identity
10
-
11
- logger.info("Application started")
12
- credential = identity.get_credential()
13
- """
14
-
15
- import os
16
- from typing import Optional, Dict, Any
17
- from azpaddypy.mgmt.logging import create_app_logger, create_function_logger
18
- from azpaddypy.mgmt.identity import create_azure_identity
19
-
20
- # =============================================================================
21
- # SERVICE CONFIGURATION
22
- # =============================================================================
23
-
24
- # Service identity - customize these for your project
25
- SERVICE_NAME = os.getenv("SERVICE_NAME", "cwyodmodules-pacakge")
26
- SERVICE_VERSION = os.getenv("SERVICE_VERSION", "1.0.0")
27
-
28
- # =============================================================================
29
- # LOGGING CONFIGURATION
30
- # =============================================================================
31
-
32
- # Enable console output (useful for local development)
33
- LOGGER_ENABLE_CONSOLE = os.getenv("LOGGER_ENABLE_CONSOLE", "true").lower() == "true"
34
-
35
- # Application Insights connection string (optional, will use environment variable if not set)
36
- LOGGER_CONNECTION_STRING = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
37
-
38
- # Configure which Azure SDK components to instrument
39
- LOGGER_INSTRUMENTATION_OPTIONS = {
40
- "azure_sdk": {"enabled": True},
41
- "django": {"enabled": False},
42
- "fastapi": {"enabled": False},
43
- "flask": {"enabled": True},
44
- "psycopg2": {"enabled": True},
45
- "requests": {"enabled": True},
46
- "urllib": {"enabled": True},
47
- "urllib3": {"enabled": True},
48
- }
49
-
50
- # =============================================================================
51
- # IDENTITY CONFIGURATION
52
- # =============================================================================
53
-
54
- # Token caching settings
55
- IDENTITY_ENABLE_TOKEN_CACHE = os.getenv("IDENTITY_ENABLE_TOKEN_CACHE", "true").lower() == "true"
56
- IDENTITY_ALLOW_UNENCRYPTED_STORAGE = os.getenv("IDENTITY_ALLOW_UNENCRYPTED_STORAGE", "true").lower() == "true"
57
-
58
- # Custom credential options (None means use defaults)
59
- IDENTITY_CUSTOM_CREDENTIAL_OPTIONS: Optional[Dict[str, Any]] = None
60
-
61
- # Connection string for identity logging (uses same as logger by default)
62
- IDENTITY_CONNECTION_STRING = LOGGER_CONNECTION_STRING
63
-
64
- # =============================================================================
65
- # INITIALIZE SERVICES
66
- # =============================================================================
67
- # Create logger instance
68
- if "functionapp" in os.getenv("REFLECTION_KIND", "app"):
69
- logger = create_function_logger(
70
- function_app_name=os.getenv("REFLECTION_NAME", "app"),
71
- function_name="backend",
72
- service_version=SERVICE_VERSION,
73
- connection_string=LOGGER_CONNECTION_STRING,
74
- instrumentation_options=LOGGER_INSTRUMENTATION_OPTIONS,
75
- )
76
- logger.info("Function logger initialized")
77
- else:
78
- logger = create_app_logger(
79
- service_name=SERVICE_NAME,
80
- service_version=SERVICE_VERSION,
81
- connection_string=LOGGER_CONNECTION_STRING,
82
- enable_console_logging=LOGGER_ENABLE_CONSOLE,
83
- instrumentation_options=LOGGER_INSTRUMENTATION_OPTIONS,
84
- )
85
- logger.info("App logger initialized")
86
-
87
- # Create identity instance with shared logger
88
- identity = create_azure_identity(
89
- service_name=SERVICE_NAME,
90
- service_version=SERVICE_VERSION,
91
- enable_token_cache=IDENTITY_ENABLE_TOKEN_CACHE,
92
- allow_unencrypted_storage=IDENTITY_ALLOW_UNENCRYPTED_STORAGE,
93
- custom_credential_options=IDENTITY_CUSTOM_CREDENTIAL_OPTIONS,
94
- connection_string=IDENTITY_CONNECTION_STRING,
95
- logger=logger,
96
- )
97
-
98
- # =============================================================================
99
- # VALIDATION & STARTUP
100
- # =============================================================================
101
-
102
- # Validate critical configuration
103
- if SERVICE_NAME == __name__:
104
- logger.warning(
105
- "SERVICE_NAME is not configured. Please set SERVICE_NAME environment variable or update this template.",
106
- extra={"configuration_issue": "service_name_not_set"}
107
- )
108
-
109
- if not LOGGER_CONNECTION_STRING:
110
- logger.info(
111
- "No Application Insights connection string configured. Telemetry will be disabled.",
112
- extra={"telemetry_status": "disabled"}
113
- )
114
-
115
- # Log successful initialization
116
- logger.info(
117
- f"Management configuration initialized for service '{SERVICE_NAME}' v{SERVICE_VERSION}",
118
- extra={
119
- "service_name": SERVICE_NAME,
120
- "service_version": SERVICE_VERSION,
121
- "console_logging": LOGGER_ENABLE_CONSOLE,
122
- "token_cache_enabled": IDENTITY_ENABLE_TOKEN_CACHE,
123
- "telemetry_enabled": bool(LOGGER_CONNECTION_STRING),
124
- }
125
- )
126
-
127
- # =============================================================================
128
- # EXPORTS
129
- # =============================================================================
130
-
131
- # Export both logger and identity for use in applications
132
- __all__ = ["logger", "identity"]
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.45
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.4
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=xRp9absSmQifcKKCn6fyqcMSJ9hDvMTqPPAViezJHZw,5308
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=S0EG0XzILrJ_iPCAwKN-kzx-yPl5K__MtBZee924DKE,15881
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=rHP9YgkwG9UodAlRALesQ54M_dDsl801s_gP710vqHk,15685
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=kwZg04XoLlKnva22o_YIuC31jWeSTpuewJTG9oyJP9o,15430
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.45.dist-info/licenses/LICENSE,sha256=UqBDTipijsSW2ZSOXyTZnMsXmLoEHTgNEM0tL4g-Sso,1150
114
- cwyodmodules-0.3.45.dist-info/METADATA,sha256=dhCo5n3jzElUG7B7kF2FimtLv8dXN5kYYF15zVZaaNU,2002
115
- cwyodmodules-0.3.45.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
116
- cwyodmodules-0.3.45.dist-info/top_level.txt,sha256=99RENLbkdRX-qpJvsxZ5AfmTL5s6shSaKOWYpz1vwzg,13
117
- cwyodmodules-0.3.45.dist-info/RECORD,,
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