kavansaun commited on
Commit
f71c002
·
verified ·
1 Parent(s): a4a2c02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -5,7 +5,7 @@ from github import Github
5
  import uuid
6
 
7
  openai.api_key = os.getenv('OPENAI_KEY')
8
-
9
  # Create UI using gradio
10
  with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}") as chatblock:
11
  message_history = []
@@ -20,6 +20,8 @@ with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}
20
  return gr.Markdown(f"<h1><center> Session Id: {new_id} </center></h1>",visible=True)
21
 
22
  # Adding the instructions to the message history in the content dictionary for the ChatBot to understand.
 
 
23
 
24
  # Message for User Interface
25
  initial_message = "Please write your prompt here and press 'enter'"
@@ -31,8 +33,7 @@ with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}
31
  message_history.append({"role": "user", "content": input})
32
  create_prompt = openai.ChatCompletion.create(
33
  model = "gpt-4o",
34
- messages = message_history,
35
- content = "talk like a pirate"
36
  )
37
 
38
  # Reply content for the chat bot
@@ -40,7 +41,7 @@ with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}
40
 
41
  # Append answer as assistant reply to keep history of prompts
42
  message_history.append({"role": "assistant", "content": reply_prompt})
43
- response = [(message_history[i]["content"], message_history[i+1]["content"]) for i in range(0, len(message_history), 2)]
44
 
45
  # variable content store each message found in the message history and states the respective user. This is for the content to add in the file
46
  content = ''
 
5
  import uuid
6
 
7
  openai.api_key = os.getenv('OPENAI_KEY')
8
+
9
  # Create UI using gradio
10
  with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}") as chatblock:
11
  message_history = []
 
20
  return gr.Markdown(f"<h1><center> Session Id: {new_id} </center></h1>",visible=True)
21
 
22
  # Adding the instructions to the message history in the content dictionary for the ChatBot to understand.
23
+ instructions = 'You only speak in the form of periods and spaces. For example: "... .. .. ..... . ..."'
24
+ message_history.append({"role": "developer", "content": instructions})
25
 
26
  # Message for User Interface
27
  initial_message = "Please write your prompt here and press 'enter'"
 
33
  message_history.append({"role": "user", "content": input})
34
  create_prompt = openai.ChatCompletion.create(
35
  model = "gpt-4o",
36
+ messages = message_history
 
37
  )
38
 
39
  # Reply content for the chat bot
 
41
 
42
  # Append answer as assistant reply to keep history of prompts
43
  message_history.append({"role": "assistant", "content": reply_prompt})
44
+ response = [(message_history[i]["content"], message_history[i+1]["content"]) for i in range(1, len(message_history) - 1, 2)]
45
 
46
  # variable content store each message found in the message history and states the respective user. This is for the content to add in the file
47
  content = ''