25
25
26
26
# Utilities
27
27
import client .utils .api_call as api_call
28
+ import client .utils .st_common as st_common
28
29
from client .utils .st_footer import remove_footer
29
30
30
31
import common .logging_config as logging_config
@@ -47,6 +48,7 @@ def get_settings(include_sensitive: bool = False):
47
48
)
48
49
return settings
49
50
51
+
50
52
def save_settings (settings ):
51
53
"""Save Settings after changing client"""
52
54
@@ -61,12 +63,7 @@ def save_settings(settings):
61
63
62
64
def compare_settings (current , uploaded , path = "" ):
63
65
"""Compare current settings with uploaded settings."""
64
- differences = {
65
- "Value Mismatch" : {},
66
- "Missing in Uploaded" : {},
67
- "Missing in Current" : {},
68
- "Override on Upload" : {}
69
- }
66
+ differences = {"Value Mismatch" : {}, "Missing in Uploaded" : {}, "Missing in Current" : {}, "Override on Upload" : {}}
70
67
71
68
sensitive_keys = {"api_key" , "password" , "wallet_password" }
72
69
@@ -98,10 +95,7 @@ def compare_settings(current, uploaded, path=""):
98
95
# Both present — compare
99
96
if is_sensitive :
100
97
if current [key ] != uploaded [key ]:
101
- differences ["Value Mismatch" ][new_path ] = {
102
- "current" : current [key ],
103
- "uploaded" : uploaded [key ]
104
- }
98
+ differences ["Value Mismatch" ][new_path ] = {"current" : current [key ], "uploaded" : uploaded [key ]}
105
99
else :
106
100
child_diff = compare_settings (current [key ], uploaded [key ], new_path )
107
101
for diff_type , diff_dict in differences .items ():
@@ -123,10 +117,7 @@ def compare_settings(current, uploaded, path=""):
123
117
124
118
else :
125
119
if current != uploaded :
126
- differences ["Value Mismatch" ][path ] = {
127
- "current" : current ,
128
- "uploaded" : uploaded
129
- }
120
+ differences ["Value Mismatch" ][path ] = {"current" : current , "uploaded" : uploaded }
130
121
131
122
return differences
132
123
@@ -153,8 +144,8 @@ def spring_ai_conf_check(ll_model, embed_model) -> str:
153
144
if ll_model is None or embed_model is None :
154
145
return "hybrid"
155
146
156
- ll_api = state . ll_model_enabled [ ll_model ] ["api" ]
157
- embed_api = state . embed_model_enabled [ embed_model ] ["api" ]
147
+ ll_api = ll_model ["api" ]
148
+ embed_api = embed_model ["api" ]
158
149
159
150
if "OpenAI" in ll_api and "OpenAI" in embed_api :
160
151
return "openai"
@@ -163,7 +154,8 @@ def spring_ai_conf_check(ll_model, embed_model) -> str:
163
154
164
155
return "hybrid"
165
156
166
- def spring_ai_obaas (src_dir , file_name , provider , ll_model ):
157
+
158
+ def spring_ai_obaas (src_dir , file_name , provider , ll_config , embed_config ):
167
159
"""Get the users CTX Prompt"""
168
160
ctx_prompt = next (
169
161
item ["prompt" ]
@@ -174,12 +166,14 @@ def spring_ai_obaas(src_dir, file_name, provider, ll_model):
174
166
with open (src_dir / "templates" / file_name , "r" , encoding = "utf-8" ) as template :
175
167
template_content = template .read ()
176
168
169
+ database_lookup = st_common .state_configs_lookup ("database_configs" , "name" )
170
+
177
171
formatted_content = template_content .format (
178
172
provider = provider ,
179
173
ctx_prompt = f"{ ctx_prompt } " ,
180
- ll_model = state . client_settings [ "ll_model" ] | state . ll_model_enabled [ ll_model ] ,
181
- vector_search = state . client_settings [ "vector_search" ] ,
182
- database_config = state . database_config [state .client_settings ["database" ]["alias" ]],
174
+ ll_model = ll_config ,
175
+ vector_search = embed_config ,
176
+ database_config = database_lookup [state .client_settings ["database" ]["alias" ]],
183
177
)
184
178
185
179
if file_name .endswith (".yaml" ):
@@ -188,9 +182,9 @@ def spring_ai_obaas(src_dir, file_name, provider, ll_model):
188
182
formatted_content = template_content .format (
189
183
provider = provider ,
190
184
ctx_prompt = ctx_prompt ,
191
- ll_model = state . client_settings [ "ll_model" ] | state . ll_model_enabled [ ll_model ] ,
192
- vector_search = state . client_settings [ "vector_search" ] ,
193
- database_config = state . database_config [state .client_settings ["database" ]["alias" ]],
185
+ ll_model = ll_config ,
186
+ vector_search = embed_config ,
187
+ database_config = database_lookup [state .client_settings ["database" ]["alias" ]],
194
188
)
195
189
196
190
yaml_data = yaml .safe_load (formatted_content )
@@ -203,7 +197,7 @@ def spring_ai_obaas(src_dir, file_name, provider, ll_model):
203
197
return formatted_content
204
198
205
199
206
- def spring_ai_zip (provider , ll_model ):
200
+ def spring_ai_zip (provider , ll_config , embed_config ):
207
201
"""Create SpringAI Zip File"""
208
202
# Source directory that you want to copy
209
203
files = ["mvnw" , "mvnw.cmd" , "pom.xml" , "README.md" ]
@@ -227,8 +221,8 @@ def spring_ai_zip(provider, ll_model):
227
221
228
222
arc_name = os .path .relpath (file_path , dst_dir ) # Make the path relative
229
223
zip_file .write (file_path , arc_name )
230
- env_content = spring_ai_obaas (src_dir , "start.sh" , provider , ll_model )
231
- yaml_content = spring_ai_obaas (src_dir , "obaas.yaml" , provider , ll_model )
224
+ env_content = spring_ai_obaas (src_dir , "start.sh" , provider , ll_config , embed_config )
225
+ yaml_content = spring_ai_obaas (src_dir , "obaas.yaml" , provider , ll_config , embed_config )
232
226
zip_file .writestr ("start.sh" , env_content .encode ("utf-8" ))
233
227
zip_file .writestr ("src/main/resources/application-obaas.yml" , yaml_content .encode ("utf-8" ))
234
228
zip_buffer .seek (0 )
@@ -291,21 +285,25 @@ def main():
291
285
st .info ("Please upload a Settings file." )
292
286
293
287
st .header ("SpringAI Settings" , divider = "red" )
294
- ll_model = state .client_settings ["ll_model" ]["model" ]
295
- embed_model = state .client_settings ["vector_search" ]["model" ]
296
- spring_ai_conf = spring_ai_conf_check (ll_model , embed_model )
288
+ # Merge the User Settings into the Model Config
289
+ model_lookup = st_common .state_configs_lookup ("model_configs" , "id" )
290
+ ll_config = model_lookup [state .client_settings ["ll_model" ]["model" ]] | state .client_settings ["ll_model" ]
291
+ embed_config = (
292
+ model_lookup [state .client_settings ["vector_search" ]["model" ]] | state .client_settings ["vector_search" ]
293
+ )
294
+ spring_ai_conf = spring_ai_conf_check (ll_config , embed_config )
297
295
298
296
if spring_ai_conf == "hybrid" :
299
297
st .markdown (f"""
300
298
The current configuration combination of embedding and language models
301
299
is currently **not supported** for SpringAI.
302
- - Language Model: **{ ll_model } **
303
- - Embedding Model: **{ embed_model } **
300
+ - Language Model: **{ ll_config [ "model" ] } **
301
+ - Embedding Model: **{ embed_config [ "model" ] } **
304
302
""" )
305
303
else :
306
304
st .download_button (
307
305
label = "Download SpringAI" ,
308
- data = spring_ai_zip (spring_ai_conf , ll_model ), # Generate zip on the fly
306
+ data = spring_ai_zip (spring_ai_conf , ll_config , embed_config ), # Generate zip on the fly
309
307
file_name = "spring_ai.zip" , # Zip file name
310
308
mime = "application/zip" , # Mime type for zip file
311
309
disabled = spring_ai_conf == "hybrid" ,
0 commit comments