pazukdev commited on
Commit
0d3cece
·
verified ·
1 Parent(s): dc26b1e

Replace stub with call of genetic algorythm at AWS endpoint

Browse files
Files changed (1) hide show
  1. app.py +127 -34
app.py CHANGED
@@ -9,6 +9,7 @@ from langchain.agents import AgentExecutor, create_openai_functions_agent
9
  from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
10
  from langchain_core.messages import AIMessage, HumanMessage
11
  from langchain.tools import StructuredTool
 
12
 
13
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
14
 
@@ -35,53 +36,144 @@ def get_all_employees() -> str:
35
  """
36
  return repo_get_all_employees_from_database()
37
 
38
- def get_employees(number_of_employees: int, start_time: str, duration_hours: int) -> str:
 
 
 
39
  """
40
- A function to get a required number_of_employees that are available from tart_time during specified duration_hours.
41
  Args:
42
- number_of_employees (int): Required number of employees.
43
- start_time (str): Required start time.
44
- duration_hours (int): Required duration of the availability in hours.
 
45
  Returns:
46
- str: Employees list in json.
47
- """
48
- method_return_value_stub = '''
49
- {
50
- "employees": [
51
- {
52
- "id": 100,
53
- "name": "Lana Kane"
54
- }
55
- ]
56
- }
57
- '''
58
- return method_return_value_stub
 
 
 
 
 
 
 
59
 
60
- class GetAllEmployees(BaseModel):
 
61
  """
62
- Pydantic arguments schema for get_all_employees function
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  """
 
 
 
 
 
 
 
 
64
 
65
- class GetEmployees(BaseModel):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  """
67
- Pydantic arguments schema for get_employees function
68
  """
69
- number_of_employees: int = Field(..., description="Required number of employees")
70
- start_time: str = Field(..., description="Required start time")
71
- duration_hours: int = Field(..., description="Required duration of the availability in hours")
72
 
73
- llm = ChatOpenAI(temperature=1.0, model_name="gpt-3.5-turbo", openai_api_key=OPENAI_API_KEY)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  tools = [
76
  StructuredTool.from_function(
77
- func=get_all_employees,
78
- args_schema=GetAllEmployees,
79
- description="A function to get a list of all employees from database."
 
 
 
 
 
 
 
 
 
 
80
  ),
81
  StructuredTool.from_function(
82
- func=get_employees,
83
- args_schema=GetEmployees,
84
- description="A function to get a required number_of_employees that are available from tart_time during specified duration_hours."
85
  )
86
  ]
87
 
@@ -116,9 +208,10 @@ def predict(message, history):
116
  return gpt_output
117
 
118
  examples = [
119
- "Tell me please about yourself: who are you, what is your purpose, what tools do you have?",
120
  "List all employees",
121
- "I need 1 employee in given time slot: start time is March 11 2024 2 pm, duration 1 hour"
 
122
  ]
123
 
124
  description = '''
 
9
  from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
10
  from langchain_core.messages import AIMessage, HumanMessage
11
  from langchain.tools import StructuredTool
12
+ from datetime import datetime, timedelta
13
 
14
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
15
 
 
36
  """
37
  return repo_get_all_employees_from_database()
38
 
39
+ def get_interviewer_teams(
40
+ team_size: int,
41
+ division: str,
42
+ interview_level: str) -> str:
43
  """
44
+ A function to get all possible teams of interviewers.
45
  Args:
46
+ team_size: int - The number of interviewers in each team.
47
+ division: str - A division interviewers belong to.
48
+ interview_level: str - A level of interview. E.g. for Junior interview level we need interviewers level Junior or higher. For Middle - Middle and higher. And so on.
49
+
50
  Returns:
51
+ str: A list of interviewers teams in json.
52
+ """
53
+ return get_interviewer_teams_by_skills(
54
+ team_size=team_size,
55
+ division=division,
56
+ interview_level=interview_level,
57
+ skills=[])
58
+
59
+ def get_interviewer_teams_by_skills(
60
+ team_size: int,
61
+ division: str,
62
+ interview_level: str,
63
+ skills: list) -> str:
64
+ """
65
+ A function to get all possible teams of interviewers by their skills.
66
+ Args:
67
+ team_size: int - The number of interviewers in each team. Required parameter.
68
+ division: str - A division interviewers belong to. Required parameter.
69
+ interview_level: str - A level of interview. E.g. for Junior interview level we need interviewers level Junior or higher. For Middle - Middle and higher. And so on. Required parameter.
70
+ skills: list - Skills that an interviewers must have to be able to conduct an interview. Optional parameter.
71
 
72
+ Returns:
73
+ str: A list of interviewers teams in json.
74
  """
75
+ return get_interviewer_teams_by_skills_in_time_slot(
76
+ team_size=team_size,
77
+ division=division,
78
+ interview_level=interview_level,
79
+ start_date_time=None,
80
+ duration_hours=0,
81
+ skills=skills)
82
+
83
+ def get_interviewer_teams_by_skills_in_time_slot(
84
+ team_size: int,
85
+ division: str,
86
+ interview_level: str,
87
+ start_date_time: str,
88
+ duration_hours: int,
89
+ skills: list) -> str:
90
  """
91
+ A function to get all possible teams of interviewers by their skills in requested time slot.
92
+ Args:
93
+ team_size: int - The number of interviewers in each team. Required parameter.
94
+ division: str - A division interviewers belong to. Required parameter.
95
+ interview_level: str - A level of interview. E.g. for Junior interview level we need interviewers level Junior or higher. For Middle - Middle and higher. And so on. Required parameter.
96
+ start_date_time: str - Date and time of start of interview. Optional parameter.
97
+ duration_hours: int - Required duration of the availability in hours. Default value is 11.
98
+ skills: list - Skills that an interviewers must have to be able to conduct an interview. Optional parameter.
99
 
100
+ Returns:
101
+ str: A list of interviewers teams in json.
102
+ """
103
+
104
+ params = "?teamSize={team_size}&division={division}&interviewLevel={interview_level}".format(
105
+ team_size=team_size,
106
+ division=division,
107
+ interview_level=interview_level)
108
+
109
+ if start_date_time is not None:
110
+ end_date_time = start_date_time
111
+ start_date_time_obj = datetime.fromisoformat(start_date_time)
112
+ end_date_time_obj = start_date_time_obj + timedelta(hours=duration_hours)
113
+ end_date_time = end_date_time_obj.isoformat()
114
+ optional_params = "&startDateTime={start}&endDateTime={end}".format(start=start_date_time, end=end_date_time)
115
+ params += optional_params
116
+
117
+ basic_url = "http://18.133.247.78/search/interviewerTeams"
118
+ url = basic_url + params
119
+ print(params)
120
+ return requests.get(url).content
121
+
122
+ class GetAllInterviewers(BaseModel):
123
  """
124
+ Pydantic arguments schema for get_all_interviewers function
125
  """
 
 
 
126
 
127
+ class GetInterviewerTeams(BaseModel):
128
+ """
129
+ Pydantic arguments schema for get_interviewer_teams function
130
+ """
131
+ team_size: int = Field(..., description="The number of interviewers in each team. Required parameter.")
132
+ division: str = Field(..., description="A division interviewers belong to. Required parameter.")
133
+ interview_level: str = Field(..., description="A level of interview. E.g. for Junior interview level we need interviewers level Junior or higher. For Middle - Middle and higher. And so on. Required parameter.")
134
+
135
+ class GetInterviewerTeamsBySkills(BaseModel):
136
+ """
137
+ Pydantic arguments schema for get_interviewer_teams_by_skills function
138
+ """
139
+ team_size: int = Field(..., description="The number of interviewers in each team. Required parameter.")
140
+ division: str = Field(..., description="A division interviewers belong to. Required parameter.")
141
+ interview_level: str = Field(..., description="A level of interview. E.g. for Junior interview level we need interviewers level Junior or higher. For Middle - Middle and higher. And so on. Required parameter.")
142
+ skills: list = Field(..., description="Skills that an interviewers must have to be able to conduct an interview. Optional parameter.")
143
+
144
+ class GetInterviewerTeamsBySkillsInTimeSlot(BaseModel):
145
+ """
146
+ Pydantic arguments schema for get_interviewer_teams_by_skills_in_time_slot function
147
+ """
148
+ team_size: int = Field(..., description="The number of interviewers in each team. Required parameter.")
149
+ division: str = Field(..., description="A division interviewers belong to. Required parameter.")
150
+ interview_level: str = Field(..., description="A level of interview. E.g. for Junior interview level we need interviewers level Junior or higher. For Middle - Middle and higher. And so on. Required parameter.")
151
+ start_date_time: str = Field(..., description="Date and time of start of interview. Optional parameter.")
152
+ duration_hours: int = Field(..., description="Required duration of the availability in hours. Optional parameter.")
153
+ skills: list = Field(..., description="Skills that an interviewers must have to be able to conduct an interview. Optional parameter.")
154
+
155
+ llm = ChatOpenAI(temperature=0.0, model_name="gpt-3.5-turbo", openai_api_key=OPENAI_API_KEY)
156
 
157
  tools = [
158
  StructuredTool.from_function(
159
+ func=get_all_interviewers,
160
+ args_schema=GetAllInterviewers,
161
+ description="A function to get a list of all interviewers from database."
162
+ ),
163
+ StructuredTool.from_function(
164
+ func=get_interviewer_teams,
165
+ args_schema=GetInterviewerTeams,
166
+ description="A function to get all possible teams of interviewers."
167
+ ),
168
+ StructuredTool.from_function(
169
+ func=get_interviewer_teams_by_skills,
170
+ args_schema=GetInterviewerTeamsBySkills,
171
+ description="A function to get all possible teams of interviewers by their skills."
172
  ),
173
  StructuredTool.from_function(
174
+ func=get_interviewer_teams_by_skills_in_time_slot,
175
+ args_schema=GetInterviewerTeamsBySkillsInTimeSlot,
176
+ description="A function to get all possible teams of interviewers by their skills in requested time slot."
177
  )
178
  ]
179
 
 
208
  return gpt_output
209
 
210
  examples = [
211
+ "Hello! Tell me please about yourself: who are you, what is your purpose, what tools do you have?",
212
  "List all employees",
213
+ "I need a team of 2 interviewers from Java division who can interview Senior level newcomers",
214
+ "I need a team of 2 interviewers from Java division with Java and SQL skills who can interview Senior level newcomers in given time slot: start time is 2024-02-12T11:00:00, duration 1 hour"
215
  ]
216
 
217
  description = '''