Danil commited on
Commit
c32f8d1
1 Parent(s): c953d57

add stop tokens

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -1,13 +1,19 @@
1
  import openai
2
  import numpy as np
3
  import os
 
4
  import gradio as gr
5
 
6
  openai.api_key = os.environ["api_key"]
7
  engine = os.environ["engine"]
8
 
9
 
10
- def happytt(temperature,max_tokens,text):
 
 
 
 
 
11
  response = openai.Completion.create(
12
  engine=engine,
13
  prompt=text,
@@ -15,7 +21,8 @@ def happytt(temperature,max_tokens,text):
15
  max_tokens=max_tokens,
16
  top_p=1,
17
  frequency_penalty=0,
18
- presence_penalty=0
 
19
  )
20
 
21
  return response.choices[0].text
@@ -38,5 +45,7 @@ https://beta.openai.com/examples?category=code'''
38
 
39
  iface = gr.Interface( happytt,[ gr.inputs.Slider(0, 1, step=0.1),gr.inputs.Slider(150, 4000, step=1),
40
  gr.inputs.Textbox(type='str',
41
- label="input prompt")],"text", title = title, description = description )
 
 
42
  iface.launch(debug=True)
 
1
  import openai
2
  import numpy as np
3
  import os
4
+ import json
5
  import gradio as gr
6
 
7
  openai.api_key = os.environ["api_key"]
8
  engine = os.environ["engine"]
9
 
10
 
11
+ def happytt(temperature,max_tokens,text,stop):
12
+ try:
13
+ s = json.loads(stop)
14
+ except json.JSONDecodeError:
15
+ s = []
16
+
17
  response = openai.Completion.create(
18
  engine=engine,
19
  prompt=text,
 
21
  max_tokens=max_tokens,
22
  top_p=1,
23
  frequency_penalty=0,
24
+ presence_penalty=0,
25
+ stop=s
26
  )
27
 
28
  return response.choices[0].text
 
45
 
46
  iface = gr.Interface( happytt,[ gr.inputs.Slider(0, 1, step=0.1),gr.inputs.Slider(150, 4000, step=1),
47
  gr.inputs.Textbox(type='str',
48
+ label="input prompt"),
49
+ gr.inputs.Textbox(type='str',
50
+ label="list of tokens, when to finish generating",value="[]"],"text", title = title, description = description )
51
  iface.launch(debug=True)