Alexander Hux commited on
Commit
6b98acb
·
1 Parent(s): 1a0255d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+
4
+ openai.api_key = "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"
5
+
6
+ messages = [{"role": "system", "content": "You are a knowledgeable assistant specialized in recruiting and hiring, and familiar with ADP Workforce Now Recruitment and various hiring and CRM tools."}]
7
+
8
+ def CustomChatGPT(user_input):
9
+ messages.append({"role": "user", "content": user_input})
10
+
11
+ # Ensure the conversation fits within the model's maximum token limit
12
+ conversation = messages[-4096:]
13
+
14
+ try:
15
+ response = openai.ChatCompletion.create(
16
+ model="gpt-3.5-turbo",
17
+ messages=conversation,
18
+ max_tokens=1000,
19
+ temperature=0.7)
20
+ except openai.api_resources.request_error.RequestError as e:
21
+ print(f"Received error from OpenAI: {e}")
22
+ return "I'm sorry, but I'm unable to generate a response at this time."
23
+
24
+ ChatGPT_reply = response["choices"][0]["message"]["content"]
25
+ messages.append({"role": "assistant", "content": ChatGPT_reply})
26
+ return ChatGPT_reply
27
+
28
+ interface = gr.Interface(fn=CustomChatGPT,
29
+ inputs="textbox",
30
+ outputs="textbox",
31
+ title="VIP-GPT",
32
+ description="Chat with a specialized assistant that can answer questions about recruiting, hiring, and various HR and CRM tools. Developed by A. Leschik.")
33
+
34
+ interface.launch()