Darpan07 commited on
Commit
d94942e
·
verified ·
1 Parent(s): 73b7828

Upload 4 files

Browse files
Files changed (4) hide show
  1. Functions.py +127 -0
  2. Prompts_and_Chains.py +74 -0
  3. Templates.py +126 -0
  4. Utils.py +32 -0
Functions.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ import os
3
+ from PyPDF2 import PdfReader
4
+ from langchain.text_splitter import CharacterTextSplitter
5
+ from langchain_community.vectorstores import Chroma
6
+ from langchain_community.embeddings import OpenAIEmbeddings
7
+ import streamlit as st
8
+ from textwrap import dedent
9
+ from Prompts_and_Chains import LLMChains
10
+ from Templates import json_structure
11
+ import json
12
+ from Utils import estimate_to_value
13
+
14
+
15
+ class RFPProcessor:
16
+ def __init__(self):
17
+ load_dotenv()
18
+ self.openai_api_key = os.getenv("OPENAI_API_KEY")
19
+ self.chains_obj = LLMChains()
20
+
21
+ def generate_estimations(self, tech_leads, senior_developers, junior_developers):
22
+ print(st.session_state["user_stories_json"])
23
+ inputs = {
24
+ "project_summary": st.session_state["rfp_summary"],
25
+ "user_stories": st.session_state["user_stories_json"],
26
+ "tech_leads": tech_leads,
27
+ "senior_developers": senior_developers,
28
+ "junior_developers": junior_developers,
29
+ }
30
+
31
+ data = self.chains_obj.estimations_chain.run(inputs)
32
+ estimation_json_data = json.loads(data)
33
+
34
+ for epic_data in estimation_json_data["epics"]:
35
+ epic = epic_data["name"]
36
+ for feature_data in epic_data["features"]:
37
+ feature = feature_data["name"]
38
+ for story in feature_data["stories"]:
39
+ average = estimate_to_value(story["estimate"])
40
+ st.session_state.estimation_data.append(
41
+ {
42
+ "epic": epic,
43
+ "Feature": feature,
44
+ "Story Description": story["description"],
45
+ "Story Estimation": story["estimate"],
46
+ "Story Effort": story["effort"],
47
+ "Average Estimate": average,
48
+ "Story Rationale": story["rationale"],
49
+ }
50
+ )
51
+ st.session_state["is_estimation_data_created"] = True
52
+
53
+ def process_rfp_data(self, project_name, file):
54
+ if project_name and file:
55
+ loader = PdfReader(file)
56
+ for i, page in enumerate(loader.pages):
57
+ content = page.extract_text()
58
+ if content:
59
+ temp = st.session_state["rfp_details"]
60
+ st.session_state["rfp_details"] = temp + content
61
+
62
+ text_splitter = CharacterTextSplitter(
63
+ separator="\n", chunk_size=1000, chunk_overlap=150, length_function=len
64
+ )
65
+
66
+ texts = text_splitter.split_text(st.session_state["rfp_details"])
67
+
68
+ st.session_state["vectorstore"] = Chroma().from_texts(
69
+ texts, embedding=OpenAIEmbeddings(openai_api_key=self.openai_api_key)
70
+ )
71
+
72
+ st.session_state.project_name = project_name
73
+ st.session_state["rfp_summary"] = self.chains_obj.summary_chain.run(
74
+ {
75
+ "project_name": st.session_state["project_name"],
76
+ "rfp_details": dedent(st.session_state["rfp_details"]),
77
+ }
78
+ )
79
+
80
+ st.session_state["is_data_processed"] = True
81
+ st.success("data processed sucessfully")
82
+
83
+ def genrate_bot_result(self):
84
+ if len(st.session_state["input"]) > 0:
85
+ db = st.session_state["vectorstore"]
86
+ context = db.similarity_search(st.session_state["input"])
87
+ inputs = {
88
+ "context": context[0].page_content,
89
+ "input": st.session_state["input"],
90
+ }
91
+ output = self.chains_obj.bot_chain.run(inputs)
92
+ st.session_state.past.append(st.session_state["input"])
93
+ st.session_state.generated.append(output)
94
+ st.session_state["input"] = ""
95
+
96
+ def genrate_user_stories(self):
97
+ output = self.chains_obj.user_story_chain.run(
98
+ {
99
+ "project_name": st.session_state["project_name"],
100
+ "rfp_details": st.session_state["rfp_details"],
101
+ }
102
+ )
103
+ st.session_state["user_stories"] = output
104
+
105
+ json_response = self.chains_obj.json_chain.run(
106
+ {
107
+ "user_stories": st.session_state["user_stories"],
108
+ "json_structure": json_structure,
109
+ }
110
+ )
111
+ user_stories_data = json.loads(json_response)
112
+ print(user_stories_data)
113
+ st.session_state["user_stories_json"] = user_stories_data
114
+
115
+ for epic_data in user_stories_data["epics"]:
116
+ epic = epic_data["name"]
117
+ for feature_data in epic_data["features"]:
118
+ feature = feature_data["name"]
119
+ for story in feature_data["stories"]:
120
+ st.session_state.user_stories_data.append(
121
+ {
122
+ "epic": epic,
123
+ "Feature": feature,
124
+ "Story Description": story["description"],
125
+ }
126
+ )
127
+ st.session_state["is_user_stories_created"] = True
Prompts_and_Chains.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ******* THIS FILE CONTAINS ALL THE PROMPTS & CHAINS USED IN Functions.py ***********
2
+ from Templates import *
3
+ from langchain import PromptTemplate
4
+ from langchain.chains import LLMChain
5
+ from langchain.llms import OpenAI
6
+ from dotenv import load_dotenv
7
+ import os
8
+
9
+
10
+ class PromptTemplates:
11
+ def __init__(self):
12
+ self.json_prompt_template = PromptTemplate(
13
+ input_variables=["user_stories", "json_structure"],
14
+ template=convert_json_template,
15
+ )
16
+
17
+ self.user_story_prompt = PromptTemplate(
18
+ input_variables=["project_name", "rfp_details"],
19
+ template=user_story_template,
20
+ )
21
+
22
+ self.bot_prompt = PromptTemplate(
23
+ input_variables=["context", "input"], template=bot_template
24
+ )
25
+
26
+ self.summary_prompt = PromptTemplate(
27
+ input_variables=["project_name", "rfp_details"], template=summary_template
28
+ )
29
+
30
+ self.estimations_prompt_template = PromptTemplate(
31
+ input_variables=["project_summary", "user_stories","tech_leads", "senior_developers","junior_developers"], template=estimations_template
32
+ )
33
+
34
+
35
+ class LLMChains:
36
+
37
+ def __init__(self):
38
+ load_dotenv()
39
+ openai_api_key = os.getenv("OPENAI_API_KEY")
40
+ obj = PromptTemplates()
41
+
42
+ # generate summary chain
43
+ self.summary_chain = LLMChain(
44
+ llm=OpenAI(model_name="gpt-3.5-turbo-16k", temperature=0.7),
45
+ prompt=obj.summary_prompt,
46
+ verbose="true",
47
+ )
48
+
49
+ # genrate bot conversastion
50
+ self.bot_chain = LLMChain(
51
+ llm=OpenAI(model_name="gpt-3.5-turbo-16k", temperature=0.7),
52
+ prompt=obj.bot_prompt,
53
+ verbose="true",
54
+ )
55
+
56
+ # genrate user stories user_story_template = """
57
+ self.user_story_chain = LLMChain(
58
+ llm=OpenAI(model_name="gpt-3.5-turbo-16k", temperature=0.7),
59
+ prompt=obj.user_story_prompt,
60
+ verbose="true",
61
+ )
62
+
63
+ # prompt template for json
64
+ self.json_chain = LLMChain(
65
+ llm=OpenAI(model_name="gpt-3.5-turbo-16k", temperature=0.7),
66
+ prompt=obj.json_prompt_template,
67
+ verbose="true",
68
+ )
69
+
70
+ self.estimations_chain = LLMChain(
71
+ llm=OpenAI(model_name="gpt-3.5-turbo-16k", temperature=0.7),
72
+ prompt=obj.estimations_prompt_template,
73
+ verbose="true",
74
+ )
Templates.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ******* THIS FILE CONTAINS ALL THE TEMPLATES USED IN APP.PY ***********
2
+
3
+
4
+ bot_template = """As a highly intelligent and powerful chatbot, your personality is a business analyst's responsibility.
5
+ Your designated name is RFP Bot. Initiate the conversation with a warm greeting only when the user asks something for the first time. Subsequent interactions can skip the greeting.
6
+ Your generated responses should be comprehensive, utilizing pointers when necessary for an enhanced user experience. Provide detailed answers, and if the user's input isn't related to personality, respond politely with an apology, encouraging them to ask questions related to your established personality. Keep your responses concise and accurate, seeking additional information from the user when required.
7
+ Incorporate the provided context and any relevant information from the chat history into your responses. If the user's input is related to the context or question, articulate your answer accordingly.
8
+ {context}
9
+ Human: {input}
10
+ Assistant:"""
11
+
12
+ user_story_template = """Given the project details with the following parameters:
13
+
14
+ **Project Name:** {project_name}
15
+
16
+ **RFP details:**
17
+ {rfp_details}
18
+
19
+ As a business analyst, analyze the given RFP details to delineate epics for the project. Break down the epics into features and features into individual requirements, adhering to the agile software development INVEST principles (where I refers to Independent (not dependent on other work deliverables), N refers to Negotiable (allows for best practices), V refers to valuable (provides working functionality), E refers to Estimable (allows clear work estimates), S refers to Small (sized for the team's sprint), T refers to Testable (can be measured to ensure it meets customer expectations)). Subsequently, generate user stories for each requirement. Ensure each story follows the "As a, I want to, So that" format and strictly avoid combining stories together.
20
+
21
+ **Examples**
22
+
23
+ 1. Epic: User Authentication and Account Security Enhancements
24
+
25
+ 1. Feature 1: User Registration
26
+ - Story 1:
27
+ - As a user, I want to provide my basic information, such as name and email address during sign-up, so that the platform can create a personalized account for me.
28
+ - Story 2:
29
+ - As a user, I want the sign-up form to include a CAPTCHA verification step, so that the system can prevent automated bots from creating fake accounts.
30
+ - Story 3:
31
+ - As a user, I want the sign-up form to include optional fields for additional profile information, so that I can customize my account based on my interests.
32
+ - Story 4:
33
+ - As a user, I want the platform to clearly communicate its data usage and privacy policy during the sign-up process, so that I can make an informed decision before creating an account.
34
+
35
+ 2. Feature 2: User Authentication
36
+ - Story 1:
37
+ - As a registered user, I want to log in securely with my credentials, so that I can access personalized account information.
38
+ - Story 2:
39
+ - As a registered user, I want the login page to feature a "Forgot Password" link, so that I can easily initiate the password recovery process if needed.
40
+ - Story 3:
41
+ - As a user concerned about account security, I want the platform to send a notification email whenever my account is accessed from a new device, so that I can be aware of any potential unauthorized access.
42
+ - Story 4:
43
+ - As a returning user, I want the option to enable two-factor authentication (2FA) for an extra layer of security during the login process, so that my account remains protected.
44
+ - Story 5:
45
+ - As a user striving for a seamless experience, I want the platform to offer a "Stay Logged In" option during login, so that I don't have to enter my credentials every time I revisit the site.
46
+ - Story 6:
47
+ - As a user with multiple devices, I want the ability to log out remotely from any active sessions through the account settings, so that I can maintain control over my account access.
48
+
49
+ 3. Feature 3: Account Security Enhancements
50
+ - Story 1:
51
+ - As a security-conscious user, I want the platform to prompt me every 15 days to update my password and provide guidance on creating a secure password to enhance the overall security of my account.
52
+ - Story 2:
53
+ - As a user who values privacy, I want the platform to automatically log me out after 5 minutes of inactivity, ensuring that my account is secure even if I forget to log out manually.
54
+ - Story 3:
55
+ - As a user concerned about account recovery, I want the platform to offer email verification and phone number verification account recovery options, to ensure I can regain access to my account if needed.
56
+ """
57
+
58
+
59
+ summary_template = """Given the project details with the following parameters:
60
+
61
+ **Project Name:** {project_name}
62
+
63
+ **RFP details:**
64
+ {rfp_details}
65
+
66
+ As a business analyst, analyze the given RFP details and give the detailed summary of the project.
67
+
68
+ """
69
+
70
+
71
+ convert_json_template = """
72
+ Given the project user stories:
73
+
74
+ **user_stories:** {user_stories}
75
+
76
+ Create a JSON representation that captures the structure and details of each epic and feature, including their respective stories. Ensure that the JSON format is well-organized, with clear hierarchies for epic,features and stories.
77
+
78
+ Example structure:
79
+
80
+ {json_structure}
81
+ """
82
+
83
+
84
+ estimations_template = """
85
+ Given the project details with the following parameters:
86
+
87
+ **Project summary:** {project_summary}
88
+
89
+ **User Stories:** {user_stories}
90
+
91
+ You are the project manager responsible for overseeing the development team. As the project manager, your task is to analyze the given Project summary and user stories for a better understanding of project requirements and assess and estimate the effort required for individual User Stories. Your development team consists of {tech_leads} Tech Lead, {senior_developers} Senior Developers, and {junior_developers} Junior Developers. Utilize t-shirt sizing (XS, S, M, L, XL) as per the provided guidelines to estimate the effort for each user story. Additionally, offer a brief rationale for each estimate, emphasizing the project scope and resource requirements based on the team composition. your generated output should be on JSON representation that captures the structure and details of each epic and feature, including their respective stories with name, description estimates, efforts, and rationale. Ensure that the JSON format is well-organized, with clear hierarchies for epic, features, and stories.
92
+
93
+
94
+ Guidelines for Estimation:
95
+ * XS: Signifies an already implemented feature with an effort range of 1-3 days, justified by minimal effort owing to the feature's existing presence.
96
+ * S: Encompasses easily testable scenarios, known solutions, and a small scope, with an effort range of 4-8 days. Justification is rooted in moderate effort due to external dependencies.
97
+ * M: Involves logic implementation and the integration of two services, with an effort range of 9-15 days. The rationale revolves around a moderate to high effort level attributed to logic intricacies and integration tasks.
98
+ * L: Encompasses extensive data modeling, uncertainty, and a large scope, with an effort range of 16-28 days. High effort is justified by the inherent complexity of the task.
99
+ * XL: Encompasses scenarios with multiple external platforms, new technologies, and comprehensive integration, requiring an effort range of 29-45 days. Very high effort is substantiated by the intricate nature of the task.
100
+ * XXL: Indicates scenarios where estimation is not feasible.
101
+
102
+ """
103
+
104
+
105
+ json_structure = {
106
+ "epics": [
107
+ {
108
+ "name": "App Performance and Efficiency",
109
+ "features": [
110
+ {
111
+ "name": "Fast and Zero Load Time",
112
+ "stories": [
113
+ {
114
+ "name": "Story 1",
115
+ "description": "As a user, I want the app to load quickly with zero load time, so that I can access news content efficiently.",
116
+ },
117
+ {
118
+ "name": "Story 2",
119
+ "description": "As a user, I want the installation process of the mobile app to be quick and hassle-free, so that I can start using the app immediately after download without any complications.",
120
+ },
121
+ ],
122
+ }
123
+ ],
124
+ }
125
+ ]
126
+ }
Utils.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import streamlit as st
3
+ import base64
4
+
5
+
6
+ def clear_rfp_data():
7
+ st.session_state.clear()
8
+
9
+
10
+ def export(data):
11
+ # data_df = pd.DataFrame(st.session_state["user_stories_json"])
12
+ data_df = pd.DataFrame(data)
13
+ csv_data = data_df.to_csv(index=False)
14
+ b64 = base64.b64encode(csv_data.encode()).decode()
15
+ href = f'<a href="data:file/csv;base64,{b64}" download="data.csv">Download CSV File</a>'
16
+ st.markdown(href, unsafe_allow_html=True)
17
+
18
+
19
+ def estimate_to_value(estimate):
20
+ if estimate == "XS":
21
+ return 2
22
+ elif estimate == "S":
23
+ return 6
24
+ elif estimate == "M":
25
+ return 12
26
+ elif estimate == "L":
27
+ return 22
28
+ elif estimate == "XL":
29
+ return 37
30
+ else:
31
+ # Handle the case when the estimate is not one of the specified values
32
+ return "Invalid estimate"