justalphie commited on
Commit
8269d69
·
1 Parent(s): 99f9c3b

Implement streaming chat

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import os
2
  import gradio as gr
3
- import cohere
4
-
5
 
6
 
7
  COHERE_KEY = os.getenv('COHERE_KEY')
@@ -24,14 +23,18 @@ def convert_history(list_history):
24
 
25
  def reply(message:str, history:list):
26
  chat_history = convert_history(history)
27
- response = co.chat(
28
  message=message,
29
  chat_history=chat_history,
30
  model="command-nightly",
31
  temperature=0.25
32
  )
33
- answer = response.text
34
- return answer
 
 
 
 
35
 
36
 
37
 
 
1
  import os
2
  import gradio as gr
3
+ import cohere
 
4
 
5
 
6
  COHERE_KEY = os.getenv('COHERE_KEY')
 
23
 
24
  def reply(message:str, history:list):
25
  chat_history = convert_history(history)
26
+ response = co.chat_stream(
27
  message=message,
28
  chat_history=chat_history,
29
  model="command-nightly",
30
  temperature=0.25
31
  )
32
+ text_so_far = ""
33
+ for event in response:
34
+ if event.event_type == 'text-generation':
35
+ text_so_far += event.text
36
+ yield text_so_far
37
+
38
 
39
 
40