Spaces:
Runtime error
Runtime error
jess commited on
Commit ·
b645eee
1
Parent(s): e4b7aa4
chore: remove sample before async def clean_sample_answers(text):
Browse files- Project.py +2 -2
- app.py +2 -14
- common_functions_v4.py +80 -38
- prompt_configs.py +1 -1
Project.py
CHANGED
|
@@ -228,8 +228,8 @@ class Project:
|
|
| 228 |
# Execute prompt with appropriate model
|
| 229 |
result = (
|
| 230 |
await async_call_4o_mini(prompt)
|
| 231 |
-
|
| 232 |
-
|
| 233 |
)
|
| 234 |
# print(f"Result from executing prompt: {result[:800]}")
|
| 235 |
|
|
|
|
| 228 |
# Execute prompt with appropriate model
|
| 229 |
result = (
|
| 230 |
await async_call_4o_mini(prompt)
|
| 231 |
+
if config.model == ModelType.O1_MINI
|
| 232 |
+
else await async_call_o1_mini(prompt)
|
| 233 |
)
|
| 234 |
# print(f"Result from executing prompt: {result[:800]}")
|
| 235 |
|
app.py
CHANGED
|
@@ -394,9 +394,7 @@ with gr.Blocks(title="Quotation Chatbot (with SOW)", css=custom_css) as demo:
|
|
| 394 |
|
| 395 |
with gr.Row():
|
| 396 |
with gr.Column(scale=1):
|
| 397 |
-
current_question = gr.Textbox(label="Edit Area", lines=
|
| 398 |
-
submit_btn = gr.Button("Submit")
|
| 399 |
-
clear_btn = gr.Button("Clear Chat")
|
| 400 |
with gr.Column(scale=1):
|
| 401 |
chatbot = gr.Chatbot(height=580 ,elem_classes=["chatbot-container"])
|
| 402 |
gr.ChatInterface(
|
|
@@ -455,17 +453,7 @@ with gr.Blocks(title="Quotation Chatbot (with SOW)", css=custom_css) as demo:
|
|
| 455 |
outputs=[current_question, current_session_display]
|
| 456 |
)
|
| 457 |
|
| 458 |
-
|
| 459 |
-
fn=lambda answer, history: (*process_response(answer, history), *get_project_state()),
|
| 460 |
-
inputs=[current_question, chatbot],
|
| 461 |
-
outputs=[chatbot, current_question]
|
| 462 |
-
)
|
| 463 |
-
|
| 464 |
-
clear_btn.click(
|
| 465 |
-
fn=lambda: ([], ""),
|
| 466 |
-
outputs=[chatbot, current_question]
|
| 467 |
-
)
|
| 468 |
-
|
| 469 |
fetch_btn.click(
|
| 470 |
fn=fetch_session,
|
| 471 |
inputs=[session_input],
|
|
|
|
| 394 |
|
| 395 |
with gr.Row():
|
| 396 |
with gr.Column(scale=1):
|
| 397 |
+
current_question = gr.Textbox(label="Edit Area", lines=30, interactive=True)
|
|
|
|
|
|
|
| 398 |
with gr.Column(scale=1):
|
| 399 |
chatbot = gr.Chatbot(height=580 ,elem_classes=["chatbot-container"])
|
| 400 |
gr.ChatInterface(
|
|
|
|
| 453 |
outputs=[current_question, current_session_display]
|
| 454 |
)
|
| 455 |
|
| 456 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
fetch_btn.click(
|
| 458 |
fn=fetch_session,
|
| 459 |
inputs=[session_input],
|
common_functions_v4.py
CHANGED
|
@@ -23,6 +23,7 @@ no_active_session = "**Current Session**:None"
|
|
| 23 |
class SLEEP_TIME(Enum):
|
| 24 |
"""Enum class containing sleep time constants."""
|
| 25 |
ONE_AND_HALF_SEC = 1.5 # Default sleep time in seconds
|
|
|
|
| 26 |
THREE_SEC = 3 # Default sleep time in seconds
|
| 27 |
|
| 28 |
load_dotenv()
|
|
@@ -271,16 +272,57 @@ async def clean_sample_answers(text):
|
|
| 271 |
try:
|
| 272 |
if not text:
|
| 273 |
return text
|
| 274 |
-
|
| 275 |
# Updated regex to handle optional parentheses
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
cleaned_text = re.sub(
|
| 277 |
-
r'(?i)
|
| 278 |
-
'
|
| 279 |
text,
|
| 280 |
-
flags=re.MULTILINE
|
| 281 |
)
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
return cleaned_text
|
|
|
|
| 284 |
except Exception as e:
|
| 285 |
print(f"Error cleaning sample answers: {e}")
|
| 286 |
return text
|
|
@@ -307,8 +349,8 @@ async def async_process_response(answer, history):
|
|
| 307 |
sanitized_answer = sanitize_text(str(answer))
|
| 308 |
|
| 309 |
# print("[DEBUG] Adding project detail")
|
| 310 |
-
|
| 311 |
-
|
| 312 |
|
| 313 |
start_time = time.time()
|
| 314 |
|
|
@@ -319,24 +361,24 @@ async def async_process_response(answer, history):
|
|
| 319 |
)
|
| 320 |
yield response, ""
|
| 321 |
|
| 322 |
-
function_to_run = state.quotation_project.
|
| 323 |
-
current_thoughts = PROMPTS["
|
| 324 |
|
| 325 |
project_detail_len = len(state.quotation_project.project_detail)
|
| 326 |
|
| 327 |
-
if project_detail_len ==
|
| 328 |
function_to_run = state.quotation_project.generate_client_follow_up
|
| 329 |
current_thoughts = PROMPTS["generate_client_follow_up"].thoughts
|
| 330 |
|
| 331 |
-
elif project_detail_len ==
|
| 332 |
function_to_run = lambda: run_question_agent(state.quotation_project)
|
| 333 |
current_thoughts = PROMPTS["generate_client_follow_up"].thoughts
|
| 334 |
|
| 335 |
-
elif project_detail_len ==
|
| 336 |
function_to_run = state.quotation_project.generate_general_questions
|
| 337 |
current_thoughts = PROMPTS["generate_general_questions"].thoughts
|
| 338 |
|
| 339 |
-
elif project_detail_len >=
|
| 340 |
function_to_run = state.quotation_project.generate_further_follow_up_questions
|
| 341 |
current_thoughts = PROMPTS["generate_further_follow_up_questions"].thoughts
|
| 342 |
|
|
@@ -359,7 +401,7 @@ async def async_process_response(answer, history):
|
|
| 359 |
thought_index += 1
|
| 360 |
# print(f"[DEBUG] Current thought: {thought}")
|
| 361 |
|
| 362 |
-
await asyncio.sleep(SLEEP_TIME.
|
| 363 |
accumulated_thoughts += f"- {thought}\n\n"
|
| 364 |
response.content = accumulated_thoughts.strip()
|
| 365 |
# print(f"[DEBUG] Yielding updated thoughts: {response.content}")
|
|
@@ -446,30 +488,30 @@ def calculate_mvp_mandays_and_costs(generated_mvp_results):
|
|
| 446 |
def create_new_session():
|
| 447 |
"""Create a new session in the database and return the session_id"""
|
| 448 |
try:
|
| 449 |
-
conn = get_db_connection()
|
| 450 |
-
cur = conn.cursor()
|
| 451 |
-
|
| 452 |
-
# Insert new session with start time
|
| 453 |
-
cur.execute("""
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
""")
|
| 458 |
-
|
| 459 |
-
session_id = cur.fetchone()[0]
|
| 460 |
-
|
| 461 |
-
# Insert session_base_project record for "Page"
|
| 462 |
-
cur.execute("""
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
""", (session_id,))
|
| 466 |
-
|
| 467 |
-
conn.commit()
|
| 468 |
-
cur.close()
|
| 469 |
-
conn.close()
|
| 470 |
-
|
| 471 |
-
return session_id
|
| 472 |
-
|
| 473 |
except Exception as e:
|
| 474 |
print(f"Error creating new session: {str(e)}")
|
| 475 |
return None
|
|
|
|
| 23 |
class SLEEP_TIME(Enum):
|
| 24 |
"""Enum class containing sleep time constants."""
|
| 25 |
ONE_AND_HALF_SEC = 1.5 # Default sleep time in seconds
|
| 26 |
+
TWO_SEC = 1.8 # Default sleep time in seconds
|
| 27 |
THREE_SEC = 3 # Default sleep time in seconds
|
| 28 |
|
| 29 |
load_dotenv()
|
|
|
|
| 272 |
try:
|
| 273 |
if not text:
|
| 274 |
return text
|
| 275 |
+
print("Starting to clean sample answers...")
|
| 276 |
# Updated regex to handle optional parentheses
|
| 277 |
+
# pattern = r'\(?\s*Sample(?:\s*Answer)?\s*:\\s*.*?\)?'
|
| 278 |
+
# cleaned_text = re.sub(pattern, 'Answer:', text, flags=re.IGNORECASE | re.DOTALL)
|
| 279 |
+
|
| 280 |
+
# pattern = re.compile(
|
| 281 |
+
# r'\(?\s*(?:Sample(?:\s*Answer)?):\s*.*?\)?',
|
| 282 |
+
# flags=re.IGNORECASE | re.DOTALL
|
| 283 |
+
# )
|
| 284 |
+
# cleaned_text = re.sub(pattern, 'Answer:', text)
|
| 285 |
+
|
| 286 |
+
# cleaned_text = re.sub(
|
| 287 |
+
# r'(?i)[\(\[]?\s*Sample\s*:\s*"[^"]*"\s*[\)\]]?',
|
| 288 |
+
# 'Answer:',
|
| 289 |
+
# text,
|
| 290 |
+
# flags=re.MULTILINE
|
| 291 |
+
# )
|
| 292 |
+
|
| 293 |
+
# cleaned_text = re.sub(r'(?i)\s*Sample\s*:\s*"[^"]*"', '\nAnswer:', text, flags=re.MULTILINE)
|
| 294 |
+
# cleaned_text = re.sub(
|
| 295 |
+
# r'(?i)\s*\(?\s*Sample\s*:\s*"[^"]*"\)?',
|
| 296 |
+
# '\nAnswer:',
|
| 297 |
+
# cleaned_text,
|
| 298 |
+
# flags=re.MULTILINE
|
| 299 |
+
# )
|
| 300 |
+
|
| 301 |
+
# Case 1 : overs both quoted and unquoted cases, with or without parentheses:
|
| 302 |
+
# cleaned_text = re.sub(
|
| 303 |
+
# r'(?i)\s*\(?\s*Sample\s*:\s*(?:"[^"]*"|[^)\n]*)\)?',
|
| 304 |
+
# '\nAnswer:',
|
| 305 |
+
# text,
|
| 306 |
+
# flags=re.MULTILINE
|
| 307 |
+
# )
|
| 308 |
+
|
| 309 |
+
# this works
|
| 310 |
cleaned_text = re.sub(
|
| 311 |
+
r'(?i)\s*(?:\(|\*)?\s*Sample(?:\s*Answer)?\s*:\s*(?:"[^"]*"|[^\)\*\n]*)\s*(?:\)|\*)?',
|
| 312 |
+
'\nAnswer:',
|
| 313 |
text,
|
| 314 |
+
flags=re.MULTILINE
|
| 315 |
)
|
| 316 |
+
|
| 317 |
+
cleaned_text = re.sub(
|
| 318 |
+
r'(?i)\s*(?:\(|\*)?\s*Sample(?:\s*Answers?)?\s*:\s*(?:"[^"]*"|[^\)\*\n]*)\s*(?:\)|\*)?',
|
| 319 |
+
'\nAnswer:',
|
| 320 |
+
text,
|
| 321 |
+
flags=re.MULTILINE
|
| 322 |
+
)
|
| 323 |
+
print("Sample answers cleaned successfully.")
|
| 324 |
return cleaned_text
|
| 325 |
+
# return cleaned_text
|
| 326 |
except Exception as e:
|
| 327 |
print(f"Error cleaning sample answers: {e}")
|
| 328 |
return text
|
|
|
|
| 349 |
sanitized_answer = sanitize_text(str(answer))
|
| 350 |
|
| 351 |
# print("[DEBUG] Adding project detail")
|
| 352 |
+
if sanitized_answer is not None and len(sanitized_answer) > 0:
|
| 353 |
+
state.quotation_project.add_project_detail(sanitized_answer)
|
| 354 |
|
| 355 |
start_time = time.time()
|
| 356 |
|
|
|
|
| 361 |
)
|
| 362 |
yield response, ""
|
| 363 |
|
| 364 |
+
# function_to_run = state.quotation_project.generate_client_follow_up
|
| 365 |
+
# current_thoughts = PROMPTS["generate_client_follow_up"].thoughts
|
| 366 |
|
| 367 |
project_detail_len = len(state.quotation_project.project_detail)
|
| 368 |
|
| 369 |
+
if project_detail_len == 1:
|
| 370 |
function_to_run = state.quotation_project.generate_client_follow_up
|
| 371 |
current_thoughts = PROMPTS["generate_client_follow_up"].thoughts
|
| 372 |
|
| 373 |
+
elif project_detail_len == 2:
|
| 374 |
function_to_run = lambda: run_question_agent(state.quotation_project)
|
| 375 |
current_thoughts = PROMPTS["generate_client_follow_up"].thoughts
|
| 376 |
|
| 377 |
+
elif project_detail_len == 3:
|
| 378 |
function_to_run = state.quotation_project.generate_general_questions
|
| 379 |
current_thoughts = PROMPTS["generate_general_questions"].thoughts
|
| 380 |
|
| 381 |
+
elif project_detail_len >= 4:
|
| 382 |
function_to_run = state.quotation_project.generate_further_follow_up_questions
|
| 383 |
current_thoughts = PROMPTS["generate_further_follow_up_questions"].thoughts
|
| 384 |
|
|
|
|
| 401 |
thought_index += 1
|
| 402 |
# print(f"[DEBUG] Current thought: {thought}")
|
| 403 |
|
| 404 |
+
await asyncio.sleep(SLEEP_TIME.TWO_SEC.value)
|
| 405 |
accumulated_thoughts += f"- {thought}\n\n"
|
| 406 |
response.content = accumulated_thoughts.strip()
|
| 407 |
# print(f"[DEBUG] Yielding updated thoughts: {response.content}")
|
|
|
|
| 488 |
def create_new_session():
|
| 489 |
"""Create a new session in the database and return the session_id"""
|
| 490 |
try:
|
| 491 |
+
# conn = get_db_connection()
|
| 492 |
+
# cur = conn.cursor()
|
| 493 |
+
|
| 494 |
+
# # Insert new session with start time
|
| 495 |
+
# cur.execute("""
|
| 496 |
+
# INSERT INTO sessions (start_time)
|
| 497 |
+
# VALUES (CURRENT_TIMESTAMP)
|
| 498 |
+
# RETURNING session_id
|
| 499 |
+
# """)
|
| 500 |
+
|
| 501 |
+
# session_id = cur.fetchone()[0]
|
| 502 |
+
|
| 503 |
+
# # Insert session_base_project record for "Page"
|
| 504 |
+
# cur.execute("""
|
| 505 |
+
# INSERT INTO session_base_project (session_id, base_project_name)
|
| 506 |
+
# VALUES (%s, 'Page')
|
| 507 |
+
# """, (session_id,))
|
| 508 |
+
|
| 509 |
+
# conn.commit()
|
| 510 |
+
# cur.close()
|
| 511 |
+
# conn.close()
|
| 512 |
+
|
| 513 |
+
# return session_id
|
| 514 |
+
return 161
|
| 515 |
except Exception as e:
|
| 516 |
print(f"Error creating new session: {str(e)}")
|
| 517 |
return None
|
prompt_configs.py
CHANGED
|
@@ -292,7 +292,7 @@ PROMPTS = {
|
|
| 292 |
"client_initial_question": PromptConfig(
|
| 293 |
prompt=
|
| 294 |
"""
|
| 295 |
-
|
| 296 |
|
| 297 |
### Company Background and Industry
|
| 298 |
1. Can you provide some background about your company?
|
|
|
|
| 292 |
"client_initial_question": PromptConfig(
|
| 293 |
prompt=
|
| 294 |
"""
|
| 295 |
+
Client Information Gathering Questions
|
| 296 |
|
| 297 |
### Company Background and Industry
|
| 298 |
1. Can you provide some background about your company?
|