pazukdev commited on
Commit
8d6f4a3
·
verified ·
1 Parent(s): b41032f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +139 -0
app.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from openai import OpenAI
2
+ from datetime import datetime, timedelta
3
+ import gradio as gr
4
+ import os
5
+ import re
6
+ import requests
7
+
8
+ api_key = os.getenv("OPENAIKEY")
9
+ client = OpenAI(api_key=api_key)
10
+
11
+ auth_token = os.getenv("DB_AUTH_TOKEN")
12
+
13
+ def repo_get_all_employees_from_database():
14
+ url = "https://api.airtable.com/v0/appopGmlHujYnd6Vw/Interviewers?maxRecords=100&view=Grid%20view"
15
+ headers = {
16
+ "Authorization": auth_token
17
+ }
18
+ response = requests.get(url, headers=headers)
19
+ records = response.json()
20
+ # print("records:")
21
+ # print(records)
22
+ records_list = records['records']
23
+ employees_list = []
24
+ for record in records_list:
25
+ employee = record["fields"]
26
+ employees_list.append(employee)
27
+
28
+ return employees_list
29
+
30
+ def predict(message, history):
31
+
32
+ # print("message:")
33
+ # print(message)
34
+
35
+ history_openai_format = []
36
+
37
+ # first_message = len(history) == 0
38
+
39
+ system_content = """
40
+ You are a computing system that strictly and directly follows all instructions from the user..
41
+ """
42
+ history_openai_format.append({"role": "system", "content": system_content})
43
+
44
+ pattern = r"For conducting an interview I need (\d+) employee.*start time is (.*), duration (\d+) hour"
45
+
46
+ data = repo_get_all_employees_from_database()
47
+
48
+ prompt = '''
49
+ {data}
50
+ ###
51
+ Above is employees data in json format.
52
+ {message}
53
+ '''.format(data=data, message=message)
54
+
55
+ # print("prompt:")
56
+ # print(prompt)
57
+
58
+ match = re.search(pattern, message)
59
+
60
+ # print("match:")
61
+ # print(match)
62
+
63
+ if match:
64
+ num_employees = int(match.group(1))
65
+ duration = int(match.group(3))
66
+ start_time = datetime.strptime(match.group(2), "%B %d %Y %I %p")
67
+ end_time = end_time = start_time + timedelta(hours=duration)
68
+
69
+ date_time = '''
70
+ "start_date_time": "{start_time}", "end_date_time": "{end_time}"
71
+ '''.format(start_time=start_time, end_time=end_time)
72
+
73
+ prompt = '''
74
+ {data}
75
+ ###
76
+ Above is employees data in json format.
77
+ Please choose {num_employees} employee with the lowest "interviews_conducted" value but whose "busy_dat_time_slots" doesn't contain the "given_date_time_slot" which is: {date_time}.
78
+ You should NOT output any Python code.
79
+ Lets think step-by-step:
80
+ 1. Remove the employees whose "busy_date_time_slots" CONTAINS the "given_date_time_slot" specified above. Provide a list of names of remaining employees.
81
+ 2. Double check your filtration. It's very important NOT to include into the remained employees list an employee whose "busy_date_time_slots" CONTAINS the "given_date_time_slot" . Type a "given_date_time_slot" value and then check that no one of remaining employees has no "given_date_time_slot" value in "busy_dat_time_slots". If someone contains - replase him.
82
+ 3. Provide a list of names of remaining employees along with their "interviews_conducted" values and choose {num_employees} employee with the lowest "interviews_conducted" value.
83
+ 4. Check previous step if you really chose an employee with the lowest "interviews_conducted" value.
84
+ 5. At the end print ids and names of finally selected employees in json format. Please remember that in your output should be maximum {num_employees} employee.
85
+ '''.format(data=data, date_time=date_time, num_employees=num_employees)
86
+
87
+
88
+ # print("prompt:")
89
+ # print(prompt)
90
+
91
+ # print("history:")
92
+ # print(history)
93
+
94
+ for human, assistant in history:
95
+ history_openai_format.append({"role": "user", "content": human })
96
+ history_openai_format.append({"role": "assistant", "content": assistant})
97
+ history_openai_format.append({"role": "user", "content": prompt})
98
+
99
+ model = "gpt-3.5-turbo"
100
+ if ("switch to gpt-3.5" in message.lower()):
101
+ model = "gpt-3.5-turbo"
102
+ print("Switched to:")
103
+ print(model)
104
+
105
+ if ("switch to gpt-4" in message.lower()):
106
+ model = "gpt-4"
107
+ print("Switched to:")
108
+ print(model)
109
+
110
+ print("Actual model:")
111
+ print(model)
112
+
113
+ response = client.chat.completions.create(
114
+ model="gpt-4",
115
+ messages= history_openai_format,
116
+ temperature=0,
117
+ stream=True)
118
+
119
+ partial_message = ""
120
+ for chunk in response:
121
+ if chunk.choices[0].delta.content is not None:
122
+ partial_message = partial_message + chunk.choices[0].delta.content
123
+ yield partial_message
124
+
125
+ pre_configured_promt = "For conducting an interview I need 1 employee in given time slot: start time is March 11 2024 2 pm, duration 1 hour"
126
+
127
+ description = '''
128
+ # AI Interview Team Assistant | Empowered by Godel Technologies AI \n
129
+ \n
130
+ This is an AI Interview Team Assistant. You can ask him any questions about recruiting a team for an interview.\n
131
+ \n
132
+ You can send any regular prompts you wish or pre-configured Chain-of-Thought prompts.\n
133
+ To trigger pre-configured prompt you have to craft a prompt with next structure:
134
+ - "{pre_configured_promt}"
135
+ '''.format(pre_configured_promt=pre_configured_promt)
136
+
137
+ examples = [pre_configured_promt]
138
+ additional_inputs = [gr.Dropdown(value=["gpt-3-turbo", "gpt-4"], label="Model")]
139
+ gr.ChatInterface(predict, examples=[examples], description=description).launch()