Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

main.py 3.0 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  1. import asyncio
  2. from database.chroma import get_chroma_collection, get_relevant_qa
  3. from database.duckdb import get_sample_questions
  4. from agents.response_evaluator import ResponseEvaluator
  5. from agents.question_generator import QuestionGenerator
  6. from multiprocessing import Pool
  7. from stt_tts.stt_tts import STT_TTS
  8. def generate_questions(skill_tested: str, sample_questions: list) -> str:
  9. """
  10. Generate questions based on the skill to be tested
  11. Parameters:
  12. -----------
  13. sample_questions: List of samples questions if any
  14. skill_tested: List of skills that needs to be tested
  15. Returns:
  16. -----------
  17. List of questions that are generated by the question generator
  18. """
  19. question_generator = QuestionGenerator()
  20. question_generator_question = question_generator.generate_question(
  21. skill_tested, sample_questions
  22. )
  23. return question_generator_question
  24. async def process_questions(questions: list, skills_to_test: str) -> list:
  25. """
  26. Async function to process questions based on the skills_to_test
  27. Parameters:
  28. -----------
  29. questions: List of questions to be processed
  30. skills_to_test: List of skills that needs to be tested
  31. Returns:
  32. -----------
  33. List of feedback along with questions and user responses
  34. """
  35. tasks = []
  36. db = get_chroma_collection("question_embeddings_v2")
  37. for question, skill_to_test in zip(questions, skills_to_test):
  38. print("Question: ", question)
  39. stt_tts = STT_TTS()
  40. question_audio = stt_tts.text_to_speech(question)
  41. print("Question audio: ", question_audio)
  42. try:
  43. relevant_qa = get_relevant_qa(db, question, skill_question_map[skill_to_test][1])
  44. except:
  45. print("No relavant questions found for this question generated by LLM")
  46. relevant_qa = []
  47. # print(relevant_qa)
  48. user_response_audio = input("Enter the audio wav filepath of response for the question:")
  49. user_response = stt_tts.speech_to_text(user_response_audio)
  50. # Call the async function while continuing to the next question
  51. evaluator = ResponseEvaluator()
  52. task = asyncio.create_task(
  53. evaluator.evaluate_response(question, user_response, skill_to_test, relevant_qa)
  54. )
  55. tasks.append(task)
  56. results = await asyncio.gather(*tasks)
  57. return results
  58. if __name__ == "__main__":
  59. skills_to_test = ["social", "speaking", "management", "technical"]
  60. company = "Salesforce"
  61. profile = "Business Development Manager"
  62. skill_question_map = {}
  63. for skill_to_test in skills_to_test:
  64. skill_question_map[skill_to_test] = get_sample_questions(company, profile, skill_to_test, 5)
  65. print(skill_question_map)
  66. sample_questions_list = [(k, v[0]) for k, v in skill_question_map.items()]
  67. # Creating a process Pool to generate all questions in parallel
  68. with Pool(4) as p:
  69. questions = p.starmap(generate_questions, sample_questions_list)
  70. # print(questions)
  71. feedback = asyncio.run(process_questions(questions, skills_to_test))
  72. print(feedback)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...