Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Business Process Flow Enhancements #33

Merged
merged 6 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/tall-mice-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"specif-ai": minor
---

- During addition/ update of a business process the attached PRDs and BRDs will not be appended to the business process description
- Added process flow diagram examples and guidelines to create flow chart prompt for better responses
- PRDs and BRDs are sent as context during the creation of business process flow chart
18 changes: 8 additions & 10 deletions backend/api/solution_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ def create_process_flow_chart():
logger.info(f"Request {g.request_id}: Entered <create_process_flow_chart>")
try:
data = create_process_flow_chart_schema.load(request.get_json())
except ValidationError as err:
logger.error(f"Request {g.request_id}: Payload validation failed: {err.messages}")
raise CustomAppException("Payload validation failed.", status_code=400) from err
try:
data = request.get_json()
process_flow_template = render_template(p_process_flow_chart)
process_flow_req = process_flow_template.render(title=data["title"], description=data["description"])
BRDS = "\n".join(data["selectedBRDs"])
PRDS = "\n".join(data["selectedPRDs"])
process_flow_req = process_flow_template.render(title=data["title"], description=data["description"], BRDS=BRDS, PRDS=PRDS,)
process_flow_description = llm_service.call_llm(process_flow_req)
parsed_res = json.dumps(process_flow_description)
except ValidationError as err:
logger.error(f"Request {g.request_id}: Payload validation failed: {err.messages}")
raise CustomAppException("Payload validation failed.", status_code=400) from err
except json.JSONDecodeError as exc:
logger.error(f"Request {g.request_id}: Failed to parse LLM response")
raise CustomAppException(
Expand Down Expand Up @@ -477,7 +477,6 @@ def add_business_process():
)
llm_response = llm_service.call_llm(template)
else:
newReqt = f"{newReqt} {BRDS} {PRDS}"
llm_response = json.dumps(
{"LLMreqt": {"title": data["title"], "requirement": newReqt}}
)
Expand Down Expand Up @@ -513,12 +512,11 @@ def update_business_process():
existingReqt=data["reqDesc"],
updatedReqt=updatedReqt,
reqId=data["reqId"],
BRDS=" ".join(data["selectedBRDs"]),
PRDS=" ".join(data["selectedPRDs"]),
BRDS=BRDS,
PRDS=PRDS,
)
llm_response = llm_service.call_llm(template)
else:
updatedReqt = f'{updatedReqt} {BRDS} {PRDS}'
llm_response = json.dumps(
{"updated": {"title": data["title"], "requirement": updatedReqt}}
)
Expand Down
82 changes: 64 additions & 18 deletions backend/llm/prompts/08_process_flow_chart.jinja2
Original file line number Diff line number Diff line change
@@ -1,40 +1,80 @@
You are a team lead tasked with creating detailed breakdown of the business process flow for a given business process.
You are a business analyst with expertise in Mermaid diagramming and charting tool tasked with creating a detailed breakdown of the business process flow for a given business process.

Below is the business process for which the mermaid flowchart diagram code syntax has to be generated:

Business Process:
Title: {{title}}
{{ description }}

The mermaid diagram code syntax should be STRICTLY derived based on the provided business process description, with no additional or irrelevant information included.
Business Requirements:
{{BRDS}}

Product Requirements:
{{PRDS}}

The mermaid diagram code syntax must be STRICTLY derived based on the provided business process description, business and product requirements, with no additional or irrelevant information included.
Ensure that each step in the flowchart diagram code is clear, concise, and comprehensive.
Maintain the title for Mermaid as same as Business Process.

Output Structure should be a valid mermaid code syntax: Here is the sample Structure. Follow this response format exactly.
Output Structure should be a valid mermaid code syntax: Here is the sample Structure. Please follow this response format exactly.

RESPONSE FORMAT EXAMPLES
Example 1:
Business Process:
Title: Login
User login functionality.
Title: Ticket Resolution Workflow
Ticket Resolution functionality.

Mermaid Flow Response:
---
title: Ticket Resolution Workflow
---
flowchart TD
A["Ticket/Email Submitted by Customer"] --> B[Support Case is Created and Assigned];
B --> C{"During STD Business Hours?"};
C -- Yes --> D[Alerts are sent to the Support team to respond];
C -- No --> E["Alerts are sent to the on-call Technician to respond"];
D --> F{"Is ticket assigned?"};
E --> F;
F -- Yes --> G[Ticket is reviewed based on priority by Support team];
F -- No --> H[Reminder is sent];
H --> F;
G --> I[Support team resolves Issues];
I --> K{"Was issue resolved?"};
K -- Yes --> J[Ticket is closed and system sends follow up Email];
K -- No --> I;

Example 2:
Business Process:
Title: Order Fulfillment Workflow

Mermaid Flow Response:
---
title: Login
title: Order Fulfillment Workflow
---
flowchart TD
A([User]) -- enters login details ---> B[[Application]]
B -- Send login request ---> C[[Server]]
C -- Server verifies credentials ---D[(Database)]
D --> E{Are credentials valid?}
E -->|Yes| F[Generate authentication token]
F --> G[Send token to Application]
G --> H[Grant access to user]
H --> L[End]
E -->|No| J[Send error message to Application]
J --> K[Show error message to user]
K --> L[End]
...
A["Start: Customer places order (online/phone)"] --> B[Order Processing System receives order];
B --> C[Check Inventory];
C -- In Stock --> D[Generate Invoice];
C -- Out of Stock --> E["Notify Customer about backorder/alternatives"];
E --> F{"Customer Accepts Alternative?"};
F -- Yes --> G[Update Order with Alternative];
G --> D;
F -- No --> H["Cancel Order / Refund"];
H --> I[Notify Customer of Cancellation];
D --> J[Payment Processing];
J -- Successful --> K["Fulfill Order (Warehouse)"];
J -- Failed --> L[Notify Customer of Payment Issue];
L --> M{"Customer Retry Payment?"};
M -- Yes --> J;
M -- No --> H;
K --> N[Shipping];
N --> O[Delivery];
O --> P[Customer Receives Order];
P --> Q["Customer Feedback/Support"];
Q --> R["End: Order Complete"];
K --> S[Update Inventory];
S --> N;


Note:
1. The actual code syntax for a given business process may differ but the format should not be changed.
Expand All @@ -46,13 +86,19 @@ Note:
e. Always have single start and end nodes.
3. Generate appropriate title for the flowchart only based on the business process information. Do not assume anything. Title should be crisp and catchy and should not exceed 3 words.
4. Do not generate more than 10 steps in the flow chart for better readability. Keep the diagram crisp and to the point.
5. Take time and think about the code and the diagram for accuracy and correctness before you write a single line of code.
6. The workflow process diagram should accurately represent the business process.
7. The workflow should not contain technical or implementation details.
8. The process should be designed to maintain a continuous and logical flow, avoiding any points where it can become stalled or blocked.

STRICT:
(!) RESPONSE SHOULD STRICTLY FOLLOW SYNTAX OF MERMAID FLOWCHART DIAGRAMS and should be parsed without errors.
(!) DO NOT include INVALID notations/symbols like [(())], (([])) that throws SYNTAX ERROR in mermaid editor.
(!) DO NOT include double quotes(") inside text of a node. USE single quotes (') instead.
(!) WRAP the node text with double quotes (") if the node text contains special characters.
(!) Response should contain mermaid flowchart diagram code syntax of business process ONLY: no other additional text.
(!) Please ensure the RESPONSE containing mermaid flowchart diagram CODE is WITHOUT ANY SYNTAX ERROR and strictly based on the provided business process context and the diagram is clear, concise, and comprehensive with complete design.
(!) Every step, decision, data element, and actor in the generated process flow must be directly derivable from the provided context. If an element cannot be logically derived from the context, it should not be included.

If you follow the above STRICT rules, 100$ tip will be given to you.

Expand Down
8 changes: 7 additions & 1 deletion backend/schemas/businessprocess_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
class CreateFlowChartSchema(Schema):
id = fields.String(required=True)
title = fields.String(required=True)
description = fields.String(required=True, validate=validate.Length(min=5, error="Description must not be empty"))
description = fields.String(
required=True,
validate=validate.Length(min=5, error="Description must not be empty"),
)
selectedBRDs = fields.List(fields.String(), required=False, load_default=list)
selectedPRDs = fields.List(fields.String(), required=False, load_default=list)


class CreateBusinessProcessSchema(Schema):
reqt = fields.String(required=False)
Expand Down
4 changes: 3 additions & 1 deletion ui/src/app/model/interfaces/IBusinessProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export interface IFlowChartRequest {
id: string;
title: string;
description: string;
selectedBRDs: string[];
selectedPRDs: string[];
}

export interface IUpdateProcessRequest {
Expand Down Expand Up @@ -65,7 +67,7 @@ export interface IUpdateProcessResponse {
selectedBRDs: string[];
selectedPRDs: any[];
title: string;
updated: ILLMresponse
updated: ILLMresponse;
updatedReqt: string;
useGenAI: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ export class BusinessProcessFlowComponent
id: this.requirementId,
title: this.selectedRequirement.title,
description: this.selectedRequirement.requirement,
selectedBRDs: this.selectedRequirement.selectedBRDs,
selectedPRDs: this.selectedRequirement.selectedPRDs,
};
this.featureService.addFlowChart(request).subscribe({
next: (response: any) => {
Expand Down
Loading