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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
import requests
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
import phoenix as px
|
7 |
+
from phoenix.trace.langchain import LangChainInstrumentor
|
8 |
+
|
9 |
+
from google.oauth2 import service_account
|
10 |
+
from json_repair import repair_json
|
11 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
12 |
+
|
13 |
+
import dto.user_story as us
|
14 |
+
import dto.release_notes as rs
|
15 |
+
import dto.requirement_gathering as rq
|
16 |
+
import prompts as pt
|
17 |
+
|
18 |
+
from langchain_community.llms import HuggingFaceEndpoint
|
19 |
+
from langchain_groq import ChatGroq
|
20 |
+
from langchain_cohere import ChatCohere
|
21 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
22 |
+
from langchain_google_vertexai import ChatVertexAI
|
23 |
+
from langchain_openai import ChatOpenAI
|
24 |
+
from langchain.prompts import PromptTemplate
|
25 |
+
|
26 |
+
from langchain_community.tools import DuckDuckGoSearchRun
|
27 |
+
from langchain_community.document_loaders import WebBaseLoader
|
28 |
+
from langchain_community.document_loaders import PyPDFLoader
|
29 |
+
from langchain.output_parsers import PydanticOutputParser
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
# Launch phoenix
|
34 |
+
lv_px_session = None
|
35 |
+
if "lv_px_session" not in st.session_state:
|
36 |
+
try:
|
37 |
+
lv_px_session = px.launch_app()
|
38 |
+
st.session_state.lv_px_session = lv_px_session
|
39 |
+
LangChainInstrumentor().instrument()
|
40 |
+
except:
|
41 |
+
lv_px_session = st.session_state.lv_px_session
|
42 |
+
else:
|
43 |
+
lv_px_session = st.session_state.lv_px_session
|
44 |
+
|
45 |
+
# Caching LLM response
|
46 |
+
if "lv_response" not in st.session_state:
|
47 |
+
lv_response = None
|
48 |
+
st.session_state.lv_response = lv_response
|
49 |
+
else:
|
50 |
+
lv_response = st.session_state.lv_response
|
51 |
+
|
52 |
+
# Caching Extracted Text
|
53 |
+
if "lv_extracted_text" not in st.session_state:
|
54 |
+
lv_extracted_text = ""
|
55 |
+
st.session_state.lv_extracted_text = lv_extracted_text
|
56 |
+
else:
|
57 |
+
lv_extracted_text = st.session_state.lv_extracted_text
|
58 |
+
|
59 |
+
# Caching LLM Model
|
60 |
+
if "lv_model_session" not in st.session_state:
|
61 |
+
st.session_state.lv_model_session = None
|
62 |
+
|
63 |
+
# Display user Error, Warning or Success Message
|
64 |
+
def fn_display_user_messages(lv_extracted_text, lv_type, mv_processing_message):
|
65 |
+
"""Display user Info, Error, Warning or Success Messages"""
|
66 |
+
|
67 |
+
if lv_type == "Success":
|
68 |
+
with mv_processing_message.container():
|
69 |
+
st.success(lv_extracted_text)
|
70 |
+
elif lv_type == "Error":
|
71 |
+
with mv_processing_message.container():
|
72 |
+
st.error(lv_extracted_text)
|
73 |
+
elif lv_type == "Warning":
|
74 |
+
with mv_processing_message.container():
|
75 |
+
st.warning(lv_extracted_text)
|
76 |
+
else:
|
77 |
+
with mv_processing_message.container():
|
78 |
+
st.info(lv_extracted_text)
|
79 |
+
|
80 |
+
# Function to set proxy
|
81 |
+
def fn_set_proxy(ui_proxy_url, ui_no_proxy_url):
|
82 |
+
"""Configure http and https proxy programmatically"""
|
83 |
+
|
84 |
+
os.environ['HTTP_PROXY'] = ui_proxy_url
|
85 |
+
os.environ['HTTPS_PROXY'] = ui_proxy_url
|
86 |
+
os.environ['NO_PROXY'] = ui_no_proxy_url
|
87 |
+
|
88 |
+
print("=== Proxy SET ===")
|
89 |
+
print("HTTP_PROXY:", os.environ.get('HTTP_PROXY'))
|
90 |
+
print("HTTPS_PROXY:", os.environ.get('HTTPS_PROXY'))
|
91 |
+
print("NO_PROXY:", os.environ.get('NO_PROXY'))
|
92 |
+
print("=================")
|
93 |
+
|
94 |
+
# Function to convert Website URL content into text
|
95 |
+
def fn_scrape_website(ui_grounding_url):
|
96 |
+
"""Function to convert Website URL content into text"""
|
97 |
+
|
98 |
+
lv_html_loader = WebBaseLoader(ui_grounding_url)
|
99 |
+
lv_html = lv_html_loader.load()
|
100 |
+
|
101 |
+
return lv_html
|
102 |
+
|
103 |
+
# Function to convert PDF content into Documents
|
104 |
+
def fn_scraper_pdf(ui_grounding_pdf):
|
105 |
+
"""Function to convert PDF content into text"""
|
106 |
+
|
107 |
+
# -- Saving file
|
108 |
+
lv_temp_file_path = os.path.join("pdf-data",ui_grounding_pdf.name)
|
109 |
+
if not os.path.exists(lv_temp_file_path):
|
110 |
+
with open(lv_temp_file_path,"wb") as lv_file:
|
111 |
+
lv_file.write(ui_grounding_pdf.getbuffer())
|
112 |
+
|
113 |
+
# -- Extracting Data
|
114 |
+
lv_pdf_loader = PyPDFLoader(lv_temp_file_path)
|
115 |
+
lv_pdf_content = lv_pdf_loader.load()
|
116 |
+
|
117 |
+
return lv_pdf_content
|
118 |
+
|
119 |
+
# Function to search internet for information
|
120 |
+
def fn_search_web(ui_search_web_input):
|
121 |
+
"""Search internet for information"""
|
122 |
+
|
123 |
+
lv_search_run = DuckDuckGoSearchRun()
|
124 |
+
lv_result = lv_search_run.run(ui_search_web_input)
|
125 |
+
|
126 |
+
return lv_result
|
127 |
+
|
128 |
+
# Function to extract YouTube Video Transcript
|
129 |
+
def fn_you_tube_video_transcript(ui_youtube_url,ui_processing_message):
|
130 |
+
"""Extract YouTube Video Transcript"""
|
131 |
+
|
132 |
+
fn_display_user_messages("Generating Youtube Transcript","Info", ui_processing_message)
|
133 |
+
|
134 |
+
try:
|
135 |
+
lv_youtube_transcript = YouTubeTranscriptApi.get_transcript(ui_youtube_url)
|
136 |
+
lv_response = ' '.join([item['text'] for item in lv_youtube_transcript])
|
137 |
+
|
138 |
+
fn_display_user_messages("Successfully generated Youtube transcript","Success", ui_processing_message)
|
139 |
+
|
140 |
+
return lv_response
|
141 |
+
except Exception as error:
|
142 |
+
print('Error Generating Youtube Transcript', error)
|
143 |
+
fn_display_user_messages("Error Generating Youtube Transcript","Error", ui_processing_message)
|
144 |
+
raise error
|
145 |
+
|
146 |
+
# Function to unset proxy
|
147 |
+
def fn_unset_proxy():
|
148 |
+
"""Unset http and https proxy"""
|
149 |
+
|
150 |
+
os.environ.pop('HTTP_PROXY', None)
|
151 |
+
os.environ.pop('HTTPS_PROXY', None)
|
152 |
+
os.environ.pop('NO_PROXY', None)
|
153 |
+
|
154 |
+
print("=== Proxy UNSET ===")
|
155 |
+
print("HTTP_PROXY:", os.environ.get('HTTP_PROXY'))
|
156 |
+
print("HTTPS_PROXY:", os.environ.get('HTTPS_PROXY'))
|
157 |
+
print("NO_PROXY:", os.environ.get('NO_PROXY'))
|
158 |
+
print("===================")
|
159 |
+
|
160 |
+
# Create Chat LLM Instance
|
161 |
+
@st.cache_resource
|
162 |
+
def fn_create_chatllm(ui_llm_provider, ui_api_key, ui_model_details):
|
163 |
+
"""Create Chat LLM Instance"""
|
164 |
+
|
165 |
+
lv_model = None
|
166 |
+
|
167 |
+
try:
|
168 |
+
if(ui_llm_provider == 'Huggingface'):
|
169 |
+
lv_model = HuggingFaceEndpoint(
|
170 |
+
repo_id=ui_model_details,
|
171 |
+
temperature=1.0,
|
172 |
+
huggingfacehub_api_token=ui_api_key
|
173 |
+
)
|
174 |
+
elif(ui_llm_provider == 'Groq'):
|
175 |
+
lv_model = ChatGroq(
|
176 |
+
temperature=1.0,
|
177 |
+
model_name=ui_model_details
|
178 |
+
)
|
179 |
+
|
180 |
+
elif(ui_llm_provider == 'Cohere'):
|
181 |
+
lv_model = ChatCohere(
|
182 |
+
temperature=1.0,
|
183 |
+
model=ui_model_details
|
184 |
+
|
185 |
+
)
|
186 |
+
elif(ui_llm_provider == 'Google'):
|
187 |
+
lv_model = ChatGoogleGenerativeAI(
|
188 |
+
temperature=1.0,
|
189 |
+
model=ui_model_details,
|
190 |
+
max_output_tokens=1000000
|
191 |
+
)
|
192 |
+
elif(ui_llm_provider == 'OpenAI'):
|
193 |
+
lv_model = ChatOpenAI(
|
194 |
+
temperature=1.0,
|
195 |
+
model=ui_model_details
|
196 |
+
)
|
197 |
+
elif(ui_llm_provider == 'Google VertexAI'):
|
198 |
+
lv_api_key = json.loads(ui_api_key)
|
199 |
+
g_creds = service_account.Credentials.from_service_account_info(lv_api_key)
|
200 |
+
lv_model = ChatVertexAI(
|
201 |
+
project=lv_api_key.get("project_id"),
|
202 |
+
temperature=1.0,
|
203 |
+
model=ui_model_details,
|
204 |
+
credentials=g_creds
|
205 |
+
)
|
206 |
+
|
207 |
+
print("Returning new model")
|
208 |
+
|
209 |
+
except Exception as e:
|
210 |
+
print("Error Configuring Model"+str(e))
|
211 |
+
|
212 |
+
return lv_model
|
213 |
+
|
214 |
+
# Generate Speech to Text
|
215 |
+
@st.cache_resource
|
216 |
+
def fn_generate_speech_to_text(ui_audio_bytes,ui_api_key):
|
217 |
+
"""Generate Speech to Text"""
|
218 |
+
lv_extracted_text = None
|
219 |
+
|
220 |
+
try:
|
221 |
+
lv_url = "https://api-inference.huggingface.co/models/openai/whisper-large-v3"
|
222 |
+
lv_headers = {
|
223 |
+
'Authorization': "Bearer "+ui_api_key,
|
224 |
+
'Content-Type': "audio/wav"
|
225 |
+
}
|
226 |
+
response = requests.request("POST", lv_url, data=ui_audio_bytes, headers=lv_headers)
|
227 |
+
lv_extracted_text = response.json().get('text')
|
228 |
+
|
229 |
+
print(lv_extracted_text)
|
230 |
+
|
231 |
+
return lv_extracted_text
|
232 |
+
except Exception as error:
|
233 |
+
print('Error Generating Speech to Text', error)
|
234 |
+
raise error
|
235 |
+
|
236 |
+
# Generate LLM response
|
237 |
+
def fn_chatllm_response(ui_llm_provider, lv_summarize_prompt_formatted, lv_model, ui_processing_message):
|
238 |
+
"""Generate LLM response"""
|
239 |
+
|
240 |
+
fn_display_user_messages("Generating LLM Response","Info", ui_processing_message)
|
241 |
+
lv_response = None
|
242 |
+
|
243 |
+
try:
|
244 |
+
|
245 |
+
if(ui_llm_provider == 'Google VertexAI' or ui_llm_provider=='Google' or ui_llm_provider=='OpenAI' or ui_llm_provider=='Groq' or ui_llm_provider=='Cohere'):
|
246 |
+
lv_response = lv_model.invoke(lv_summarize_prompt_formatted).content
|
247 |
+
else:
|
248 |
+
lv_response = lv_model.invoke(lv_summarize_prompt_formatted)
|
249 |
+
|
250 |
+
lv_response = str(lv_response).replace("```json","")
|
251 |
+
lv_response = lv_response.replace("```","")
|
252 |
+
|
253 |
+
fn_display_user_messages("Generated LLM Response","Success", ui_processing_message)
|
254 |
+
return lv_response
|
255 |
+
except Exception as error:
|
256 |
+
print('Error Generating LLM Response', error)
|
257 |
+
fn_display_user_messages("Error Generating LLM Response","Error", ui_processing_message)
|
258 |
+
|
259 |
+
raise error
|
260 |
+
|
261 |
+
# Function to convert user story JSON to Markdown
|
262 |
+
def fn_convert_user_story_json_to_markdown(lv_json):
|
263 |
+
"""Convert User Story JSON to Markdown"""
|
264 |
+
|
265 |
+
lv_markdown = ""
|
266 |
+
try:
|
267 |
+
# Convert the dictionary to Markdown format
|
268 |
+
lv_markdown = f"# {lv_json['title']}\n\n"
|
269 |
+
lv_markdown += f"**Role:** {lv_json['role']}\n\n"
|
270 |
+
lv_markdown += f"**Feature:** {lv_json['feature']}\n\n"
|
271 |
+
lv_markdown += f"**Benefit:** {lv_json['benefit']}\n\n"
|
272 |
+
lv_markdown += "## User Story Scenarios\n"
|
273 |
+
|
274 |
+
for lv_scenario in lv_json['user_story_scenarios']:
|
275 |
+
lv_markdown += f"### {lv_scenario['scenario_title']}\n\n"
|
276 |
+
lv_markdown += f"**Pre-conditions:** {lv_scenario['pre_conditions']}\n\n"
|
277 |
+
lv_markdown += f"**Action Details:** {lv_scenario['action_details']}\n\n"
|
278 |
+
lv_markdown += f"**Expected Outcome:** {lv_scenario['expected_outcome']}\n\n"
|
279 |
+
except Exception as e:
|
280 |
+
print("UserStory - Error converting JSON to Markdown",str(e))
|
281 |
+
|
282 |
+
return lv_markdown
|
283 |
+
|
284 |
+
# Function to convert release notes JSON to Markdown
|
285 |
+
def fn_convert_release_notes_json_to_markdown(lv_json):
|
286 |
+
"""Convert Release Notes JSON to Markdown"""
|
287 |
+
|
288 |
+
lv_markdown = ""
|
289 |
+
try:
|
290 |
+
# Convert the dictionary to Markdown format
|
291 |
+
lv_markdown = f"# Release Notes\n\n"
|
292 |
+
lv_markdown += f"**Release Date:** {lv_json['release_date']}\n\n"
|
293 |
+
lv_markdown += f"**Product Name:** {lv_json['product_name']}\n\n"
|
294 |
+
lv_markdown += f"**Summary:** {lv_json['summary']}\n\n"
|
295 |
+
lv_markdown += "## Enhancements\n"
|
296 |
+
|
297 |
+
for lv_enhancement in lv_json['enhancements']:
|
298 |
+
lv_markdown += f"### {lv_enhancement['title']}\n\n"
|
299 |
+
lv_markdown += f"**Description:** {lv_enhancement['description']}\n\n"
|
300 |
+
lv_markdown += f"**Benefits:** {lv_enhancement['benefits']}\n\n"
|
301 |
+
lv_markdown += f"**Reason:** {lv_enhancement['reason']}\n\n"
|
302 |
+
except Exception as e:
|
303 |
+
print("ReleaseNotes - Error converting JSON to Markdown",str(e))
|
304 |
+
|
305 |
+
return lv_markdown
|
306 |
+
|
307 |
+
# Function to convert requirement generation JSON to Markdown
|
308 |
+
def fn_convert_requirement_generation_json_to_markdown(lv_json):
|
309 |
+
"""Convert Requirement Generation JSON to Markdown"""
|
310 |
+
|
311 |
+
lv_markdown = ""
|
312 |
+
try:
|
313 |
+
# Convert the dictionary to Markdown format
|
314 |
+
lv_markdown = f"# {lv_json['header']}\n\n"
|
315 |
+
lv_markdown += "## Requirements\n"
|
316 |
+
|
317 |
+
for requirement in lv_json['requirements']:
|
318 |
+
lv_markdown += f"### {requirement['overview']}\n\n"
|
319 |
+
lv_markdown += f"**Description:** {requirement['description']}\n\n"
|
320 |
+
lv_markdown += f"**Benefits:** {requirement['benefits']}\n\n"
|
321 |
+
lv_markdown += f"**Reason:** {requirement['reason']}\n\n"
|
322 |
+
lv_markdown += f"**Priority:** {requirement['priority']}\n\n"
|
323 |
+
if requirement['tags']:
|
324 |
+
tags = ', '.join(requirement['tags'])
|
325 |
+
lv_markdown += f"**Tags:** {tags}\n\n"
|
326 |
+
except Exception as e:
|
327 |
+
print("Requirement Gathering - Error converting JSON to Markdown",str(e))
|
328 |
+
|
329 |
+
return lv_markdown
|
330 |
+
|
331 |
+
# Main Program
|
332 |
+
def main():
|
333 |
+
|
334 |
+
# -- Streamlit Settings
|
335 |
+
st.set_page_config(
|
336 |
+
page_title="OBMA AI Assist",
|
337 |
+
page_icon="🧊",
|
338 |
+
layout="wide",
|
339 |
+
initial_sidebar_state="expanded"
|
340 |
+
)
|
341 |
+
|
342 |
+
# -- Display Processing Details
|
343 |
+
col1, col2, col3 = st.columns(3)
|
344 |
+
ui_processing_message = col2.empty()
|
345 |
+
ui_search_web_input =st.empty()
|
346 |
+
if "lv_model_session" in st.session_state:
|
347 |
+
lv_model = st.session_state.lv_model_session
|
348 |
+
else:
|
349 |
+
lv_model= None
|
350 |
+
|
351 |
+
global lv_response
|
352 |
+
global lv_extracted_text
|
353 |
+
|
354 |
+
col2.text("")
|
355 |
+
|
356 |
+
col2.header("OBMA - AI Assist")
|
357 |
+
col2.text("")
|
358 |
+
col2.text("")
|
359 |
+
col2.text("")
|
360 |
+
|
361 |
+
# -- Variables
|
362 |
+
cn_llm_providers_lov_values = ['Huggingface','Groq','Cohere','Google','Google VertexAI','OpenAI']
|
363 |
+
cn_huggingface_models_lov_values = ['meta-llama/Meta-Llama-3-70B-Instruct','CohereForAI/c4ai-command-r-plus','mistralai/Mistral-7B-Instruct-v0.2','microsoft/Phi-3-mini-128k-instruct','google/gemma-7b']
|
364 |
+
lv_user_actions = ["User Story","Release Notes","Requirement Generation","Summarization"]
|
365 |
+
|
366 |
+
# -- Configuration
|
367 |
+
with st.sidebar:
|
368 |
+
st.header("Configurations")
|
369 |
+
st.text("")
|
370 |
+
|
371 |
+
# -- Recording User Output
|
372 |
+
st.subheader("Output")
|
373 |
+
ui_user_actions = st.multiselect(
|
374 |
+
label='User Actions',
|
375 |
+
options=lv_user_actions,
|
376 |
+
default="User Story"
|
377 |
+
)
|
378 |
+
ui_show_json = st.toggle("Show JSON", value=False)
|
379 |
+
st.text("")
|
380 |
+
|
381 |
+
# -- Recording Proxy Details
|
382 |
+
try:
|
383 |
+
st.subheader("HTTP Proxy")
|
384 |
+
ui_proxy_url = st.text_input("URL")
|
385 |
+
ui_no_proxy_url = st.text_input("No Proxy URL",value="localhost,127.0.0.1")
|
386 |
+
col1, col2, col3 = st.columns([0.60,0.85,1.40])
|
387 |
+
with col1:
|
388 |
+
if st.button("Set"):
|
389 |
+
fn_set_proxy(ui_proxy_url,ui_no_proxy_url)
|
390 |
+
with col2:
|
391 |
+
if st.button("Unset"):
|
392 |
+
fn_unset_proxy()
|
393 |
+
except Exception as e:
|
394 |
+
st.error('Error Configuring LLM Details',str(e))
|
395 |
+
fn_display_user_messages("Error updating proxy details","Error", ui_processing_message)
|
396 |
+
|
397 |
+
# -- Read LLM Configuration
|
398 |
+
st.text("")
|
399 |
+
try:
|
400 |
+
st.subheader("LLM")
|
401 |
+
ui_llm_provider = st.selectbox(label='LLM Provider',options=cn_llm_providers_lov_values)
|
402 |
+
ui_api_key = st.empty()
|
403 |
+
ui_model_details = st.empty()
|
404 |
+
|
405 |
+
if ui_llm_provider:
|
406 |
+
# -- Prepopulated Configuration Details, Comment in production
|
407 |
+
if ui_llm_provider == 'Huggingface':
|
408 |
+
ui_api_key = st.text_input("HUGGINGFACEHUB_API_TOKEN",type="password")
|
409 |
+
ui_model_details = st.selectbox("Model Details",options=cn_huggingface_models_lov_values)
|
410 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = ui_api_key
|
411 |
+
elif(ui_llm_provider == 'Groq'):
|
412 |
+
ui_api_key = st.text_input("GROQ_API_KEY",type="password")
|
413 |
+
ui_model_details = st.text_input("Model Details","mixtral-8x7b-32768")
|
414 |
+
os.environ["GROQ_API_KEY"] = ui_api_key
|
415 |
+
elif(ui_llm_provider == 'Cohere'):
|
416 |
+
ui_api_key = st.text_input("COHERE_API_KEY", type="password")
|
417 |
+
ui_model_details = st.text_input("Model Details","command-r-plus")
|
418 |
+
os.environ["COHERE_API_KEY"] = ui_api_key
|
419 |
+
elif(ui_llm_provider == 'Google'):
|
420 |
+
ui_api_key = st.text_input("GOOGLE_API_KEY","AIzaSyAsksUKYnB4SuDNT6rB3d2Qd2hVk_TA5AA",type="password")
|
421 |
+
ui_model_details = st.text_input("Model Details","gemini-1.5-pro-latest")
|
422 |
+
os.environ["GOOGLE_API_KEY"] = ui_api_key
|
423 |
+
elif(ui_llm_provider == 'Google VertexAI'):
|
424 |
+
ui_api_key = st.text_area("GOOGLE_APPLICATION_CREDENTIALS")
|
425 |
+
ui_model_details = st.text_input("Model Details","gemini-1.5-pro-preview-0409")
|
426 |
+
elif(ui_llm_provider == 'OpenAI'):
|
427 |
+
ui_api_key = st.text_input("OPENAI_API_KEY", type="password")
|
428 |
+
ui_model_details = st.text_input("Model Details","gpt-4o")
|
429 |
+
os.environ["OPENAI_API_KEY"] = ui_api_key
|
430 |
+
else:
|
431 |
+
st.error('Please configure LLM Details')
|
432 |
+
fn_display_user_messages("Please configure LLM Details","Error", ui_processing_message)
|
433 |
+
|
434 |
+
if st.button("Configure LLM"):
|
435 |
+
# -- Create LLM Instance
|
436 |
+
if ui_llm_provider and ui_api_key and ui_model_details:
|
437 |
+
print("Configuring LLM")
|
438 |
+
lv_model = fn_create_chatllm(ui_llm_provider, ui_api_key, ui_model_details)
|
439 |
+
st.session_state.lv_model_session = lv_model
|
440 |
+
else:
|
441 |
+
st.error('Please configure LLM Details')
|
442 |
+
fn_display_user_messages("Please configure LLM Details","Error", ui_processing_message)
|
443 |
+
except Exception as e:
|
444 |
+
st.error('Error Configuring LLM Details'+str(e))
|
445 |
+
fn_display_user_messages("Error Configuring LLM Details","Error", ui_processing_message)
|
446 |
+
|
447 |
+
# -- Recording Knowledge Base Details
|
448 |
+
st.text("")
|
449 |
+
try:
|
450 |
+
st.subheader("Knowledge Base")
|
451 |
+
ui_grounding_url = st.text_input("Grounding URL")
|
452 |
+
ui_youtube_url = st.text_input("Youtube Video ID")
|
453 |
+
ui_grounding_pdf = st.file_uploader("Grounding PDF",type="pdf",accept_multiple_files=False)
|
454 |
+
ui_grounding_wav = st.file_uploader("Grounding WAV",type="wav",accept_multiple_files=False)
|
455 |
+
ui_search_web = st.checkbox("Search Web")
|
456 |
+
if ui_search_web:
|
457 |
+
ui_search_web_input = st.text_input("Search Details")
|
458 |
+
|
459 |
+
col1, col2, col3 = st.columns([0.85,0.80,1.40])
|
460 |
+
|
461 |
+
if col1.button("Extract"):
|
462 |
+
|
463 |
+
if ui_youtube_url:
|
464 |
+
lv_extracted_text +=fn_you_tube_video_transcript(ui_youtube_url,ui_processing_message)
|
465 |
+
|
466 |
+
if ui_grounding_url:
|
467 |
+
lv_extracted_text += ' '.join(doc.page_content for doc in fn_scrape_website(ui_grounding_url))
|
468 |
+
|
469 |
+
if ui_grounding_pdf:
|
470 |
+
lv_extracted_text += ' '.join(doc.page_content for doc in fn_scraper_pdf(ui_grounding_pdf))
|
471 |
+
|
472 |
+
if ui_search_web:
|
473 |
+
if ui_search_web_input:
|
474 |
+
lv_extracted_text += fn_search_web(ui_search_web_input)
|
475 |
+
|
476 |
+
if ui_grounding_wav:
|
477 |
+
lv_extracted_text += fn_generate_speech_to_text(ui_grounding_wav.getvalue(),ui_api_key)
|
478 |
+
|
479 |
+
st.session_state.lv_extracted_text = lv_extracted_text
|
480 |
+
|
481 |
+
if col2.button("Clear"):
|
482 |
+
lv_extracted_text = ""
|
483 |
+
st.session_state.lv_extracted_text = lv_extracted_text
|
484 |
+
lv_response = ""
|
485 |
+
st.session_state.lv_response = lv_response
|
486 |
+
except Exception as e:
|
487 |
+
st.error('Error extracting data - '+str(e))
|
488 |
+
fn_display_user_messages("Error extracting data","Error", ui_processing_message)
|
489 |
+
|
490 |
+
# -- User Actions
|
491 |
+
user_story, release_notes, requirement_generation, summarization = st.tabs(lv_user_actions)
|
492 |
+
|
493 |
+
with user_story:
|
494 |
+
# -- Generate User Story LLM Response
|
495 |
+
if ui_llm_provider and lv_extracted_text and not(lv_response) and "User Story" in ui_user_actions:
|
496 |
+
# -- Pydantice Schema
|
497 |
+
lv_parser = PydanticOutputParser(pydantic_object=us.UserStory)
|
498 |
+
|
499 |
+
# -- Creating Prompt
|
500 |
+
lv_template = pt.CN_USER_STORY
|
501 |
+
lv_summarize_prompt = PromptTemplate(
|
502 |
+
template=lv_template,
|
503 |
+
input_variables=["context"],
|
504 |
+
partial_variables={"format_instructions": lv_parser.get_format_instructions()},
|
505 |
+
)
|
506 |
+
lv_summarize_prompt_formatted = lv_summarize_prompt.format(
|
507 |
+
context=lv_extracted_text
|
508 |
+
)
|
509 |
+
|
510 |
+
# -- LLM Response
|
511 |
+
if lv_model:
|
512 |
+
lv_response = fn_chatllm_response(ui_llm_provider, lv_summarize_prompt_formatted, lv_model, ui_processing_message)
|
513 |
+
st.session_state.lv_response = lv_response
|
514 |
+
|
515 |
+
# -- Display LLM response
|
516 |
+
if lv_response and "User Story" in ui_user_actions:
|
517 |
+
lv_repaired = repair_json(lv_response, skip_json_loads=True)
|
518 |
+
|
519 |
+
if ui_show_json:
|
520 |
+
st.header("User Story")
|
521 |
+
st.json(lv_repaired)
|
522 |
+
else:
|
523 |
+
lv_markdown = fn_convert_user_story_json_to_markdown(json.loads(lv_repaired))
|
524 |
+
st.markdown(lv_markdown)
|
525 |
+
# st.json(lv_response)
|
526 |
+
|
527 |
+
with release_notes:
|
528 |
+
if ui_llm_provider and lv_extracted_text and not(lv_response) and "Release Notes" in ui_user_actions:
|
529 |
+
# -- Pydantice Schema
|
530 |
+
lv_parser = PydanticOutputParser(pydantic_object=rs.ReleaseNotes)
|
531 |
+
|
532 |
+
# -- Creating Prompt
|
533 |
+
lv_template = pt.CN_RELEASE_NOTES
|
534 |
+
lv_summarize_prompt = PromptTemplate(
|
535 |
+
template=lv_template,
|
536 |
+
input_variables=["context"],
|
537 |
+
partial_variables={"format_instructions": lv_parser.get_format_instructions()},
|
538 |
+
)
|
539 |
+
lv_summarize_prompt_formatted = lv_summarize_prompt.format(
|
540 |
+
context=lv_extracted_text
|
541 |
+
)
|
542 |
+
|
543 |
+
# -- LLM Response
|
544 |
+
if lv_model:
|
545 |
+
lv_response = fn_chatllm_response(ui_llm_provider, lv_summarize_prompt_formatted, lv_model, ui_processing_message)
|
546 |
+
st.session_state.lv_response = lv_response
|
547 |
+
|
548 |
+
# -- Display LLM response
|
549 |
+
if lv_response and "Release Notes" in ui_user_actions:
|
550 |
+
lv_repaired = repair_json(lv_response, skip_json_loads=True)
|
551 |
+
if ui_show_json:
|
552 |
+
st.header("Release Notes")
|
553 |
+
st.json(lv_repaired)
|
554 |
+
else:
|
555 |
+
lv_markdown = fn_convert_release_notes_json_to_markdown(json.loads(lv_repaired))
|
556 |
+
st.markdown(lv_markdown)
|
557 |
+
|
558 |
+
with requirement_generation:
|
559 |
+
if ui_llm_provider and lv_extracted_text and not(lv_response) and "Requirement Generation" in ui_user_actions:
|
560 |
+
# -- Pydantice Schema
|
561 |
+
lv_parser = PydanticOutputParser(pydantic_object=rq.RequirementGatheringDetails)
|
562 |
+
|
563 |
+
# -- Creating Prompt
|
564 |
+
lv_template = pt.CN_REQUIREMENT_GATHERING
|
565 |
+
lv_summarize_prompt = PromptTemplate(
|
566 |
+
template=lv_template,
|
567 |
+
input_variables=["context"],
|
568 |
+
partial_variables={"format_instructions": lv_parser.get_format_instructions()},
|
569 |
+
)
|
570 |
+
lv_summarize_prompt_formatted = lv_summarize_prompt.format(
|
571 |
+
context=lv_extracted_text
|
572 |
+
)
|
573 |
+
|
574 |
+
# -- LLM Response
|
575 |
+
if lv_model:
|
576 |
+
lv_response = fn_chatllm_response(ui_llm_provider, lv_summarize_prompt_formatted, lv_model, ui_processing_message)
|
577 |
+
st.session_state.lv_response = lv_response
|
578 |
+
|
579 |
+
# -- Display LLM response
|
580 |
+
if lv_response and "Requirement Generation" in ui_user_actions:
|
581 |
+
lv_repaired = repair_json(lv_response, skip_json_loads=True)
|
582 |
+
|
583 |
+
if ui_show_json:
|
584 |
+
st.header("Requirement Generation")
|
585 |
+
st.json(lv_repaired)
|
586 |
+
else:
|
587 |
+
lv_markdown = fn_convert_requirement_generation_json_to_markdown(json.loads(lv_repaired))
|
588 |
+
st.markdown(lv_markdown)
|
589 |
+
|
590 |
+
with summarization:
|
591 |
+
if ui_llm_provider and "Summarization" in ui_user_actions:
|
592 |
+
st.header("Summarization")
|
593 |
+
st.text("")
|
594 |
+
st.text("")
|
595 |
+
|
596 |
+
ui_summary_input = st.text_area("Input Text", value=lv_extracted_text)
|
597 |
+
if st.button("Summarize",key="summary"):
|
598 |
+
# -- Creating Prompt
|
599 |
+
lv_template = pt.CN_SUMMARY
|
600 |
+
lv_summarize_prompt = PromptTemplate(
|
601 |
+
template=lv_template,
|
602 |
+
input_variables=["context"]
|
603 |
+
)
|
604 |
+
lv_summarize_prompt_formatted = lv_summarize_prompt.format(
|
605 |
+
context=ui_summary_input
|
606 |
+
)
|
607 |
+
|
608 |
+
# -- LLM Response
|
609 |
+
if lv_model:
|
610 |
+
lv_response = fn_chatllm_response(ui_llm_provider, lv_summarize_prompt_formatted, lv_model, ui_processing_message)
|
611 |
+
st.session_state.lv_response = lv_response
|
612 |
+
|
613 |
+
# -- Display LLM response
|
614 |
+
if lv_response:
|
615 |
+
st.subheader("Summary")
|
616 |
+
st.markdown(lv_response)
|
617 |
+
|
618 |
+
# Loading Main
|
619 |
+
if __name__ == "__main__":
|
620 |
+
main()
|
pdf-data/Rahul Kiran Gaddam - Resume.pdf
ADDED
Binary file (66.6 kB). View file
|
|
prompts.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CN_USER_STORY="""
|
2 |
+
Instruction:
|
3 |
+
- You are an AI assistant product manager that generates a detailed user story based on the provided context.
|
4 |
+
- Stories are tailored to create a Lending System for banking institutions.
|
5 |
+
- Generate Response in JSON Format only.
|
6 |
+
- Don't try to make up an answer.
|
7 |
+
- Only extract relevant information from the context.
|
8 |
+
- Remove any notes and suggestions in the response.
|
9 |
+
- Dont add any comments like ```json
|
10 |
+
- Avoid statement like This JSON object confirms to the following schema.
|
11 |
+
=======
|
12 |
+
{format_instructions}
|
13 |
+
=======
|
14 |
+
{context}
|
15 |
+
=======
|
16 |
+
Output:\n"""
|
17 |
+
|
18 |
+
CN_RELEASE_NOTES="""
|
19 |
+
Instruction:
|
20 |
+
- You are an AI assistant product technical document writer that generates a detailed release notes based on the provided context.
|
21 |
+
- This document is customer facing for the product Oracle Banking Retail Lending.
|
22 |
+
- Ensure the tone is professional, informative, and user-friendly, suitable for a diverse audience of Oracle Banking Retail Lending customers.
|
23 |
+
- Generate elaborate release notes details all the feature and do not missing details from the context provided.
|
24 |
+
- Generate Response in JSON Format only.
|
25 |
+
- Don't try to make up an answer.
|
26 |
+
- Only extract relevant information from the context.
|
27 |
+
- Remove any notes and suggestions in the response.
|
28 |
+
- Dont add any comments like ```json
|
29 |
+
- Avoid statement like This JSON object confirms to the following schema.
|
30 |
+
=======
|
31 |
+
{format_instructions}
|
32 |
+
=======
|
33 |
+
{context}
|
34 |
+
=======
|
35 |
+
Output:\n"""
|
36 |
+
|
37 |
+
CN_REQUIREMENT_GATHERING="""
|
38 |
+
Instruction:
|
39 |
+
- You are an AI assistant product manager designed to extract and organize requirements from legal documents into a detailed scope document.
|
40 |
+
- Your objective is to identify and group key requirements, while also highlighting areas of potential ambiguity that might need clarification.
|
41 |
+
- Generate Response in JSON Format only.
|
42 |
+
- Don't try to make up an answer.
|
43 |
+
- Only extract relevant information from the context.
|
44 |
+
- Remove any notes and suggestions in the response.
|
45 |
+
- Dont add any comments like ```json
|
46 |
+
- Avoid statement like This JSON object confirms to the following schema.
|
47 |
+
=======
|
48 |
+
{format_instructions}
|
49 |
+
=======
|
50 |
+
{context}
|
51 |
+
=======
|
52 |
+
Output:\n"""
|
53 |
+
|
54 |
+
CN_SUMMARY="""
|
55 |
+
IDENTITY and PURPOSE:
|
56 |
+
- You are an expert content summarizer.
|
57 |
+
- Don't try to make up an answer.
|
58 |
+
- Only extract relevant information from the context.
|
59 |
+
- You take content in and output a Markdown formatted summary using the format below.
|
60 |
+
- Take a deep breath and think step by step about how to best accomplish this goal using the following steps.
|
61 |
+
OUTPUT SECTIONS:
|
62 |
+
- Combine all of your understanding of the content into a single, 20-word sentence in a section called ONE SENTENCE SUMMARY:.
|
63 |
+
- Output the 10 most important points of the content as a list with no more than 15 words per point into a section called MAIN POINTS:.
|
64 |
+
- Output a list of the 5 best takeaways from the content in a section called TAKEAWAYS:.
|
65 |
+
- Output a list Text Classification identified in a section called CLASSIFICATION:.
|
66 |
+
- Output a list Entity Recognition identified in a section called ENTITY RECOGNITION:.
|
67 |
+
- Output a list Sentiment Analysis identified in a section called SENTIMENT:.
|
68 |
+
OUTPUT INSTRUCTIONS:
|
69 |
+
- Create the output using the formatting above.
|
70 |
+
- You only output human readable Markdown.
|
71 |
+
- Output numbered lists, not bullets.
|
72 |
+
- Do not output warnings or notes—just the requested sections.
|
73 |
+
- Do not repeat items in the output sections.
|
74 |
+
- Do not start items with the same opening words.
|
75 |
+
=======
|
76 |
+
{context}
|
77 |
+
=======
|
78 |
+
Output:\n"""
|