Spaces:
Runtime error
Runtime error
ICAS03 commited on
Commit ·
8e9804e
1
Parent(s): c22dff8
- fix generation_results
Browse files- Project.py +216 -76
- app.py +42 -23
- event_handler.py +86 -43
- prompt_configs.py +1 -0
- sample_permutations.py +8 -15
- state.py +1 -0
Project.py
CHANGED
|
@@ -7,6 +7,7 @@ from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
|
|
| 7 |
import openai
|
| 8 |
from contextlib import contextmanager
|
| 9 |
import json
|
|
|
|
| 10 |
from state import state
|
| 11 |
import re
|
| 12 |
from typing import Tuple
|
|
@@ -218,82 +219,221 @@ class Project:
|
|
| 218 |
##########################################################
|
| 219 |
## Generate PRD and components from project details ##
|
| 220 |
def generate_prd_and_components(self, progress=gr.Progress()):
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
|
| 299 |
|
|
|
|
| 7 |
import openai
|
| 8 |
from contextlib import contextmanager
|
| 9 |
import json
|
| 10 |
+
from sample_permutations import *
|
| 11 |
from state import state
|
| 12 |
import re
|
| 13 |
from typing import Tuple
|
|
|
|
| 219 |
##########################################################
|
| 220 |
## Generate PRD and components from project details ##
|
| 221 |
def generate_prd_and_components(self, progress=gr.Progress()):
|
| 222 |
+
"""Generate PRD and components from project details, streaming results"""
|
| 223 |
+
results = [] # Use a list instead of a set to maintain order
|
| 224 |
+
|
| 225 |
+
# Generate PRD
|
| 226 |
+
yield "Generating PRD...", results
|
| 227 |
+
prd_response = self.execute_prompt(
|
| 228 |
+
"generate_prd",
|
| 229 |
+
{
|
| 230 |
+
"project_detail": self.get_project_detail()
|
| 231 |
+
}
|
| 232 |
+
)
|
| 233 |
+
|
| 234 |
+
# Parse and format the PRD response
|
| 235 |
+
try:
|
| 236 |
+
# Handle PRD response
|
| 237 |
+
if isinstance(prd_response, str):
|
| 238 |
+
if "```json" in prd_response:
|
| 239 |
+
prd_response = prd_response.split("```json")[1].split("```")[0].strip()
|
| 240 |
+
elif "```" in prd_response:
|
| 241 |
+
prd_response = prd_response.split("```")[1].split("```")[0].strip()
|
| 242 |
+
prd_json = json.loads(prd_response)
|
| 243 |
+
else:
|
| 244 |
+
prd_json = prd_response
|
| 245 |
+
|
| 246 |
+
# Extract PRD content
|
| 247 |
+
if isinstance(prd_json, dict):
|
| 248 |
+
if "detailed_breakdown" in prd_json:
|
| 249 |
+
self.generated_prd = prd_json["detailed_breakdown"]
|
| 250 |
+
formatted_prd = {
|
| 251 |
+
"function_name": "generate_prd",
|
| 252 |
+
"result": {
|
| 253 |
+
"detailed_breakdown": prd_json["detailed_breakdown"],
|
| 254 |
+
"summary": prd_json.get("summary", "")
|
| 255 |
+
}
|
| 256 |
+
}
|
| 257 |
+
else:
|
| 258 |
+
self.generated_prd = prd_json
|
| 259 |
+
formatted_prd = {
|
| 260 |
+
"function_name": "generate_prd",
|
| 261 |
+
"result": prd_json
|
| 262 |
+
}
|
| 263 |
+
else:
|
| 264 |
+
self.generated_prd = str(prd_json)
|
| 265 |
+
formatted_prd = {
|
| 266 |
+
"function_name": "generate_prd",
|
| 267 |
+
"result": str(prd_json)
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
# Add formatted PRD to results
|
| 271 |
+
results.append(formatted_prd)
|
| 272 |
+
yield "PRD generation complete", results
|
| 273 |
+
|
| 274 |
+
except json.JSONDecodeError as e:
|
| 275 |
+
print(f"Warning: Could not parse PRD as JSON: {str(e)}")
|
| 276 |
+
self.generated_prd = prd_response
|
| 277 |
+
results.append({
|
| 278 |
+
"function_name": "generate_prd",
|
| 279 |
+
"result": prd_response
|
| 280 |
+
})
|
| 281 |
+
yield "PRD generation complete (raw format)", results
|
| 282 |
+
|
| 283 |
+
try:
|
| 284 |
+
yield "Analyzing configuration with component agent...", results
|
| 285 |
+
configuration_output = self.execute_prompt(
|
| 286 |
+
"component_agent",
|
| 287 |
+
{
|
| 288 |
+
"generated_prd": self.generated_prd
|
| 289 |
+
}
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
# Parse and format configuration output
|
| 293 |
+
try:
|
| 294 |
+
if isinstance(configuration_output, str):
|
| 295 |
+
if "```json" in configuration_output:
|
| 296 |
+
configuration_output = configuration_output.split("```json")[1].split("```")[0].strip()
|
| 297 |
+
elif "```" in configuration_output:
|
| 298 |
+
configuration_output = configuration_output.split("```")[1].split("```")[0].strip()
|
| 299 |
+
config = json.loads(configuration_output)
|
| 300 |
+
else:
|
| 301 |
+
config = configuration_output
|
| 302 |
+
|
| 303 |
+
# Store config for later use
|
| 304 |
+
self.config = config
|
| 305 |
+
|
| 306 |
+
formatted_config = {
|
| 307 |
+
"function_name": "component_agent",
|
| 308 |
+
"result": json.dumps(config, indent=2)
|
| 309 |
+
}
|
| 310 |
+
results.append(formatted_config)
|
| 311 |
+
|
| 312 |
+
selected_functions = config[0]["selected_functions"]
|
| 313 |
+
yield f"Selected {len(selected_functions)} components to generate", results
|
| 314 |
+
|
| 315 |
+
except (json.JSONDecodeError, KeyError, IndexError) as e:
|
| 316 |
+
yield f"Warning: Could not parse configuration output ({str(e)})", results
|
| 317 |
+
return
|
| 318 |
+
|
| 319 |
+
except Exception as e:
|
| 320 |
+
yield f"Error in analyzing configuration: {str(e)}", results
|
| 321 |
+
return
|
| 322 |
+
|
| 323 |
+
# Execute each function and stream results
|
| 324 |
+
for i, function_name in enumerate(selected_functions, 1):
|
| 325 |
+
try:
|
| 326 |
+
yield f"Generating component {i}/{len(selected_functions)}: {function_name}...", results
|
| 327 |
+
result = self.execute_prompt(function_name)
|
| 328 |
+
|
| 329 |
+
# Format the component result
|
| 330 |
+
try:
|
| 331 |
+
if isinstance(result, str):
|
| 332 |
+
if "```json" in result:
|
| 333 |
+
result = result.split("```json")[1].split("```")[0].strip()
|
| 334 |
+
elif "```" in result:
|
| 335 |
+
result = result.split("```")[1].split("```")[0].strip()
|
| 336 |
+
try:
|
| 337 |
+
# Try to parse as JSON
|
| 338 |
+
parsed_result = json.loads(result)
|
| 339 |
+
formatted_result = {
|
| 340 |
+
"function_name": function_name,
|
| 341 |
+
"result": json.dumps(parsed_result, indent=2)
|
| 342 |
+
}
|
| 343 |
+
except json.JSONDecodeError:
|
| 344 |
+
# If not JSON, use raw string
|
| 345 |
+
formatted_result = {
|
| 346 |
+
"function_name": function_name,
|
| 347 |
+
"result": result
|
| 348 |
+
}
|
| 349 |
+
else:
|
| 350 |
+
formatted_result = {
|
| 351 |
+
"function_name": function_name,
|
| 352 |
+
"result": json.dumps(result, indent=2) if isinstance(result, (dict, list)) else str(result)
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
results.append(formatted_result)
|
| 356 |
+
yield f"Successfully generated {function_name}", results
|
| 357 |
+
|
| 358 |
+
except Exception as e:
|
| 359 |
+
print(f"Warning: Error formatting result for {function_name}: {str(e)}")
|
| 360 |
+
results.append({
|
| 361 |
+
"function_name": function_name,
|
| 362 |
+
"result": str(result)
|
| 363 |
+
})
|
| 364 |
+
yield f"Generated {function_name} (raw format)", results
|
| 365 |
+
|
| 366 |
+
except Exception as e:
|
| 367 |
+
yield f"Error executing {function_name}: {str(e)}", results
|
| 368 |
+
continue
|
| 369 |
+
|
| 370 |
+
yield "All components generated successfully!", results
|
| 371 |
+
|
| 372 |
+
def generate_mandays_estimate(self, progress=gr.Progress()):
|
| 373 |
+
"""Generate mandays estimation based on configuration type and selected functions, streaming results"""
|
| 374 |
+
results = [] # Use a list instead of a set to maintain order
|
| 375 |
+
|
| 376 |
+
try:
|
| 377 |
+
# Check if the configuration is already available
|
| 378 |
+
if not hasattr(self, 'config'):
|
| 379 |
+
yield "Configuration not found. Please run 'generate_prd_and_components' first.", results
|
| 380 |
+
return
|
| 381 |
+
|
| 382 |
+
# Use the pre-parsed configuration
|
| 383 |
+
config = self.config
|
| 384 |
+
configuration_type = config[0]["configuration_type"]
|
| 385 |
+
yield f"Configuration type detected: {configuration_type}", results
|
| 386 |
+
|
| 387 |
+
# Map the configuration type to the enum
|
| 388 |
+
try:
|
| 389 |
+
config_type_enum = ConfigurationType(configuration_type)
|
| 390 |
+
except ValueError:
|
| 391 |
+
yield f"Unsupported configuration type: {configuration_type}", results
|
| 392 |
+
return
|
| 393 |
+
|
| 394 |
+
# Get the functions to execute based on the configuration type
|
| 395 |
+
selected_functions = CONFIGURATION_TYPE_FUNCTIONS.get(config_type_enum, [])
|
| 396 |
+
yield f"Selected functions: {', '.join(selected_functions)}", results
|
| 397 |
+
|
| 398 |
+
# Execute each function with its required inputs
|
| 399 |
+
for function_name in selected_functions:
|
| 400 |
+
try:
|
| 401 |
+
yield f"Executing function: {function_name}...", results
|
| 402 |
+
|
| 403 |
+
# Get the required inputs for the function from PROMPTS
|
| 404 |
+
if function_name not in PROMPTS:
|
| 405 |
+
yield f"Error: Function {function_name} not found in PROMPTS.", results
|
| 406 |
+
continue
|
| 407 |
+
|
| 408 |
+
prompt_config = PROMPTS[function_name]
|
| 409 |
+
input_variables = {}
|
| 410 |
+
|
| 411 |
+
# Populate input variables using INPUT_MAPPINGS
|
| 412 |
+
for input_name in prompt_config.inputs:
|
| 413 |
+
if input_name not in self.INPUT_MAPPINGS:
|
| 414 |
+
yield f"Error: No mapping defined for required input '{input_name}' in function {function_name}.", results
|
| 415 |
+
continue
|
| 416 |
+
|
| 417 |
+
try:
|
| 418 |
+
input_variables[input_name] = self.INPUT_MAPPINGS[input_name](self)
|
| 419 |
+
except Exception as e:
|
| 420 |
+
yield f"Error retrieving input '{input_name}' for function {function_name}: {str(e)}", results
|
| 421 |
+
continue
|
| 422 |
+
|
| 423 |
+
# Execute the function with the populated input variables
|
| 424 |
+
result = self.execute_prompt(function_name, input_variables)
|
| 425 |
+
results.append((function_name, result))
|
| 426 |
+
yield f"Successfully executed {function_name}", results
|
| 427 |
+
|
| 428 |
+
except Exception as e:
|
| 429 |
+
yield f"Error executing {function_name}: {str(e)}", results
|
| 430 |
+
continue
|
| 431 |
+
|
| 432 |
+
yield "Mandays estimation complete!", results
|
| 433 |
+
|
| 434 |
+
except Exception as e:
|
| 435 |
+
yield f"Error in generate_mandays_estimate: {str(e)}", results
|
| 436 |
+
|
| 437 |
|
| 438 |
|
| 439 |
|
app.py
CHANGED
|
@@ -168,7 +168,7 @@ def create_quotation_generator_section():
|
|
| 168 |
page_notes_box = None
|
| 169 |
page_save_quotation_btn = None
|
| 170 |
project_name = None
|
| 171 |
-
generation_results = gr.State(
|
| 172 |
|
| 173 |
with gr.Tab(label="Quotation Generator"):
|
| 174 |
with gr.Row():
|
|
@@ -189,41 +189,60 @@ def create_quotation_generator_section():
|
|
| 189 |
with gr.Column(scale=4):
|
| 190 |
# Organize steps and their outputs
|
| 191 |
step_outputs = {}
|
|
|
|
|
|
|
| 192 |
for prompt_key, prompt_config in PROMPTS.items():
|
| 193 |
if prompt_config.step == "Chatbot Prompt Editors":
|
| 194 |
continue
|
| 195 |
|
| 196 |
step = prompt_config.step
|
| 197 |
sub_step = prompt_config.sub_step
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
if sub_step
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
step_outputs[step]["main"].append(prompt_key)
|
| 211 |
|
| 212 |
all_components = {}
|
| 213 |
step_buttons = {}
|
| 214 |
|
| 215 |
# Create main step accordions
|
| 216 |
-
for step_name,
|
| 217 |
with gr.Accordion(step_name, open=False):
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
-
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
# Create the render function for this specific step
|
| 229 |
create_render_results(step_name, generation_results)
|
|
|
|
| 168 |
page_notes_box = None
|
| 169 |
page_save_quotation_btn = None
|
| 170 |
project_name = None
|
| 171 |
+
generation_results = gr.State({})
|
| 172 |
|
| 173 |
with gr.Tab(label="Quotation Generator"):
|
| 174 |
with gr.Row():
|
|
|
|
| 189 |
with gr.Column(scale=4):
|
| 190 |
# Organize steps and their outputs
|
| 191 |
step_outputs = {}
|
| 192 |
+
sub_steps = {}
|
| 193 |
+
|
| 194 |
for prompt_key, prompt_config in PROMPTS.items():
|
| 195 |
if prompt_config.step == "Chatbot Prompt Editors":
|
| 196 |
continue
|
| 197 |
|
| 198 |
step = prompt_config.step
|
| 199 |
sub_step = prompt_config.sub_step
|
| 200 |
+
if step and step.strip():
|
| 201 |
+
if step not in step_outputs:
|
| 202 |
+
step_outputs[step] = []
|
| 203 |
+
step_outputs[step].append(prompt_key)
|
| 204 |
+
|
| 205 |
+
# Track sub-steps if they exist
|
| 206 |
+
if sub_step:
|
| 207 |
+
if step not in sub_steps:
|
| 208 |
+
sub_steps[step] = {}
|
| 209 |
+
if sub_step not in sub_steps[step]:
|
| 210 |
+
sub_steps[step][sub_step] = []
|
| 211 |
+
sub_steps[step][sub_step].append(prompt_key)
|
|
|
|
| 212 |
|
| 213 |
all_components = {}
|
| 214 |
step_buttons = {}
|
| 215 |
|
| 216 |
# Create main step accordions
|
| 217 |
+
for step_name, prompt_keys in step_outputs.items():
|
| 218 |
with gr.Accordion(step_name, open=False):
|
| 219 |
+
if "Step 2" in step_name:
|
| 220 |
+
with gr.Row():
|
| 221 |
+
with gr.Column(scale=4):
|
| 222 |
+
# Check if this step has sub-steps
|
| 223 |
+
if step_name in sub_steps:
|
| 224 |
+
# Iterate through sub-steps for this step
|
| 225 |
+
for sub_step_name, prompt_keys_list in sub_steps[step_name].items():
|
| 226 |
+
# Create button for this sub-step
|
| 227 |
+
button_label = sub_step_name.split(' : ')[1] if ' : ' in sub_step_name else sub_step_name
|
| 228 |
+
step_buttons[sub_step_name] = gr.Button(f"✅ {button_label}")
|
| 229 |
+
|
| 230 |
+
with gr.Column(scale=1):
|
| 231 |
+
quotation_cost = gr.Textbox(label="Cost Summary", lines=3, interactive=False)
|
| 232 |
+
page_recalc_btn = gr.Button("Recalculate")
|
| 233 |
+
print(f"recalc_btn created: {page_recalc_btn}")
|
| 234 |
+
|
| 235 |
+
page_notes_box = gr.Textbox(
|
| 236 |
+
label="Notes",
|
| 237 |
+
lines=3,
|
| 238 |
+
placeholder="Add your notes here..."
|
| 239 |
+
)
|
| 240 |
+
page_save_quotation_btn = gr.Button("Save Quotation with Note")
|
| 241 |
|
| 242 |
+
else:
|
| 243 |
+
# Regular step button for non-Step 2
|
| 244 |
+
button_label = step_name.split(' : ')[1] if ' : ' in step_name else step_name
|
| 245 |
+
step_buttons[step_name] = gr.Button(f"✅ Generate {button_label}")
|
| 246 |
|
| 247 |
# Create the render function for this specific step
|
| 248 |
create_render_results(step_name, generation_results)
|
event_handler.py
CHANGED
|
@@ -7,27 +7,43 @@ import json
|
|
| 7 |
from prompt_configs import PROMPTS
|
| 8 |
from typing import Generator, Tuple
|
| 9 |
|
| 10 |
-
|
| 11 |
def generate_step_1(progress=gr.Progress()) -> Generator[Tuple[str, list], Any, None]:
|
| 12 |
"""Generate content using the Project instance"""
|
| 13 |
try:
|
|
|
|
|
|
|
|
|
|
| 14 |
# Generate PRD and components, yielding results as they're generated
|
| 15 |
for status_msg, result in state.quotation_project.generate_prd_and_components(progress):
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
except Exception as e:
|
| 19 |
-
print(f"Error during generation: {str(e)}")
|
| 20 |
yield f"Error during generation: {str(e)}", []
|
| 21 |
|
| 22 |
-
def
|
| 23 |
"""Generate content using the Project instance"""
|
| 24 |
try:
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
except Exception as e:
|
| 30 |
-
print(f"Error during generation: {str(e)}")
|
| 31 |
yield f"Error during generation: {str(e)}", []
|
| 32 |
|
| 33 |
def setup_all_handlers(step_buttons, all_components, progress_update, quotation_cost=None, recalc_btn=None, upload_drive_btn=None, upload_notion_btn=None, project_name=None, generation_results=None):
|
|
@@ -39,58 +55,85 @@ def setup_all_handlers(step_buttons, all_components, progress_update, quotation_
|
|
| 39 |
queue=True
|
| 40 |
)
|
| 41 |
|
| 42 |
-
step_buttons['Step 2 :
|
| 43 |
-
fn=
|
| 44 |
outputs=[progress_update, generation_results],
|
| 45 |
queue=True
|
| 46 |
)
|
| 47 |
|
| 48 |
-
return generation_results
|
| 49 |
-
|
| 50 |
def create_render_results(step, generation_results):
|
| 51 |
@gr.render(inputs=[generation_results])
|
| 52 |
def render_results(results):
|
| 53 |
if not results:
|
| 54 |
return [gr.Markdown("No results generated yet.")]
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
if not relevant_results:
|
| 62 |
return [gr.Markdown("No results generated for this step.")]
|
| 63 |
|
| 64 |
# Create components as a list
|
| 65 |
result_components = []
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
|
|
|
|
|
|
|
| 94 |
return result_components
|
| 95 |
|
| 96 |
return render_results
|
|
|
|
| 7 |
from prompt_configs import PROMPTS
|
| 8 |
from typing import Generator, Tuple
|
| 9 |
|
|
|
|
| 10 |
def generate_step_1(progress=gr.Progress()) -> Generator[Tuple[str, list], Any, None]:
|
| 11 |
"""Generate content using the Project instance"""
|
| 12 |
try:
|
| 13 |
+
# Initialize a list of step_results
|
| 14 |
+
step_results = []
|
| 15 |
+
|
| 16 |
# Generate PRD and components, yielding results as they're generated
|
| 17 |
for status_msg, result in state.quotation_project.generate_prd_and_components(progress):
|
| 18 |
+
step_results.append(result)
|
| 19 |
+
state.generation_results['step_1'] = step_results
|
| 20 |
+
print(f"Intermediate state update: {state.generation_results}")
|
| 21 |
+
yield status_msg, step_results
|
| 22 |
|
| 23 |
+
# Store results in the shared data structure
|
| 24 |
+
state.generation_results['step_1'] = step_results
|
| 25 |
+
print("Step 1 Results Stored:", state.generation_results)
|
| 26 |
+
|
| 27 |
except Exception as e:
|
| 28 |
+
print(f"Error during generation: {str(e)}")
|
| 29 |
yield f"Error during generation: {str(e)}", []
|
| 30 |
|
| 31 |
+
def generate_step_2_a(progress=gr.Progress()) -> Generator[Tuple[str, list], Any, None]:
|
| 32 |
"""Generate content using the Project instance"""
|
| 33 |
try:
|
| 34 |
+
# Initialize results for this step
|
| 35 |
+
step_results = []
|
| 36 |
+
|
| 37 |
+
# Generate mandays estimate, yielding results as they're generated
|
| 38 |
+
for status_msg, result in state.quotation_project.generate_mandays_estimate(progress):
|
| 39 |
+
step_results.append(result)
|
| 40 |
+
yield status_msg, step_results
|
| 41 |
+
|
| 42 |
+
# Store results in the shared data structure
|
| 43 |
+
state.generation_results['step_2_a'] = step_results
|
| 44 |
|
| 45 |
except Exception as e:
|
| 46 |
+
print(f"Error during generation: {str(e)}")
|
| 47 |
yield f"Error during generation: {str(e)}", []
|
| 48 |
|
| 49 |
def setup_all_handlers(step_buttons, all_components, progress_update, quotation_cost=None, recalc_btn=None, upload_drive_btn=None, upload_notion_btn=None, project_name=None, generation_results=None):
|
|
|
|
| 55 |
queue=True
|
| 56 |
)
|
| 57 |
|
| 58 |
+
step_buttons['Step 2.1 : Generate Mandays'].click(
|
| 59 |
+
fn=generate_step_2_a,
|
| 60 |
outputs=[progress_update, generation_results],
|
| 61 |
queue=True
|
| 62 |
)
|
| 63 |
|
|
|
|
|
|
|
| 64 |
def create_render_results(step, generation_results):
|
| 65 |
@gr.render(inputs=[generation_results])
|
| 66 |
def render_results(results):
|
| 67 |
if not results:
|
| 68 |
return [gr.Markdown("No results generated yet.")]
|
| 69 |
|
| 70 |
+
# Retrieve relevant results for the current step from the state
|
| 71 |
+
if step == "Step 1 : Scope & Components":
|
| 72 |
+
relevant_results = state.generation_results.get('step_1', [])
|
| 73 |
+
elif step == "Step 2.1 : Generate Mandays":
|
| 74 |
+
relevant_results = state.generation_results.get('step_2_a', [])
|
| 75 |
+
else:
|
| 76 |
+
relevant_results = []
|
| 77 |
|
| 78 |
if not relevant_results:
|
| 79 |
return [gr.Markdown("No results generated for this step.")]
|
| 80 |
|
| 81 |
# Create components as a list
|
| 82 |
result_components = []
|
| 83 |
+
seen_results = set() # To avoid duplicates
|
| 84 |
+
|
| 85 |
+
# Handle case where relevant_results is a list of results
|
| 86 |
+
if isinstance(relevant_results, list):
|
| 87 |
+
# If it's a single list in the results, process its items
|
| 88 |
+
for result_item in relevant_results[-1]: # Take the latest result set
|
| 89 |
+
try:
|
| 90 |
+
# Extract function name and result from the item
|
| 91 |
+
if isinstance(result_item, dict):
|
| 92 |
+
function_name = result_item.get("function_name", "Unknown Function")
|
| 93 |
+
result = result_item.get("result", "No result")
|
| 94 |
+
|
| 95 |
+
# Skip if we've seen this exact result before
|
| 96 |
+
result_str = json.dumps(result) if isinstance(result, (dict, list)) else str(result)
|
| 97 |
+
if result_str in seen_results:
|
| 98 |
+
continue
|
| 99 |
+
seen_results.add(result_str)
|
| 100 |
+
|
| 101 |
+
# Get prompt config if available
|
| 102 |
+
prompt_config = PROMPTS.get(function_name)
|
| 103 |
+
description = prompt_config.description if prompt_config else function_name
|
| 104 |
+
|
| 105 |
+
# Create an accordion for each result
|
| 106 |
+
with gr.Accordion(f"{description}", open=False):
|
| 107 |
+
result_components.append(
|
| 108 |
+
gr.Row([
|
| 109 |
+
gr.Column(
|
| 110 |
+
gr.Textbox(
|
| 111 |
+
value=result_str,
|
| 112 |
+
label="Text Output",
|
| 113 |
+
lines=10,
|
| 114 |
+
interactive=True
|
| 115 |
+
),
|
| 116 |
+
scale=1
|
| 117 |
+
),
|
| 118 |
+
gr.Column(
|
| 119 |
+
gr.Markdown(
|
| 120 |
+
value=result_str,
|
| 121 |
+
show_copy_button=True,
|
| 122 |
+
elem_classes=["scrollable-markdown"]
|
| 123 |
+
),
|
| 124 |
+
scale=1
|
| 125 |
+
)
|
| 126 |
+
])
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
except Exception as e:
|
| 131 |
+
print(f"Debug: Error processing result item: {str(e)}")
|
| 132 |
+
continue
|
| 133 |
|
| 134 |
+
if not result_components:
|
| 135 |
+
return [gr.Markdown("No valid results to display.")]
|
| 136 |
+
|
| 137 |
return result_components
|
| 138 |
|
| 139 |
return render_results
|
prompt_configs.py
CHANGED
|
@@ -934,6 +934,7 @@ PROMPTS = {
|
|
| 934 |
}
|
| 935 |
),
|
| 936 |
|
|
|
|
| 937 |
"generate_plan_test_mandays": PromptConfig(
|
| 938 |
prompt=
|
| 939 |
"""
|
|
|
|
| 934 |
}
|
| 935 |
),
|
| 936 |
|
| 937 |
+
# Ivy : Combine both into one
|
| 938 |
"generate_plan_test_mandays": PromptConfig(
|
| 939 |
prompt=
|
| 940 |
"""
|
sample_permutations.py
CHANGED
|
@@ -5,28 +5,21 @@ class ConfigurationType(Enum):
|
|
| 5 |
CHATBOT = "Basic Chatbot"
|
| 6 |
DOCUMENT_EXTRACTION = "Document Extraction"
|
| 7 |
CHATBOT_AND_DOC = "Basic Chatbot and Document Extraction"
|
| 8 |
-
GENERAL_SOFTWARE = "General Software"
|
| 9 |
|
| 10 |
CONFIGURATION_TYPE_FUNCTIONS = {
|
| 11 |
ConfigurationType.CHATBOT: [
|
| 12 |
-
"
|
| 13 |
-
"
|
| 14 |
-
"
|
| 15 |
],
|
| 16 |
ConfigurationType.DOCUMENT_EXTRACTION: [
|
| 17 |
-
"
|
| 18 |
-
"
|
| 19 |
],
|
| 20 |
ConfigurationType.CHATBOT_AND_DOC: [
|
| 21 |
-
"
|
| 22 |
-
"
|
| 23 |
-
"
|
| 24 |
-
"generate_page_dev_components",
|
| 25 |
-
"generate_engage_dev_components",
|
| 26 |
-
],
|
| 27 |
-
ConfigurationType.GENERAL_SOFTWARE: [
|
| 28 |
-
"generate_plan_test_components",
|
| 29 |
-
"generate_dev_components"
|
| 30 |
]
|
| 31 |
}
|
| 32 |
|
|
|
|
| 5 |
CHATBOT = "Basic Chatbot"
|
| 6 |
DOCUMENT_EXTRACTION = "Document Extraction"
|
| 7 |
CHATBOT_AND_DOC = "Basic Chatbot and Document Extraction"
|
|
|
|
| 8 |
|
| 9 |
CONFIGURATION_TYPE_FUNCTIONS = {
|
| 10 |
ConfigurationType.CHATBOT: [
|
| 11 |
+
"generate_intents_csv",
|
| 12 |
+
"generate_plan_test_mandays",
|
| 13 |
+
"generate_dev_mandays",
|
| 14 |
],
|
| 15 |
ConfigurationType.DOCUMENT_EXTRACTION: [
|
| 16 |
+
"generate_plan_test_mandays",
|
| 17 |
+
"generate_dev_mandays",
|
| 18 |
],
|
| 19 |
ConfigurationType.CHATBOT_AND_DOC: [
|
| 20 |
+
"generate_intents_csv",
|
| 21 |
+
"generate_plan_test_mandays",
|
| 22 |
+
"generate_dev_mandays",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
]
|
| 24 |
}
|
| 25 |
|
state.py
CHANGED
|
@@ -8,6 +8,7 @@ class ProjectType(Enum):
|
|
| 8 |
class GlobalState:
|
| 9 |
def __init__(self):
|
| 10 |
self._quotation_project = None
|
|
|
|
| 11 |
|
| 12 |
@property
|
| 13 |
def quotation_project(self):
|
|
|
|
| 8 |
class GlobalState:
|
| 9 |
def __init__(self):
|
| 10 |
self._quotation_project = None
|
| 11 |
+
self.generation_results = {}
|
| 12 |
|
| 13 |
@property
|
| 14 |
def quotation_project(self):
|