Spaces:
Runtime error
Runtime error
jess commited on
Commit ·
2a9812a
1
Parent(s): 6801443
add: question agent partially functional
Browse files- Project.py +4 -0
- common_functions_v4.py +50 -40
- prompt_configs.py +10 -0
Project.py
CHANGED
|
@@ -265,6 +265,10 @@ class Project:
|
|
| 265 |
for output in config.outputs:
|
| 266 |
setattr(self, output, "")
|
| 267 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
async def generate_client_follow_up(self):
|
| 269 |
"""Generate follow-up questions after initial client response"""
|
| 270 |
return await self.async_execute_prompt(
|
|
|
|
| 265 |
for output in config.outputs:
|
| 266 |
setattr(self, output, "")
|
| 267 |
|
| 268 |
+
async def generate_client_initial_question(self):
|
| 269 |
+
"""Generate follow-up questions after initial client response"""
|
| 270 |
+
return PROMPTS["client_initial_question"].prompt
|
| 271 |
+
|
| 272 |
async def generate_client_follow_up(self):
|
| 273 |
"""Generate follow-up questions after initial client response"""
|
| 274 |
return await self.async_execute_prompt(
|
common_functions_v4.py
CHANGED
|
@@ -277,7 +277,7 @@ async def clean_sample_answers(text):
|
|
| 277 |
r'(?i)[\(\[]?\s*Sample\s*:\s*"[^"]*"\s*[\)\]]?',
|
| 278 |
'Answer:',
|
| 279 |
text,
|
| 280 |
-
flags=re.MULTILINE
|
| 281 |
)
|
| 282 |
|
| 283 |
return cleaned_text
|
|
@@ -288,19 +288,7 @@ async def clean_sample_answers(text):
|
|
| 288 |
# Example usage:
|
| 289 |
# chat_history = [{'role': 'user', ...}, {'role': 'assistant', ...}]
|
| 290 |
# log_chat_history(chat_history)
|
| 291 |
-
#
|
| 292 |
-
# next_question = state.quotation_project.generate_client_follow_up()
|
| 293 |
-
# elif len(history) == 2:
|
| 294 |
-
# # Get configuration output
|
| 295 |
-
# next_question = validate_project_choice(answer,state.quotation_project)
|
| 296 |
-
# # next_question = result
|
| 297 |
-
# elif len(history) == 3: # After specific questioning, run general questions
|
| 298 |
-
# next_question = state.quotation_project.generate_general_questions()
|
| 299 |
-
|
| 300 |
-
# else: # Subsequent project requirements questions
|
| 301 |
-
# # next_question = quotation_project.generate_follow_up()
|
| 302 |
-
# next_question = state.quotation_project.generate_further_follow_up_questions()
|
| 303 |
-
|
| 304 |
#TODO: Ensure it directs towards correct question
|
| 305 |
async def async_process_response(answer, history):
|
| 306 |
"""Process user responses and generate appropriate follow-up questions."""
|
|
@@ -330,10 +318,32 @@ async def async_process_response(answer, history):
|
|
| 330 |
metadata={"title": "_Processing_ step-by-step", "id": 0, "status": "pending"}
|
| 331 |
)
|
| 332 |
yield response, ""
|
| 333 |
-
|
|
|
|
| 334 |
current_thoughts = PROMPTS["client_initial_question"].thoughts
|
|
|
|
|
|
|
| 335 |
|
| 336 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
|
| 338 |
# Update project detail with new list;
|
| 339 |
if state.quotation_project.session_id:
|
|
@@ -436,30 +446,30 @@ def calculate_mvp_mandays_and_costs(generated_mvp_results):
|
|
| 436 |
def create_new_session():
|
| 437 |
"""Create a new session in the database and return the session_id"""
|
| 438 |
try:
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
#
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
#
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
return 151
|
| 463 |
except Exception as e:
|
| 464 |
print(f"Error creating new session: {str(e)}")
|
| 465 |
return None
|
|
|
|
| 277 |
r'(?i)[\(\[]?\s*Sample\s*:\s*"[^"]*"\s*[\)\]]?',
|
| 278 |
'Answer:',
|
| 279 |
text,
|
| 280 |
+
flags=re.MULTILINE | re.IGNORECASE
|
| 281 |
)
|
| 282 |
|
| 283 |
return cleaned_text
|
|
|
|
| 288 |
# Example usage:
|
| 289 |
# chat_history = [{'role': 'user', ...}, {'role': 'assistant', ...}]
|
| 290 |
# log_chat_history(chat_history)
|
| 291 |
+
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
#TODO: Ensure it directs towards correct question
|
| 293 |
async def async_process_response(answer, history):
|
| 294 |
"""Process user responses and generate appropriate follow-up questions."""
|
|
|
|
| 318 |
metadata={"title": "_Processing_ step-by-step", "id": 0, "status": "pending"}
|
| 319 |
)
|
| 320 |
yield response, ""
|
| 321 |
+
|
| 322 |
+
function_to_run = state.quotation_project.generate_client_initial_question
|
| 323 |
current_thoughts = PROMPTS["client_initial_question"].thoughts
|
| 324 |
+
|
| 325 |
+
project_detail_len = len(state.quotation_project.project_detail)
|
| 326 |
|
| 327 |
+
if project_detail_len == 2:
|
| 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 == 3:
|
| 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 == 4:
|
| 336 |
+
function_to_run = state.quotation_project.generate_general_questions
|
| 337 |
+
current_thoughts = PROMPTS["generate_general_questions"].thoughts
|
| 338 |
+
|
| 339 |
+
elif project_detail_len >= 5:
|
| 340 |
+
function_to_run = state.quotation_project.generate_further_follow_up_questions
|
| 341 |
+
current_thoughts = PROMPTS["generate_further_follow_up_questions"].thoughts
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
|
| 346 |
+
next_question_task = asyncio.create_task(function_to_run())
|
| 347 |
|
| 348 |
# Update project detail with new list;
|
| 349 |
if state.quotation_project.session_id:
|
|
|
|
| 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 |
+
INSERT INTO sessions (start_time)
|
| 455 |
+
VALUES (CURRENT_TIMESTAMP)
|
| 456 |
+
RETURNING session_id
|
| 457 |
+
""")
|
| 458 |
+
|
| 459 |
+
session_id = cur.fetchone()[0]
|
| 460 |
+
|
| 461 |
+
# Insert session_base_project record for "Page"
|
| 462 |
+
cur.execute("""
|
| 463 |
+
INSERT INTO session_base_project (session_id, base_project_name)
|
| 464 |
+
VALUES (%s, 'Page')
|
| 465 |
+
""", (session_id,))
|
| 466 |
+
|
| 467 |
+
conn.commit()
|
| 468 |
+
cur.close()
|
| 469 |
+
conn.close()
|
| 470 |
+
|
| 471 |
+
return session_id
|
| 472 |
+
# return 151
|
| 473 |
except Exception as e:
|
| 474 |
print(f"Error creating new session: {str(e)}")
|
| 475 |
return None
|
prompt_configs.py
CHANGED
|
@@ -142,6 +142,16 @@ PROMPTS = {
|
|
| 142 |
show_copy_button=True
|
| 143 |
)
|
| 144 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
),
|
| 146 |
|
| 147 |
"component_agent": PromptConfig(
|
|
|
|
| 142 |
show_copy_button=True
|
| 143 |
)
|
| 144 |
},
|
| 145 |
+
thoughts=[
|
| 146 |
+
"Read the project detail and function list.",
|
| 147 |
+
"Identify the project requirements and function list.",
|
| 148 |
+
"Determine the project configuration type.",
|
| 149 |
+
"Output a JSON object with the configuration type and selected functions.",
|
| 150 |
+
"Running the selected functions to generate questions.",
|
| 151 |
+
"Analyzing the project requirements to determine the best question set.",
|
| 152 |
+
"Generating context-aware questions based on the project type.",
|
| 153 |
+
"Formatting the output with sample answers for clarity."
|
| 154 |
+
],
|
| 155 |
),
|
| 156 |
|
| 157 |
"component_agent": PromptConfig(
|