Update app.py
Browse files
app.py
CHANGED
|
@@ -160,70 +160,190 @@ Return:
|
|
| 160 |
"""
|
| 161 |
return call_llm(model, prompt)
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
# Gradio App
|
| 164 |
def main():
|
| 165 |
with gr.Blocks(title="Salesforce B2B Commerce Migration Assistant") as app:
|
| 166 |
gr.Markdown("# Salesforce B2B Commerce Migration Assistant")
|
| 167 |
gr.Markdown("This tool helps migrate CloudCraze code to B2B Lightning Experience.")
|
| 168 |
|
| 169 |
-
# Create
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
with gr.Tab("Apex Trigger Correction"):
|
| 177 |
gr.Markdown("### Apex Trigger Correction")
|
| 178 |
gr.Markdown("Paste your Apex Trigger code below:")
|
| 179 |
|
| 180 |
trigger_input = gr.Textbox(
|
| 181 |
-
lines=
|
| 182 |
placeholder="Paste Apex Trigger code here...",
|
| 183 |
label="Apex Trigger Code"
|
| 184 |
)
|
| 185 |
trigger_output = gr.Textbox(
|
| 186 |
-
lines=
|
| 187 |
label="Corrected Apex Trigger",
|
| 188 |
interactive=True
|
| 189 |
)
|
| 190 |
trigger_button = gr.Button("Correct Apex Trigger")
|
| 191 |
trigger_button.click(
|
| 192 |
fn=correct_apex_trigger,
|
| 193 |
-
inputs=[
|
| 194 |
outputs=trigger_output,
|
| 195 |
show_progress=True
|
| 196 |
)
|
| 197 |
-
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
with gr.Tab("CloudCraze Object Conversion"):
|
| 201 |
gr.Markdown("### CloudCraze Object Conversion")
|
| 202 |
gr.Markdown("Paste your CloudCraze Object code below:")
|
| 203 |
|
| 204 |
object_input = gr.Textbox(
|
| 205 |
-
lines=
|
| 206 |
placeholder="Paste CC object code here...",
|
| 207 |
label="CloudCraze Object Code"
|
| 208 |
)
|
| 209 |
object_output = gr.Textbox(
|
| 210 |
-
lines=
|
| 211 |
label="Converted B2B LEx Object",
|
| 212 |
interactive=True
|
| 213 |
)
|
| 214 |
object_button = gr.Button("Convert Object")
|
| 215 |
object_button.click(
|
| 216 |
fn=convert_cc_object,
|
| 217 |
-
inputs=[
|
| 218 |
outputs=object_output,
|
| 219 |
show_progress=True
|
| 220 |
)
|
| 221 |
-
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
gr.Markdown("### About This Tool")
|
| 225 |
gr.Markdown(
|
| 226 |
"""
|
|
|
|
|
|
|
| 227 |
- **Trigger Correction**: Fixes Apex Triggers for B2B LEx compatibility.
|
| 228 |
- **Object Conversion**: Maps and converts CloudCraze object definitions to B2B LEx.
|
| 229 |
- **Model Selection**: Choose from Together AI models or Anthropic's Claude models.
|
|
|
|
| 160 |
"""
|
| 161 |
return call_llm(model, prompt)
|
| 162 |
|
| 163 |
+
# Validation function for Apex Trigger correction
|
| 164 |
+
def validate_apex_trigger(validation_model, original_code, corrected_code):
|
| 165 |
+
if not validation_model or not original_code.strip() or not corrected_code.strip():
|
| 166 |
+
return "Please provide all required inputs for validation."
|
| 167 |
+
|
| 168 |
+
prompt = f"""
|
| 169 |
+
I need you to validate and review the following Apex Trigger code migration from CloudCraze to B2B Lightning Experience.
|
| 170 |
+
|
| 171 |
+
ORIGINAL CODE:
|
| 172 |
+
```apex
|
| 173 |
+
{original_code}
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
CORRECTED CODE:
|
| 177 |
+
```apex
|
| 178 |
+
{corrected_code}
|
| 179 |
+
```
|
| 180 |
+
|
| 181 |
+
Please review the corrected code and provide:
|
| 182 |
+
1. Is the correction accurate and complete? Highlight any missed issues.
|
| 183 |
+
2. Are there any potential runtime errors or performance concerns?
|
| 184 |
+
3. Does it follow Salesforce best practices for B2B Lightning Experience?
|
| 185 |
+
4. Would you recommend any additional improvements?
|
| 186 |
+
5. Rate the quality of the correction on a scale of 1-10 with explanation.
|
| 187 |
+
|
| 188 |
+
Be thorough and detailed in your assessment.
|
| 189 |
+
"""
|
| 190 |
+
return call_llm(validation_model, prompt)
|
| 191 |
+
|
| 192 |
+
# Validation function for object conversion
|
| 193 |
+
def validate_cc_object_conversion(validation_model, original_object, converted_object):
|
| 194 |
+
if not validation_model or not original_object.strip() or not converted_object.strip():
|
| 195 |
+
return "Please provide all required inputs for validation."
|
| 196 |
+
|
| 197 |
+
prompt = f"""
|
| 198 |
+
I need you to validate and review the following CloudCraze Object conversion to B2B Lightning Experience format.
|
| 199 |
+
|
| 200 |
+
ORIGINAL CLOUDCRAZE OBJECT:
|
| 201 |
+
```
|
| 202 |
+
{original_object}
|
| 203 |
+
```
|
| 204 |
+
|
| 205 |
+
CONVERTED B2B LEX OBJECT:
|
| 206 |
+
```
|
| 207 |
+
{converted_object}
|
| 208 |
+
```
|
| 209 |
+
|
| 210 |
+
Please review the conversion and provide:
|
| 211 |
+
1. Is the object mapping correct and complete? Identify any missed fields or relationships.
|
| 212 |
+
2. Are there any potential data migration issues or concerns?
|
| 213 |
+
3. Does the converted object follow B2B Lightning Experience best practices?
|
| 214 |
+
4. Would you recommend any additional improvements or optimizations?
|
| 215 |
+
5. Rate the quality of the conversion on a scale of 1-10 with explanation.
|
| 216 |
+
|
| 217 |
+
Be thorough and detailed in your assessment.
|
| 218 |
+
"""
|
| 219 |
+
return call_llm(validation_model, prompt)
|
| 220 |
+
|
| 221 |
# Gradio App
|
| 222 |
def main():
|
| 223 |
with gr.Blocks(title="Salesforce B2B Commerce Migration Assistant") as app:
|
| 224 |
gr.Markdown("# Salesforce B2B Commerce Migration Assistant")
|
| 225 |
gr.Markdown("This tool helps migrate CloudCraze code to B2B Lightning Experience.")
|
| 226 |
|
| 227 |
+
# Create model dropdowns
|
| 228 |
+
with gr.Row():
|
| 229 |
+
with gr.Column():
|
| 230 |
+
gr.Markdown("### Primary Model")
|
| 231 |
+
primary_model_dropdown = gr.Dropdown(
|
| 232 |
+
choices=all_models,
|
| 233 |
+
value=anthropic_models[0], # Default to Claude 3.7 Sonnet
|
| 234 |
+
label="Select Primary AI Model for Conversion"
|
| 235 |
+
)
|
| 236 |
+
|
| 237 |
+
with gr.Column():
|
| 238 |
+
gr.Markdown("### Validation Model")
|
| 239 |
+
validation_model_dropdown = gr.Dropdown(
|
| 240 |
+
choices=all_models,
|
| 241 |
+
value=anthropic_models[1], # Default to Claude 3 Haiku
|
| 242 |
+
label="Select Validation AI Model for Review",
|
| 243 |
+
info="This model will validate and review the output from the primary model"
|
| 244 |
+
)
|
| 245 |
|
| 246 |
with gr.Tab("Apex Trigger Correction"):
|
| 247 |
gr.Markdown("### Apex Trigger Correction")
|
| 248 |
gr.Markdown("Paste your Apex Trigger code below:")
|
| 249 |
|
| 250 |
trigger_input = gr.Textbox(
|
| 251 |
+
lines=12,
|
| 252 |
placeholder="Paste Apex Trigger code here...",
|
| 253 |
label="Apex Trigger Code"
|
| 254 |
)
|
| 255 |
trigger_output = gr.Textbox(
|
| 256 |
+
lines=15,
|
| 257 |
label="Corrected Apex Trigger",
|
| 258 |
interactive=True
|
| 259 |
)
|
| 260 |
trigger_button = gr.Button("Correct Apex Trigger")
|
| 261 |
trigger_button.click(
|
| 262 |
fn=correct_apex_trigger,
|
| 263 |
+
inputs=[primary_model_dropdown, trigger_input],
|
| 264 |
outputs=trigger_output,
|
| 265 |
show_progress=True
|
| 266 |
)
|
| 267 |
+
|
| 268 |
+
gr.Markdown("### Validation Results")
|
| 269 |
+
trigger_validation_output = gr.Textbox(
|
| 270 |
+
lines=15,
|
| 271 |
+
label="Validation Assessment",
|
| 272 |
+
placeholder="Validation results will appear here after clicking 'Validate Correction'",
|
| 273 |
+
interactive=True
|
| 274 |
+
)
|
| 275 |
+
validate_trigger_button = gr.Button("Validate Correction")
|
| 276 |
+
validate_trigger_button.click(
|
| 277 |
+
fn=validate_apex_trigger,
|
| 278 |
+
inputs=[validation_model_dropdown, trigger_input, trigger_output],
|
| 279 |
+
outputs=trigger_validation_output,
|
| 280 |
+
show_progress=True
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
+
with gr.Row():
|
| 284 |
+
trigger_clear = gr.Button("Clear Input")
|
| 285 |
+
trigger_clear.click(lambda: "", [], trigger_input)
|
| 286 |
+
|
| 287 |
+
results_clear = gr.Button("Clear Results")
|
| 288 |
+
results_clear.click(
|
| 289 |
+
lambda: ["", ""],
|
| 290 |
+
[],
|
| 291 |
+
[trigger_output, trigger_validation_output]
|
| 292 |
+
)
|
| 293 |
|
| 294 |
with gr.Tab("CloudCraze Object Conversion"):
|
| 295 |
gr.Markdown("### CloudCraze Object Conversion")
|
| 296 |
gr.Markdown("Paste your CloudCraze Object code below:")
|
| 297 |
|
| 298 |
object_input = gr.Textbox(
|
| 299 |
+
lines=12,
|
| 300 |
placeholder="Paste CC object code here...",
|
| 301 |
label="CloudCraze Object Code"
|
| 302 |
)
|
| 303 |
object_output = gr.Textbox(
|
| 304 |
+
lines=15,
|
| 305 |
label="Converted B2B LEx Object",
|
| 306 |
interactive=True
|
| 307 |
)
|
| 308 |
object_button = gr.Button("Convert Object")
|
| 309 |
object_button.click(
|
| 310 |
fn=convert_cc_object,
|
| 311 |
+
inputs=[primary_model_dropdown, object_input],
|
| 312 |
outputs=object_output,
|
| 313 |
show_progress=True
|
| 314 |
)
|
| 315 |
+
|
| 316 |
+
gr.Markdown("### Validation Results")
|
| 317 |
+
object_validation_output = gr.Textbox(
|
| 318 |
+
lines=15,
|
| 319 |
+
label="Validation Assessment",
|
| 320 |
+
placeholder="Validation results will appear here after clicking 'Validate Conversion'",
|
| 321 |
+
interactive=True
|
| 322 |
+
)
|
| 323 |
+
validate_object_button = gr.Button("Validate Conversion")
|
| 324 |
+
validate_object_button.click(
|
| 325 |
+
fn=validate_cc_object_conversion,
|
| 326 |
+
inputs=[validation_model_dropdown, object_input, object_output],
|
| 327 |
+
outputs=object_validation_output,
|
| 328 |
+
show_progress=True
|
| 329 |
+
)
|
| 330 |
+
|
| 331 |
+
with gr.Row():
|
| 332 |
+
object_clear = gr.Button("Clear Input")
|
| 333 |
+
object_clear.click(lambda: "", [], object_input)
|
| 334 |
+
|
| 335 |
+
object_results_clear = gr.Button("Clear Results")
|
| 336 |
+
object_results_clear.click(
|
| 337 |
+
lambda: ["", ""],
|
| 338 |
+
[],
|
| 339 |
+
[object_output, object_validation_output]
|
| 340 |
+
)
|
| 341 |
|
| 342 |
gr.Markdown("### About This Tool")
|
| 343 |
gr.Markdown(
|
| 344 |
"""
|
| 345 |
+
- **Primary Model**: Performs the initial code conversion or correction.
|
| 346 |
+
- **Validation Model**: Reviews and validates the output from the primary model, identifying potential issues or improvements.
|
| 347 |
- **Trigger Correction**: Fixes Apex Triggers for B2B LEx compatibility.
|
| 348 |
- **Object Conversion**: Maps and converts CloudCraze object definitions to B2B LEx.
|
| 349 |
- **Model Selection**: Choose from Together AI models or Anthropic's Claude models.
|