cwyodmodules 0.3.32__py3-none-any.whl → 0.3.33__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.
Files changed (46) hide show
  1. cwyodmodules/api/chat_history.py +14 -7
  2. cwyodmodules/batch/utilities/chat_history/auth_utils.py +7 -3
  3. cwyodmodules/batch/utilities/chat_history/cosmosdb.py +17 -1
  4. cwyodmodules/batch/utilities/chat_history/postgresdbservice.py +239 -254
  5. cwyodmodules/batch/utilities/common/source_document.py +60 -61
  6. cwyodmodules/batch/utilities/document_chunking/fixed_size_overlap.py +8 -3
  7. cwyodmodules/batch/utilities/document_chunking/layout.py +8 -3
  8. cwyodmodules/batch/utilities/document_chunking/page.py +8 -3
  9. cwyodmodules/batch/utilities/document_loading/read.py +30 -34
  10. cwyodmodules/batch/utilities/helpers/azure_computer_vision_client.py +10 -3
  11. cwyodmodules/batch/utilities/helpers/azure_form_recognizer_helper.py +6 -2
  12. cwyodmodules/batch/utilities/helpers/azure_postgres_helper.py +14 -2
  13. cwyodmodules/batch/utilities/helpers/azure_postgres_helper_light_rag.py +14 -2
  14. cwyodmodules/batch/utilities/helpers/azure_search_helper.py +15 -6
  15. cwyodmodules/batch/utilities/helpers/config/config_helper.py +24 -2
  16. cwyodmodules/batch/utilities/helpers/env_helper.py +9 -9
  17. cwyodmodules/batch/utilities/helpers/lightrag_helper.py +9 -2
  18. cwyodmodules/batch/utilities/helpers/llm_helper.py +13 -2
  19. cwyodmodules/batch/utilities/helpers/secret_helper.py +9 -9
  20. cwyodmodules/batch/utilities/integrated_vectorization/azure_search_index.py +8 -2
  21. cwyodmodules/batch/utilities/integrated_vectorization/azure_search_indexer.py +9 -2
  22. cwyodmodules/batch/utilities/integrated_vectorization/azure_search_skillset.py +6 -2
  23. cwyodmodules/batch/utilities/orchestrator/lang_chain_agent.py +8 -2
  24. cwyodmodules/batch/utilities/orchestrator/open_ai_functions.py +6 -2
  25. cwyodmodules/batch/utilities/orchestrator/orchestrator_base.py +9 -3
  26. cwyodmodules/batch/utilities/orchestrator/prompt_flow.py +8 -2
  27. cwyodmodules/batch/utilities/orchestrator/semantic_kernel_orchestrator.py +135 -138
  28. cwyodmodules/batch/utilities/parser/output_parser_tool.py +64 -64
  29. cwyodmodules/batch/utilities/plugins/outlook_calendar_plugin.py +91 -93
  30. cwyodmodules/batch/utilities/search/azure_search_handler.py +16 -3
  31. cwyodmodules/batch/utilities/search/azure_search_handler_light_rag.py +14 -2
  32. cwyodmodules/batch/utilities/search/integrated_vectorization_search_handler.py +36 -24
  33. cwyodmodules/batch/utilities/search/lightrag_search_handler.py +14 -2
  34. cwyodmodules/batch/utilities/search/postgres_search_handler.py +100 -97
  35. cwyodmodules/batch/utilities/search/postgres_search_handler_light_rag.py +103 -104
  36. cwyodmodules/batch/utilities/search/search.py +21 -24
  37. cwyodmodules/batch/utilities/tools/content_safety_checker.py +66 -78
  38. cwyodmodules/batch/utilities/tools/post_prompt_tool.py +48 -60
  39. cwyodmodules/batch/utilities/tools/question_answer_tool.py +196 -206
  40. cwyodmodules/batch/utilities/tools/text_processing_tool.py +36 -39
  41. cwyodmodules/logging_config.py +15 -0
  42. {cwyodmodules-0.3.32.dist-info → cwyodmodules-0.3.33.dist-info}/METADATA +2 -1
  43. {cwyodmodules-0.3.32.dist-info → cwyodmodules-0.3.33.dist-info}/RECORD +46 -45
  44. {cwyodmodules-0.3.32.dist-info → cwyodmodules-0.3.33.dist-info}/WHEEL +0 -0
  45. {cwyodmodules-0.3.32.dist-info → cwyodmodules-0.3.33.dist-info}/licenses/LICENSE +0 -0
  46. {cwyodmodules-0.3.32.dist-info → cwyodmodules-0.3.33.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,4 @@
1
1
  import os
2
- import logging
3
2
  from uuid import uuid4
4
3
 
5
4
  # from dotenv import load_dotenv
@@ -11,15 +10,16 @@ from ..batch.utilities.chat_history.auth_utils import (
11
10
  from ..batch.utilities.helpers.config.config_helper import ConfigHelper
12
11
  from ..batch.utilities.helpers.env_helper import EnvHelper
13
12
  from ..batch.utilities.chat_history.database_factory import DatabaseFactory
14
-
13
+ from logging_config import logger
15
14
  # load_dotenv()
15
+
16
16
  bp_chat_history_response = Blueprint("chat_history", __name__)
17
- logger = logging.getLogger("__main__")
18
- logger.setLevel(level=os.environ.get("LOGLEVEL", "INFO").upper())
19
17
 
20
18
  env_helper: EnvHelper = EnvHelper()
19
+ log_args = env_helper.LOG_ARGS
20
+ log_result = env_helper.LOG_RESULT
21
21
 
22
-
22
+ @logger.trace_function(log_args=log_args, log_result=log_result)
23
23
  def init_database_client():
24
24
  try:
25
25
  conversation_client = DatabaseFactory.get_conversation_client()
@@ -28,7 +28,7 @@ def init_database_client():
28
28
  logger.exception("Exception in database initialization: %s", e)
29
29
  raise e
30
30
 
31
-
31
+ @logger.trace_function(log_args=log_args, log_result=log_result)
32
32
  def init_openai_client():
33
33
  try:
34
34
  if env_helper.is_auth_type_keys():
@@ -45,11 +45,12 @@ def init_openai_client():
45
45
  )
46
46
  return azure_openai_client
47
47
  except Exception as e:
48
- logging.exception("Exception in Azure OpenAI initialization: %s", e)
48
+ logger.exception("Exception in Azure OpenAI initialization: %s", e)
49
49
  raise e
50
50
 
51
51
 
52
52
  @bp_chat_history_response.route("/history/list", methods=["GET"])
53
+ @logger.trace_function(log_args=log_args, log_result=log_result)
53
54
  async def list_conversations():
54
55
  config = ConfigHelper.get_active_config_or_default()
55
56
  if not config.enable_chat_history:
@@ -89,6 +90,7 @@ async def list_conversations():
89
90
 
90
91
 
91
92
  @bp_chat_history_response.route("/history/rename", methods=["POST"])
93
+ @logger.trace_function(log_args=log_args, log_result=log_result)
92
94
  async def rename_conversation():
93
95
  config = ConfigHelper.get_active_config_or_default()
94
96
  if not config.enable_chat_history:
@@ -151,6 +153,7 @@ async def rename_conversation():
151
153
 
152
154
 
153
155
  @bp_chat_history_response.route("/history/read", methods=["POST"])
156
+ @logger.trace_function(log_args=log_args, log_result=log_result)
154
157
  async def get_conversation():
155
158
  config = ConfigHelper.get_active_config_or_default()
156
159
  if not config.enable_chat_history:
@@ -223,6 +226,7 @@ async def get_conversation():
223
226
 
224
227
 
225
228
  @bp_chat_history_response.route("/history/delete", methods=["DELETE"])
229
+ @logger.trace_function(log_args=log_args, log_result=log_result)
226
230
  async def delete_conversation():
227
231
  config = ConfigHelper.get_active_config_or_default()
228
232
  if not config.enable_chat_history:
@@ -283,6 +287,7 @@ async def delete_conversation():
283
287
 
284
288
 
285
289
  @bp_chat_history_response.route("/history/delete_all", methods=["DELETE"])
290
+ @logger.trace_function(log_args=log_args, log_result=log_result)
286
291
  async def delete_all_conversations():
287
292
  config = ConfigHelper.get_active_config_or_default()
288
293
 
@@ -354,6 +359,7 @@ async def delete_all_conversations():
354
359
 
355
360
 
356
361
  @bp_chat_history_response.route("/history/update", methods=["POST"])
362
+ @logger.trace_function(log_args=log_args, log_result=log_result)
357
363
  async def update_conversation():
358
364
  config = ConfigHelper.get_active_config_or_default()
359
365
  if not config.enable_chat_history:
@@ -455,6 +461,7 @@ async def update_conversation():
455
461
 
456
462
 
457
463
  @bp_chat_history_response.route("/history/frontend_settings", methods=["GET"])
464
+ @logger.trace_function(log_args=log_args, log_result=log_result)
458
465
  def get_frontend_settings():
459
466
  try:
460
467
  # Clear the cache for the config helper method
@@ -1,8 +1,13 @@
1
1
  import base64
2
2
  import json
3
- import logging
4
3
 
4
+ from ...utilities.helpers.env_helper import EnvHelper
5
+ from logging_config import logger
6
+ env_helper: EnvHelper = EnvHelper()
7
+ log_args = env_helper.LOG_ARGS
8
+ log_result = env_helper.LOG_RESULT
5
9
 
10
+ @logger.trace_function(log_args=log_args, log_result=log_result)
6
11
  def get_authenticated_user_details(request_headers):
7
12
  user_object = {}
8
13
 
@@ -25,9 +30,8 @@ def get_authenticated_user_details(request_headers):
25
30
 
26
31
  return user_object
27
32
 
28
-
33
+ @logger.trace_function(log_args=log_args, log_result=log_result)
29
34
  def get_tenantid(client_principal_b64):
30
- logger = logging.getLogger("__main__")
31
35
  tenant_id = ""
32
36
  if client_principal_b64:
33
37
  try:
@@ -3,7 +3,11 @@ from azure.cosmos.aio import CosmosClient
3
3
  from azure.cosmos import exceptions
4
4
 
5
5
  from .database_client_base import DatabaseClientBase
6
-
6
+ from ...utilities.helpers.env_helper import EnvHelper
7
+ from logging_config import logger
8
+ env_helper: EnvHelper = EnvHelper()
9
+ log_args = env_helper.LOG_ARGS
10
+ log_result = env_helper.LOG_RESULT
7
11
 
8
12
  class CosmosConversationClient(DatabaseClientBase):
9
13
 
@@ -44,12 +48,15 @@ class CosmosConversationClient(DatabaseClientBase):
44
48
  except exceptions.CosmosResourceNotFoundError:
45
49
  raise ValueError("Invalid CosmosDB container name")
46
50
 
51
+ @logger.trace_function(log_args=log_args, log_result=log_result)
47
52
  async def connect(self):
48
53
  pass
49
54
 
55
+ @logger.trace_function(log_args=log_args, log_result=log_result)
50
56
  async def close(self):
51
57
  pass
52
58
 
59
+ @logger.trace_function(log_args=log_args, log_result=log_result)
53
60
  async def ensure(self):
54
61
  if (
55
62
  not self.cosmosdb_client
@@ -72,6 +79,7 @@ class CosmosConversationClient(DatabaseClientBase):
72
79
 
73
80
  return True, "CosmosDB client initialized successfully"
74
81
 
82
+ @logger.trace_function(log_args=log_args, log_result=log_result)
75
83
  async def create_conversation(self, user_id, conversation_id, title=""):
76
84
  conversation = {
77
85
  "id": conversation_id,
@@ -89,6 +97,7 @@ class CosmosConversationClient(DatabaseClientBase):
89
97
  else:
90
98
  return False
91
99
 
100
+ @logger.trace_function(log_args=log_args, log_result=log_result)
92
101
  async def upsert_conversation(self, conversation):
93
102
  resp = await self.container_client.upsert_item(conversation)
94
103
  if resp:
@@ -96,6 +105,7 @@ class CosmosConversationClient(DatabaseClientBase):
96
105
  else:
97
106
  return False
98
107
 
108
+ @logger.trace_function(log_args=log_args, log_result=log_result)
99
109
  async def delete_conversation(self, user_id, conversation_id):
100
110
  conversation = await self.container_client.read_item(
101
111
  item=conversation_id, partition_key=user_id
@@ -108,6 +118,7 @@ class CosmosConversationClient(DatabaseClientBase):
108
118
  else:
109
119
  return True
110
120
 
121
+ @logger.trace_function(log_args=log_args, log_result=log_result)
111
122
  async def delete_messages(self, conversation_id, user_id):
112
123
  # get a list of all the messages in the conversation
113
124
  messages = await self.get_messages(user_id, conversation_id)
@@ -120,6 +131,7 @@ class CosmosConversationClient(DatabaseClientBase):
120
131
  response_list.append(resp)
121
132
  return response_list
122
133
 
134
+ @logger.trace_function(log_args=log_args, log_result=log_result)
123
135
  async def get_conversations(self, user_id, limit, sort_order="DESC", offset=0):
124
136
  parameters = [{"name": "@userId", "value": user_id}]
125
137
  query = f"SELECT * FROM c where c.userId = @userId and c.type='conversation' order by c.updatedAt {sort_order}"
@@ -134,6 +146,7 @@ class CosmosConversationClient(DatabaseClientBase):
134
146
 
135
147
  return conversations
136
148
 
149
+ @logger.trace_function(log_args=log_args, log_result=log_result)
137
150
  async def get_conversation(self, user_id, conversation_id):
138
151
  parameters = [
139
152
  {"name": "@conversationId", "value": conversation_id},
@@ -152,6 +165,7 @@ class CosmosConversationClient(DatabaseClientBase):
152
165
  else:
153
166
  return conversations[0]
154
167
 
168
+ @logger.trace_function(log_args=log_args, log_result=log_result)
155
169
  async def create_message(self, uuid, conversation_id, user_id, input_message: dict):
156
170
  message = {
157
171
  "id": uuid,
@@ -179,6 +193,7 @@ class CosmosConversationClient(DatabaseClientBase):
179
193
  else:
180
194
  return False
181
195
 
196
+ @logger.trace_function(log_args=log_args, log_result=log_result)
182
197
  async def update_message_feedback(self, user_id, message_id, feedback):
183
198
  message = await self.container_client.read_item(
184
199
  item=message_id, partition_key=user_id
@@ -190,6 +205,7 @@ class CosmosConversationClient(DatabaseClientBase):
190
205
  else:
191
206
  return False
192
207
 
208
+ @logger.trace_function(log_args=log_args, log_result=log_result)
193
209
  async def get_messages(self, user_id, conversation_id):
194
210
  parameters = [
195
211
  {"name": "@conversationId", "value": conversation_id},