Jay Patel commited on
Commit
09a277f
·
1 Parent(s): 970420e

fixed the chatbot

Browse files
Files changed (1) hide show
  1. home_view/ui_home.py +21 -8
home_view/ui_home.py CHANGED
@@ -66,11 +66,25 @@ def CreateGame():
66
  return game_ideas, game_ideas_dict[0]['Description'],game_ideas_dict[0]['Name']
67
  return None, constants.NO_GAME_TITLE, constants.NO_GAME
68
 
69
- def yes_man(message, history):
70
- if message.endswith("?"):
71
- return "Yes"
72
- else:
73
- return "Ask me anything!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  df1 =gr.Dataframe(type="pandas", value=startDF)
76
  df2 =gr.Dataframe(type="pandas", value=slackDF)
@@ -95,9 +109,7 @@ with gr.Blocks() as ui:
95
  label=gr.Label()
96
  with gr.Row(visible=False) as chatRow:
97
  chat = gr.ChatInterface(
98
- yes_man,
99
- chatbot=gr.Chatbot(height=300),
100
- textbox=gr.Textbox(placeholder="Ask me a yes or no question", container=False, scale=7),
101
  title="Yes Man",
102
  description="Ask Yes Man any question",
103
  theme="soft",
@@ -107,6 +119,7 @@ with gr.Blocks() as ui:
107
  undo_btn="Delete Previous",
108
  clear_btn="Clear",
109
  )
 
110
  sketch.change(Predict, inputs=[sketch], outputs=[label])
111
  playersCB.change(SetSelected, inputs=[playersCB], outputs=[])
112
  createBtn.click(CreateGame, inputs=[], outputs=[df4,desc,gameTitle])
 
66
  return game_ideas, game_ideas_dict[0]['Description'],game_ideas_dict[0]['Name']
67
  return None, constants.NO_GAME_TITLE, constants.NO_GAME
68
 
69
+ def chatBot(message, history):
70
+ history_openai_format = []
71
+ for human, assistant in history:
72
+ history_openai_format.append({"role": "user", "content": human })
73
+ history_openai_format.append({"role": "assistant", "content":assistant})
74
+ history_openai_format.append({"role": "user", "content": message})
75
+
76
+ response = openai.ChatCompletion.create(
77
+ model='gpt-3.5-turbo',
78
+ messages= history_openai_format,
79
+ temperature=1.0,
80
+ stream=True
81
+ )
82
+
83
+ partial_message = ""
84
+ for chunk in response:
85
+ if len(chunk['choices'][0]['delta']) != 0:
86
+ partial_message = partial_message + chunk['choices'][0]['delta']['content']
87
+ yield partial_message
88
 
89
  df1 =gr.Dataframe(type="pandas", value=startDF)
90
  df2 =gr.Dataframe(type="pandas", value=slackDF)
 
109
  label=gr.Label()
110
  with gr.Row(visible=False) as chatRow:
111
  chat = gr.ChatInterface(
112
+ chatBot,
 
 
113
  title="Yes Man",
114
  description="Ask Yes Man any question",
115
  theme="soft",
 
119
  undo_btn="Delete Previous",
120
  clear_btn="Clear",
121
  )
122
+
123
  sketch.change(Predict, inputs=[sketch], outputs=[label])
124
  playersCB.change(SetSelected, inputs=[playersCB], outputs=[])
125
  createBtn.click(CreateGame, inputs=[], outputs=[df4,desc,gameTitle])