anzorq commited on
Commit
2535cc5
β€’
1 Parent(s): ee3159b

remove env key and 300 limit

Browse files
Files changed (1) hide show
  1. app.py +6 -10
app.py CHANGED
@@ -6,8 +6,6 @@ import json
6
  import csv
7
 
8
 
9
- openai.api_key = os.environ.get("OPENAI_API_KEY")
10
-
11
  prompt_templates = {"Default ChatGPT": ""}
12
 
13
  def get_empty_state():
@@ -43,7 +41,7 @@ def submit_message(user_token, prompt, prompt_template, temperature, max_tokens,
43
  history = state['messages']
44
 
45
  if not prompt:
46
- return gr.update(value='', visible=state['total_tokens'] < 1_000), [(history[i]['content'], history[i+1]['content']) for i in range(0, len(history)-1, 2)], f"Total tokens used: {state['total_tokens']} / 3000", state
47
 
48
  prompt_template = prompt_templates[prompt_template]
49
 
@@ -68,11 +66,10 @@ def submit_message(user_token, prompt, prompt_template, temperature, max_tokens,
68
  "content": f"Error: {e}"
69
  })
70
 
71
- total_tokens_used_msg = f"Total tokens used: {state['total_tokens']} / 3000" if not user_token else ""
72
  chat_messages = [(history[i]['content'], history[i+1]['content']) for i in range(0, len(history)-1, 2)]
73
- input_visibility = user_token or state['total_tokens'] < 3000
74
 
75
- return gr.update(value='', visible=input_visibility), chat_messages, total_tokens_used_msg, state
76
 
77
  def clear_conversation():
78
  return gr.update(value=None, visible=True), None, "", get_empty_state()
@@ -95,8 +92,7 @@ with gr.Blocks(css=css) as demo:
95
  with gr.Column(elem_id="col-container"):
96
  gr.Markdown("""## OpenAI ChatGPT Demo
97
  Using the ofiicial API (gpt-3.5-turbo model)<br>
98
- Prompt templates from [awesome-chatgpt-prompts](https://github.com/f/awesome-chatgpt-prompts).<br>
99
- Current limit is 3000 tokens per conversation.""",
100
  elem_id="header")
101
 
102
  with gr.Row():
@@ -107,10 +103,10 @@ with gr.Blocks(css=css) as demo:
107
  total_tokens_str = gr.Markdown(elem_id="total_tokens_str")
108
  btn_clear_conversation = gr.Button("πŸ”ƒ Start New Conversation")
109
  with gr.Column():
 
 
110
  prompt_template = gr.Dropdown(label="Set a custom insruction for the chatbot:", choices=list(prompt_templates.keys()))
111
  prompt_template_preview = gr.Markdown(elem_id="prompt_template_preview")
112
- gr.Markdown("Enter your own OpenAI API Key to remove the 3000 token limit. You can get it [here](https://platform.openai.com/account/api-keys).", elem_id="label")
113
- user_token = gr.Textbox(placeholder="OpenAI API Key", type="password", show_label=False)
114
  with gr.Accordion("Advanced parameters", open=False):
115
  temperature = gr.Slider(minimum=0, maximum=2.0, value=0.7, step=0.1, interactive=True, label="Temperature (higher = more creative/chaotic)")
116
  max_tokens = gr.Slider(minimum=100, maximum=4096, value=1000, step=1, interactive=True, label="Max tokens per response")
 
6
  import csv
7
 
8
 
 
 
9
  prompt_templates = {"Default ChatGPT": ""}
10
 
11
  def get_empty_state():
 
41
  history = state['messages']
42
 
43
  if not prompt:
44
+ return gr.update(value=''), [(history[i]['content'], history[i+1]['content']) for i in range(0, len(history)-1, 2)], f"Total tokens used: {state['total_tokens']}", state
45
 
46
  prompt_template = prompt_templates[prompt_template]
47
 
 
66
  "content": f"Error: {e}"
67
  })
68
 
69
+ total_tokens_used_msg = f"Total tokens used: {state['total_tokens']}"
70
  chat_messages = [(history[i]['content'], history[i+1]['content']) for i in range(0, len(history)-1, 2)]
 
71
 
72
+ return gr.update(value=''), chat_messages, total_tokens_used_msg, state
73
 
74
  def clear_conversation():
75
  return gr.update(value=None, visible=True), None, "", get_empty_state()
 
92
  with gr.Column(elem_id="col-container"):
93
  gr.Markdown("""## OpenAI ChatGPT Demo
94
  Using the ofiicial API (gpt-3.5-turbo model)<br>
95
+ Prompt templates from [awesome-chatgpt-prompts](https://github.com/f/awesome-chatgpt-prompts).""",
 
96
  elem_id="header")
97
 
98
  with gr.Row():
 
103
  total_tokens_str = gr.Markdown(elem_id="total_tokens_str")
104
  btn_clear_conversation = gr.Button("πŸ”ƒ Start New Conversation")
105
  with gr.Column():
106
+ gr.Markdown("Enter your own OpenAI API Key. You can get one [here](https://platform.openai.com/account/api-keys).", elem_id="label")
107
+ user_token = gr.Textbox(placeholder="OpenAI API Key", type="password", show_label=False)
108
  prompt_template = gr.Dropdown(label="Set a custom insruction for the chatbot:", choices=list(prompt_templates.keys()))
109
  prompt_template_preview = gr.Markdown(elem_id="prompt_template_preview")
 
 
110
  with gr.Accordion("Advanced parameters", open=False):
111
  temperature = gr.Slider(minimum=0, maximum=2.0, value=0.7, step=0.1, interactive=True, label="Temperature (higher = more creative/chaotic)")
112
  max_tokens = gr.Slider(minimum=100, maximum=4096, value=1000, step=1, interactive=True, label="Max tokens per response")