Skip to content

Commit

Permalink
remove threads config file writing by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jhakulin committed May 7, 2024
1 parent d9f6fba commit 3956a97
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sdk/azure-ai-assistant/azure/ai/assistant/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

VERSION = "0.3.4a1"
VERSION = "0.3.5a1"
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def load_configs(self) -> None:
try:
config_files = os.listdir(self._config_folder)
except FileNotFoundError:
logger.warning("No assistant configurations found in the config folder.")
logger.warning(f"No assistant configurations found in the folder '{self._config_folder}'")
return

loaded_assistants = set() # Track loaded assistant names to prevent duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,36 @@ class AsyncConversationThreadClient:
:param ai_client_type: The type of the AI client to use.
:type ai_client_type: AIClientType
:param config_folder: The folder to save the thread config to.
:type config_folder: str, optional
:param client_args: The arguments to pass to the AI client.
:type client_args: dict
"""
def __init_private(self, ai_client_type, **client_args):
def __init_private(
self,
ai_client_type,
config_folder : Optional[str] = None,
**client_args
):
self._ai_client_type = ai_client_type
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/threads.json')
self._thread_config = ConversationThreadConfig(self._ai_client_type, config_folder)
self._assistant_config_manager = AssistantConfigManager.get_instance()

@classmethod
def get_instance(
cls,
ai_client_type : AsyncAIClientType,
config_folder : Optional[str] = None,
**client_args
) -> 'AsyncConversationThreadClient':
"""
Get the singleton instance of the AsyncConversationThreadClient.
:param ai_client_type: The type of the AI client to use.
:type ai_client_type: AsyncAIClientType
:param config_folder: The folder to save the thread config to.
:type config_folder: str, optional
:param client_args: The arguments to pass to the AI client.
:type client_args: dict
Expand All @@ -56,7 +66,7 @@ def get_instance(
with cls._lock:
if ai_client_type not in cls._instances:
instance = cls.__new__(cls)
instance.__init_private(ai_client_type, **client_args)
instance.__init_private(ai_client_type, config_folder, **client_args)
cls._instances[ai_client_type] = instance
return cls._instances[ai_client_type]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,36 @@ class ConversationThreadClient:
:param ai_client_type: The type of the AI client to use.
:type ai_client_type: AIClientType
:param config_folder: The folder to save the thread config to.
:type config_folder: str, optional
:param client_args: The arguments to pass to the AI client.
:type client_args: dict
"""
def __init_private(self, ai_client_type, **client_args):
def __init_private(
self,
ai_client_type,
config_folder : Optional[str] = None,
**client_args
):
self._ai_client_type = ai_client_type
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/threads.json')
self._thread_config = ConversationThreadConfig(self._ai_client_type, config_folder)
self._assistant_config_manager = AssistantConfigManager.get_instance()

@classmethod
def get_instance(
cls,
ai_client_type : AIClientType,
config_folder : Optional[str] = None,
**client_args
) -> 'ConversationThreadClient':
"""
Get the singleton instance of the ConversationThreadClient.
:param ai_client_type: The type of the AI client to use.
:type ai_client_type: AIClientType
:param config_folder: The folder to save the thread config to.
:type config_folder: str, optional
:param client_args: The arguments to pass to the AI client.
:type client_args: dict
Expand All @@ -56,7 +66,7 @@ def get_instance(
with cls._lock:
if ai_client_type not in cls._instances:
instance = cls.__new__(cls)
instance.__init_private(ai_client_type, **client_args)
instance.__init_private(ai_client_type, config_folder, **client_args)
cls._instances[ai_client_type] = instance
return cls._instances[ai_client_type]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from azure.ai.assistant.management.logger_module import logger

import json, os
from typing import Optional


class ConversationThreadConfig:
Expand All @@ -18,11 +19,14 @@ class ConversationThreadConfig:
"""
def __init__(
self,
ai_client_type: AIClientType,
config_file
ai_client_type: AIClientType,
config_folder : Optional[str] = None,
) -> None:
self._ai_client_type = ai_client_type.name
self._config_file = config_file
if config_folder:
self._config_file = os.path.join(config_folder, 'threads.json')
else:
self._config_file = None
self._config_data = {}
self._current_thread_id = None
self._threads = []
Expand Down Expand Up @@ -185,6 +189,9 @@ def get_all_threads(self) -> list:
:rtype: list
"""
# create config file if it doesn't exist
if self._config_file is None:
return []

try:
with open(self._config_file, 'r') as f:
pass
Expand Down Expand Up @@ -310,6 +317,9 @@ def save_to_json(self) -> None:
"""
Save the configuration for the specific ai_client_type to a JSON file.
"""
if self._config_file is None:
return

# Ensure the directory exists
os.makedirs(os.path.dirname(self._config_file), exist_ok=True)

Expand Down

0 comments on commit 3956a97

Please sign in to comment.