FGOTYT commited on
Commit
9bbd26e
·
verified ·
1 Parent(s): 4ee9947

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -36,15 +36,24 @@ def respond(
36
  )
37
 
38
  for chunk in stream:
39
- if chunk.choices[0].delta.content is not None:
40
- response += chunk.choices[0].delta.content
41
- yield response
 
 
 
 
 
 
 
 
 
42
 
43
  # Create the Gradio interface
44
  demo = gr.ChatInterface(
45
  respond,
46
  additional_inputs=[
47
- gr.Textbox(value="You are a helpful AI assistant.", label="System prompt"),
48
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
49
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
50
  gr.Slider(
 
36
  )
37
 
38
  for chunk in stream:
39
+ # Extract content from the chunk
40
+ if 'choices' in chunk and len(chunk['choices']) > 0:
41
+ if 'text' in chunk['choices'][0]:
42
+ content = chunk['choices'][0]['text']
43
+ elif 'delta' in chunk['choices'][0] and 'content' in chunk['choices'][0]['delta']:
44
+ content = chunk['choices'][0]['delta']['content']
45
+ else:
46
+ continue
47
+
48
+ if content is not None:
49
+ response += content
50
+ yield response
51
 
52
  # Create the Gradio interface
53
  demo = gr.ChatInterface(
54
  respond,
55
  additional_inputs=[
56
+ gr.Textbox(value="(Answer on the language of the user)", label="System prompt"),
57
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
58
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
59
  gr.Slider(