ShermanAI commited on
Commit
ca7fd27
·
1 Parent(s): 800b433

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -9,19 +9,39 @@ import os
9
 
10
  load_dotenv() # load environment variables from .env file
11
  api_key = os.getenv("OPENAI_API_KEY") # access the value of the OPENAI_API_KEY environment variable
12
-
13
  def openai_chat(prompt):
14
  if "who are you" in prompt.lower() or "your name" in prompt.lower() or "name" in prompt.lower():
15
  return "My name is ChatSherman. How can I assist you today?"
16
  else:
17
  prompt = "I'm an AI chatbot named ChatSherman designed by a super intelligent student named ShermanAI at the Department of Electronic and Information Engineering at the Hong Kong Polytechnic University to help you with your engineering questions. Also, I can assist with a wide range of topics and questions." + prompt
18
- completions = openai.Completion.create(engine="text-davinci-003", prompt=prompt, max_tokens=1024, n=1, temperature=0.5,)
19
  message = completions.choices[0].text
20
  return message.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- def chatbot(talk_to_chatsherman):
23
- output = openai_chat(talk_to_chatsherman)
24
- return output
25
 
26
  title = "ChatSherman"
27
  description = "This is an AI chatbot powered by ShermanAI. Enter your question below to get started."
 
9
 
10
  load_dotenv() # load environment variables from .env file
11
  api_key = os.getenv("OPENAI_API_KEY") # access the value of the OPENAI_API_KEY environment variable
12
+ '''
13
  def openai_chat(prompt):
14
  if "who are you" in prompt.lower() or "your name" in prompt.lower() or "name" in prompt.lower():
15
  return "My name is ChatSherman. How can I assist you today?"
16
  else:
17
  prompt = "I'm an AI chatbot named ChatSherman designed by a super intelligent student named ShermanAI at the Department of Electronic and Information Engineering at the Hong Kong Polytechnic University to help you with your engineering questions. Also, I can assist with a wide range of topics and questions." + prompt
18
+ completions = openai.Completion.create(engine="text-davinci-003", prompt=prompt, max_tokens=10000, n=1, temperature=0.5,)
19
  message = completions.choices[0].text
20
  return message.strip()
21
+ '''
22
+ def gptresponse(message, history):
23
+ system_prompt = "I'm an AI chatbot named ChatSherman designed by a super intelligent student named ShermanAI at the Department of Electronic and Information Engineering at the Hong Kong Polytechnic University to help you with your engineering questions. Also, I can assist with a wide range of topics and questions."
24
+
25
+ messages = [{"role":"system","content":system_prompt}]
26
+ for human, assistant in history:
27
+ messages.append({"role":"user", "content":human})
28
+ messages.append({"role":"assistant", "content":assistant})
29
+
30
+ if message != '':
31
+ messages.append({"role":"user", "content":message})
32
+
33
+ response = openai.ChatCompletion.create(engine = "text-davinci-003",
34
+ messages = messages,
35
+ temperature =0.5,
36
+ max_tokens = 10000,
37
+ top_p = 0.95,
38
+ frequency_penalty = 1,
39
+ presence_penalty = 1,
40
+ stop = None)
41
+
42
+ return response["choices"][0]["message"]["content"]
43
+
44
 
 
 
 
45
 
46
  title = "ChatSherman"
47
  description = "This is an AI chatbot powered by ShermanAI. Enter your question below to get started."