Skip to content

Commit

Permalink
update logger
Browse files Browse the repository at this point in the history
  • Loading branch information
jhakulin committed May 9, 2024
1 parent 6c37747 commit b2f5d22
Showing 6 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -656,6 +656,9 @@ def __init__(self,
# Completion settings based on assistant type
self._text_completion_config = self._setup_completion_settings(config_data)

# Config folder for local assistant and threads configuration
self._config_folder = None

def _setup_completion_settings(self, config_data):
if config_data.get('completion_settings', None) is not None:
if self._assistant_type == 'chat_assistant':
@@ -787,6 +790,7 @@ def _get_config_data(self):
self._config_data['assistant_type'] = self._assistant_type
self._config_data['assistant_role'] = self._assistant_role
self._config_data['completion_settings'] = self._text_completion_config.to_dict() if self._text_completion_config is not None else None
self._config_data['config_folder'] = self._config_folder
return self._config_data

def _get_function_configs(self):
@@ -1025,6 +1029,25 @@ def text_completion_config(self) -> Union[TextCompletionConfig, AssistantTextCom
:rtype: Union[TextCompletionConfig, AssistantTextCompletionConfig, None]
"""
return self._text_completion_config

@property
def config_folder(self) -> str:
"""Get the config folder.
:return: The config folder.
:rtype: str
"""
return self._config_folder

@config_folder.setter
def config_folder(self, value) -> None:
"""
Set the config folder.
:param value: The config folder.
:type value: str
"""
self._config_folder = value

def _remove_trailing_spaces(self, text):
return '\n'.join(line.rstrip() for line in text.splitlines())
Original file line number Diff line number Diff line change
@@ -38,8 +38,9 @@ def __init_private(
**client_args
):
self._ai_client_type = ai_client_type
self._config_folder = config_folder
self._ai_client : Union[AsyncOpenAI, AsyncAzureOpenAI] = AIClientFactory.get_instance().get_client(self._ai_client_type, **client_args)
self._thread_config = ConversationThreadConfig(self._ai_client_type, config_folder)
self._thread_config = ConversationThreadConfig(self._ai_client_type, self._config_folder)
self._assistant_config_manager = AssistantConfigManager.get_instance()

@classmethod
Original file line number Diff line number Diff line change
@@ -61,10 +61,10 @@ def _initialize_client(
self._ai_client : Union[OpenAI, AsyncOpenAI, AzureOpenAI, AsyncAzureOpenAI] = self._get_ai_client(self._ai_client_type, **client_args)
if async_mode:
self._callbacks = callbacks if callbacks is not None else AsyncAssistantClientCallbacks()
self._conversation_thread_client = AsyncConversationThreadClient.get_instance(self._ai_client_type)
self._conversation_thread_client = AsyncConversationThreadClient.get_instance(self._ai_client_type, config_folder=self._config_data["config_folder"])
else:
self._callbacks = callbacks if callbacks is not None else AssistantClientCallbacks()
self._conversation_thread_client = ConversationThreadClient.get_instance(self._ai_client_type)
self._conversation_thread_client = ConversationThreadClient.get_instance(self._ai_client_type, config_folder=self._config_data["config_folder"])
self._functions = {}
self._assistant_config = AssistantConfig.from_dict(self._config_data)
self._cancel_run_requested = threading.Event()
Original file line number Diff line number Diff line change
@@ -38,8 +38,9 @@ def __init_private(
**client_args
):
self._ai_client_type = ai_client_type
self._config_folder = config_folder
self._ai_client : Union[OpenAI, AzureOpenAI] = AIClientFactory.get_instance().get_client(self._ai_client_type, **client_args)
self._thread_config = ConversationThreadConfig(self._ai_client_type, config_folder)
self._thread_config = ConversationThreadConfig(self._ai_client_type, self._config_folder)
self._assistant_config_manager = AssistantConfigManager.get_instance()

@classmethod
Original file line number Diff line number Diff line change
@@ -58,19 +58,19 @@ def _default_config_path() -> str:
@classmethod
def get_instance(
cls,
config_directory : Optional[str] = None
config_folder : Optional[str] = None
) -> 'FunctionConfigManager':
"""
Get the singleton instance of FunctionConfigManager.
:param config_directory: The directory containing the function specifications.
:type config_directory: str
:param config_folder: The directory containing the function specifications.
:type config_folder: str
:return: The singleton instance of FunctionConfigManager.
:rtype: FunctionConfigManager
"""
if cls._instance is None:
cls._instance = cls(config_directory)
cls._instance = cls(config_folder)
return cls._instance

def load_function_configs(self) -> None:
Original file line number Diff line number Diff line change
@@ -30,6 +30,9 @@ def setup_logger() -> logging.Logger:
logger = logging.getLogger('assistant_logger')
logger.setLevel(logging.INFO)

# Disable by default
logger.disabled = True

# Including function name in the log message format
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(funcName)s - %(message)s')

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

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

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

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

0 comments on commit b2f5d22

Please sign in to comment.