Skip to content

Commit 2597498

Browse files
tkiliasckunki
andauthored
Apply suggestions from code review
Co-authored-by: Christoph Kuhnke <[email protected]>
1 parent acd1a0b commit 2597498

File tree

1 file changed

+42
-33
lines changed

1 file changed

+42
-33
lines changed

exasol/nb_connector/text_ai_extension_wrapper.py

+42-33
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,37 @@
1212
from exasol.nb_connector.secret_store import Secrets
1313
from exasol.nb_connector.ai_lab_config import AILabConfig as CKey
1414

15-
# Models will be uploaded into this directory in BucketFS.
15+
# Models will be uploaded into directory BFS_MODELS_DIR in BucketFS.
16+
#
1617
# Models downloaded from the Huggingface archive to a local drive will be
17-
# cached in this directory.
18-
# we use the same dirs as in initialize_te_extension, because both extensions use
19-
# Huggingface Models and splitting them is confusing. So we reuse the TE directories to be also backwards compatible.
18+
# cached in directory MODELS_CACHE_DIR.
19+
#
20+
# TXAIE uses the same directories as TE (see function initialize_te_extension)
21+
# as both extensions are using Huggingface Models. This also avoids confusion,
22+
# and ensures backwards compatibility.
2023
from exasol.nb_connector.transformers_extension_wrapper import BFS_MODELS_DIR, MODELS_CACHE_DIR
2124

2225

23-
# Root directory in a BucketFS bucket where all stuff of the Text AI
24-
# Extension, including its language container, will be uploaded.
2526
PATH_IN_BUCKET = "TXAIE"
27+
""" Location in BucketFS bucket to upload data for TXAIE, e.g. its language container. """
2628

2729
LANGUAGE_ALIAS = "PYTHON3_TXAIE"
2830

2931
LATEST_KNOWN_VERSION = "???"
3032

31-
# Activation SQL for the Text AI Extension will be saved in the secret
32-
# store with this key.
3333
ACTIVATION_KEY = ACTIVATION_KEY_PREFIX + "txaie"
34+
"""
35+
Activation SQL for the Text AI Extension will be saved in the secret store
36+
with this key.
37+
38+
TXAIE brings its own Script Language Container (SLC) which needs to be
39+
activated by a dedicated SQL statement `ALTER SESSION SET SCRIPT_LANGUAGES`. Applications
40+
can store the language definition in the configuration store (SCS) from the Notebook
41+
Connector's class `exasol.nb_connector.secret_store.Secrets`.
42+
43+
Using `ACTIVATION_KEY` as defined key, TXAIE can provide convenient interfaces
44+
accepting only the SCS and retrieving all further data from the there.
45+
"""
3446

3547
# The name of the connection object with BucketFS location and credentials
3648
# will be prefixed with this string.
@@ -159,36 +171,35 @@ def initialize_text_ai_extension(conf: Secrets,
159171
container_name = "exasol_text_ai_extension_container_release.tar.gz"
160172

161173

174+
def from_ai_lab_config(key: AILabConfig) -> Path | None:
175+
entry = conf.get(key)
176+
return Path(entry) if entry else None
177+
162178
if run_deploy_container:
163179
if version:
164-
install_txaie_version(version)
180+
install_text_ai_extension(version)
181+
# Can run_upload_models, run_deploy_scripts,
182+
# run_encapsulate_bfs_credentials, etc. be ignored here?
165183
return
184+
185+
container_file = container_file or from_ai_lab_config(CKey.txaie_slc_file_local_path)
166186
if not container_file:
167-
# if container_file and version are not set,
168-
# use txaie_slc_file_local_path for installing the slc, if it exists
169-
try:
170-
container_file_str = str(conf.get(CKey.txaie_slc_file_local_path))
171-
container_file = Path(container_file_str)
172-
finally:
173-
pass
174-
175-
if container_file:
176-
deploy_language_container(conf=conf,
177-
path_in_bucket=PATH_IN_BUCKET,
178-
language_alias=language_alias,
179-
activation_key=ACTIVATION_KEY,
180-
container_file=container_file,
181-
container_name=container_name,
182-
allow_override=allow_override,
183-
)
184-
else:
185-
version = LATEST_KNOWN_VERSION
186-
install_txaie_version(version)
187+
install_text_ai_extension(LATEST_KNOWN_VERSION)
188+
else
189+
deploy_language_container(
190+
conf=conf,
191+
path_in_bucket=PATH_IN_BUCKET,
192+
language_alias=language_alias,
193+
activation_key=ACTIVATION_KEY,
194+
container_file=container_file,
195+
container_name=container_name,
196+
allow_override=allow_override,
197+
)
187198

188199

189200

190201
if run_upload_models:
191-
# Install default transformers models into the Bucketfs using
202+
# Install default Hugging Face models into the Bucketfs using
192203
# Transformers Extensions upload model functionality.
193204
raise NotImplementedError('Implementation is waiting for TE release.')
194205

@@ -202,10 +213,8 @@ def initialize_text_ai_extension(conf: Secrets,
202213
conf, path_in_bucket=PATH_IN_BUCKET, connection_name=bfs_conn_name
203214
)
204215

205-
# Save the connection object names in the secret store.
216+
# Update secret store
206217
conf.save(CKey.txaie_bfs_connection, bfs_conn_name)
207-
208-
# Save the directory names in the secret store
209218
conf.save(CKey.txaie_models_bfs_dir, BFS_MODELS_DIR)
210219
conf.save(CKey.txaie_models_cache_dir, MODELS_CACHE_DIR)
211220

0 commit comments

Comments
 (0)