maitai-python 1.1.14__tar.gz → 1.1.15__tar.gz
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.
- {maitai_python-1.1.14 → maitai_python-1.1.15}/PKG-INFO +1 -1
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai/_config.py +42 -8
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_common/version.py +1 -1
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_python.egg-info/PKG-INFO +1 -1
- {maitai_python-1.1.14 → maitai_python-1.1.15}/README.md +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai/_azure.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai/_config_listener_thread.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai/_context.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai/_evaluator.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai/_inference.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai/_maitai.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai/_maitai_async.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai/_maitai_client.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai/_types.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai/_utils.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai/tools/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_common/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_common/config/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_common/config/config_service.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_common/processes/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_common/processes/io_thread.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_common/processes/websocket_listener_thread.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_common/utils/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_common/utils/proto_utils.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_common/utils/types.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/application/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/backtest/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/chat/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/company/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/config/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/embedding/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/event/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/inference/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/key/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/metric/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/model/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/notification/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/sandbox/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/sentinel/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_gen/session/__init__.py +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_python.egg-info/SOURCES.txt +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_python.egg-info/dependency_links.txt +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_python.egg-info/requires.txt +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_python.egg-info/top_level.txt +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/setup.cfg +0 -0
- {maitai_python-1.1.14 → maitai_python-1.1.15}/setup.py +0 -0
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import json
|
|
1
2
|
import os
|
|
3
|
+
import threading
|
|
2
4
|
from typing import List
|
|
3
5
|
|
|
4
6
|
import requests
|
|
7
|
+
from betterproto import Casing
|
|
5
8
|
from requests.adapters import HTTPAdapter
|
|
6
9
|
from urllib3 import Retry
|
|
7
10
|
|
|
@@ -57,14 +60,25 @@ class Config:
|
|
|
57
60
|
def api_key(self, value):
|
|
58
61
|
self._api_key = value
|
|
59
62
|
|
|
60
|
-
def initialize(self, api_key):
|
|
63
|
+
def initialize(self, api_key, retry=0):
|
|
61
64
|
if self.initialized and self.api_key == api_key:
|
|
62
65
|
return
|
|
63
66
|
self.api_key = api_key
|
|
64
67
|
self.initialized = True
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
try:
|
|
69
|
+
self._initialize_company()
|
|
70
|
+
self.refresh_applications()
|
|
71
|
+
self._initialize_websocket()
|
|
72
|
+
except Exception as e:
|
|
73
|
+
try:
|
|
74
|
+
self._load_config_from_file()
|
|
75
|
+
except Exception:
|
|
76
|
+
raise e
|
|
77
|
+
self.initialized = False
|
|
78
|
+
if retry < 5:
|
|
79
|
+
t = threading.Timer(interval=2 ** retry, function=self.initialize, args=(api_key, retry))
|
|
80
|
+
t.daemon = True
|
|
81
|
+
t.start()
|
|
68
82
|
|
|
69
83
|
def get_application(self, application_ref_name: str) -> Application:
|
|
70
84
|
return self._applications.get(application_ref_name)
|
|
@@ -84,8 +98,7 @@ class Config:
|
|
|
84
98
|
response = self._session.get(url, headers=headers, timeout=15)
|
|
85
99
|
self._session.close()
|
|
86
100
|
if response.status_code != 200:
|
|
87
|
-
|
|
88
|
-
return
|
|
101
|
+
raise Exception(f"Failed to initialize Maitai client: {response.text}")
|
|
89
102
|
|
|
90
103
|
self._company_id = response.json().get("id")
|
|
91
104
|
|
|
@@ -101,8 +114,7 @@ class Config:
|
|
|
101
114
|
response = self._session.get(url, headers=headers, timeout=15)
|
|
102
115
|
self._session.close()
|
|
103
116
|
if response.status_code != 200:
|
|
104
|
-
|
|
105
|
-
return
|
|
117
|
+
raise Exception(f"Failed to initialize Maitai client: {response.text}")
|
|
106
118
|
applications = [Application().from_dict(app_json) for app_json in response.json()]
|
|
107
119
|
return self.store_application_metadata(applications)
|
|
108
120
|
|
|
@@ -113,6 +125,28 @@ class Config:
|
|
|
113
125
|
if application.application_ref_name not in self._application_action_configs:
|
|
114
126
|
self._application_action_configs[application.application_ref_name] = {}
|
|
115
127
|
self._application_action_configs[application.application_ref_name][action_type.action_type] = action_type.meta
|
|
128
|
+
self._dump_application_metadata()
|
|
129
|
+
|
|
130
|
+
def _dump_application_metadata(self):
|
|
131
|
+
filename = os.path.expanduser("~/.maitai/config.json")
|
|
132
|
+
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
|
133
|
+
with open(filename, "w") as f:
|
|
134
|
+
config_object = {}
|
|
135
|
+
for ref_name, intent_map in self._application_action_configs.items():
|
|
136
|
+
config_object[ref_name] = {}
|
|
137
|
+
for intent_name, intent_config in intent_map.items():
|
|
138
|
+
config_object[ref_name][intent_name] = intent_config.to_pydict(casing=Casing.SNAKE, include_default_values=False)
|
|
139
|
+
f.write(json.dumps(config_object, indent=2))
|
|
140
|
+
|
|
141
|
+
def _load_config_from_file(self):
|
|
142
|
+
filename = os.path.expanduser("~/.maitai/config.json")
|
|
143
|
+
with open(filename, "r") as f:
|
|
144
|
+
config_object = json.load(f)
|
|
145
|
+
for ref_name, intent_map in config_object.items():
|
|
146
|
+
if ref_name not in self._application_action_configs:
|
|
147
|
+
self._application_action_configs[ref_name] = {}
|
|
148
|
+
for intent_name, intent_config in intent_map.items():
|
|
149
|
+
self._application_action_configs[ref_name][intent_name] = ActionConfig().from_pydict(intent_config)
|
|
116
150
|
|
|
117
151
|
def _initialize_websocket(self):
|
|
118
152
|
self.config_listener_thread = ConfigListenerThread(self, self.maitai_ws, "APPLICATION_CONFIG_CHANGE", self._company_id)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{maitai_python-1.1.14 → maitai_python-1.1.15}/maitai_common/processes/websocket_listener_thread.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|