Skip to content

Commit b2f5d22

Browse files
author
Jarno Ensio Hakulinen
committed
update logger
1 parent 6c37747 commit b2f5d22

6 files changed

Lines changed: 39 additions & 8 deletions

File tree

sdk/azure-ai-assistant/azure/ai/assistant/management/assistant_config.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,9 @@ def __init__(self,
656656
# Completion settings based on assistant type
657657
self._text_completion_config = self._setup_completion_settings(config_data)
658658

659+
# Config folder for local assistant and threads configuration
660+
self._config_folder = None
661+
659662
def _setup_completion_settings(self, config_data):
660663
if config_data.get('completion_settings', None) is not None:
661664
if self._assistant_type == 'chat_assistant':
@@ -787,6 +790,7 @@ def _get_config_data(self):
787790
self._config_data['assistant_type'] = self._assistant_type
788791
self._config_data['assistant_role'] = self._assistant_role
789792
self._config_data['completion_settings'] = self._text_completion_config.to_dict() if self._text_completion_config is not None else None
793+
self._config_data['config_folder'] = self._config_folder
790794
return self._config_data
791795

792796
def _get_function_configs(self):
@@ -1025,6 +1029,25 @@ def text_completion_config(self) -> Union[TextCompletionConfig, AssistantTextCom
10251029
:rtype: Union[TextCompletionConfig, AssistantTextCompletionConfig, None]
10261030
"""
10271031
return self._text_completion_config
1032+
1033+
@property
1034+
def config_folder(self) -> str:
1035+
"""Get the config folder.
1036+
1037+
:return: The config folder.
1038+
:rtype: str
1039+
"""
1040+
return self._config_folder
1041+
1042+
@config_folder.setter
1043+
def config_folder(self, value) -> None:
1044+
"""
1045+
Set the config folder.
1046+
1047+
:param value: The config folder.
1048+
:type value: str
1049+
"""
1050+
self._config_folder = value
10281051

10291052
def _remove_trailing_spaces(self, text):
10301053
return '\n'.join(line.rstrip() for line in text.splitlines())

sdk/azure-ai-assistant/azure/ai/assistant/management/async_conversation_thread_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ def __init_private(
3838
**client_args
3939
):
4040
self._ai_client_type = ai_client_type
41+
self._config_folder = config_folder
4142
self._ai_client : Union[AsyncOpenAI, AsyncAzureOpenAI] = AIClientFactory.get_instance().get_client(self._ai_client_type, **client_args)
42-
self._thread_config = ConversationThreadConfig(self._ai_client_type, config_folder)
43+
self._thread_config = ConversationThreadConfig(self._ai_client_type, self._config_folder)
4344
self._assistant_config_manager = AssistantConfigManager.get_instance()
4445

4546
@classmethod

sdk/azure-ai-assistant/azure/ai/assistant/management/base_assistant_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ def _initialize_client(
6161
self._ai_client : Union[OpenAI, AsyncOpenAI, AzureOpenAI, AsyncAzureOpenAI] = self._get_ai_client(self._ai_client_type, **client_args)
6262
if async_mode:
6363
self._callbacks = callbacks if callbacks is not None else AsyncAssistantClientCallbacks()
64-
self._conversation_thread_client = AsyncConversationThreadClient.get_instance(self._ai_client_type)
64+
self._conversation_thread_client = AsyncConversationThreadClient.get_instance(self._ai_client_type, config_folder=self._config_data["config_folder"])
6565
else:
6666
self._callbacks = callbacks if callbacks is not None else AssistantClientCallbacks()
67-
self._conversation_thread_client = ConversationThreadClient.get_instance(self._ai_client_type)
67+
self._conversation_thread_client = ConversationThreadClient.get_instance(self._ai_client_type, config_folder=self._config_data["config_folder"])
6868
self._functions = {}
6969
self._assistant_config = AssistantConfig.from_dict(self._config_data)
7070
self._cancel_run_requested = threading.Event()

sdk/azure-ai-assistant/azure/ai/assistant/management/conversation_thread_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ def __init_private(
3838
**client_args
3939
):
4040
self._ai_client_type = ai_client_type
41+
self._config_folder = config_folder
4142
self._ai_client : Union[OpenAI, AzureOpenAI] = AIClientFactory.get_instance().get_client(self._ai_client_type, **client_args)
42-
self._thread_config = ConversationThreadConfig(self._ai_client_type, config_folder)
43+
self._thread_config = ConversationThreadConfig(self._ai_client_type, self._config_folder)
4344
self._assistant_config_manager = AssistantConfigManager.get_instance()
4445

4546
@classmethod

sdk/azure-ai-assistant/azure/ai/assistant/management/function_config_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ def _default_config_path() -> str:
5858
@classmethod
5959
def get_instance(
6060
cls,
61-
config_directory : Optional[str] = None
61+
config_folder : Optional[str] = None
6262
) -> 'FunctionConfigManager':
6363
"""
6464
Get the singleton instance of FunctionConfigManager.
6565
66-
:param config_directory: The directory containing the function specifications.
67-
:type config_directory: str
66+
:param config_folder: The directory containing the function specifications.
67+
:type config_folder: str
6868
6969
:return: The singleton instance of FunctionConfigManager.
7070
:rtype: FunctionConfigManager
7171
"""
7272
if cls._instance is None:
73-
cls._instance = cls(config_directory)
73+
cls._instance = cls(config_folder)
7474
return cls._instance
7575

7676
def load_function_configs(self) -> None:

sdk/azure-ai-assistant/azure/ai/assistant/management/logger_module.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def setup_logger() -> logging.Logger:
3030
logger = logging.getLogger('assistant_logger')
3131
logger.setLevel(logging.INFO)
3232

33+
# Disable by default
34+
logger.disabled = True
35+
3336
# Including function name in the log message format
3437
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(funcName)s - %(message)s')
3538

@@ -39,12 +42,14 @@ def setup_logger() -> logging.Logger:
3942
log_to_file = os.getenv('ASSISTANT_LOG_TO_FILE', 'false').lower() in ('true', '1', 't')
4043

4144
if log_to_file:
45+
logger.disabled = False
4246
# Set the file handler with UTF-8 encoding for file output
4347
file_handler = logging.FileHandler('assistant.log', encoding='utf-8')
4448
file_handler.setFormatter(formatter)
4549
logger.addHandler(file_handler)
4650

4751
if log_to_console:
52+
logger.disabled = False
4853
# Set the stream handler for console output
4954
stream_handler = logging.StreamHandler()
5055
stream_handler.setFormatter(formatter)
@@ -60,6 +65,7 @@ def add_broadcaster_to_logger(broadcaster) -> None:
6065
"""
6166
global logger
6267

68+
logger.disabled = False
6369
# Check if a BroadcasterLoggingHandler is already added and update it
6470
for handler in logger.handlers:
6571
if isinstance(handler, BroadcasterLoggingHandler):

0 commit comments

Comments
 (0)