ajwthompson commited on
Commit
679fe00
·
1 Parent(s): f3b9247

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -16,10 +16,9 @@ def set_openai_api_key(api_key: str):
16
  """
17
  print(os.environ["TEST"])
18
 
19
- if api_key:
20
- os.environ["OPENAI_API_KEY"] = api_key
21
- chain = get_chain(vectorstore)
22
- os.environ["OPENAI_API_KEY"] = ""
23
  return chain
24
 
25
  class ChatWrapper:
@@ -27,19 +26,21 @@ class ChatWrapper:
27
  def __init__(self):
28
  self.lock = Lock()
29
  def __call__(
30
- self, api_key: str, inp: str, history: Optional[Tuple[str, str]], chain
31
  ):
32
  """Execute the chat functionality."""
33
  self.lock.acquire()
34
  try:
35
  history = history or []
 
36
  # If chain is None, that is because no API key was provided.
37
  if chain is None:
38
  history.append((inp, "Please paste your OpenAI key to use"))
39
  return history, history
40
  # Set OpenAI key
41
  import openai
42
- openai.api_key = api_key
 
43
  # Run chain and append input.
44
  output = chain({"question": inp, "chat_history": history})["answer"]
45
  history.append((inp, output))
@@ -92,14 +93,10 @@ with block:
92
  state = gr.State()
93
  agent_state = gr.State()
94
 
95
- submit.click(chat, inputs=[openai_api_key_textbox, message, state, agent_state], outputs=[chatbot, state],api_name="chat")
96
  message.submit(chat, inputs=[openai_api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
97
 
98
- openai_api_key_textbox.change(
99
- set_openai_api_key,
100
- inputs=[openai_api_key_textbox],
101
- outputs=[agent_state],
102
- )
103
  def echo(name, request: gr.Request):
104
  if request:
105
  print("Request headers dictionary:", request.headers)
 
16
  """
17
  print(os.environ["TEST"])
18
 
19
+
20
+
21
+
 
22
  return chain
23
 
24
  class ChatWrapper:
 
26
  def __init__(self):
27
  self.lock = Lock()
28
  def __call__(
29
+ self, api_key: str, inp: str, history: Optional[Tuple[str, str]]
30
  ):
31
  """Execute the chat functionality."""
32
  self.lock.acquire()
33
  try:
34
  history = history or []
35
+ chain = get_chain(vectorstore)
36
  # If chain is None, that is because no API key was provided.
37
  if chain is None:
38
  history.append((inp, "Please paste your OpenAI key to use"))
39
  return history, history
40
  # Set OpenAI key
41
  import openai
42
+
43
+ openai.api_key = os.environ["OPENAI_API_KEY"]
44
  # Run chain and append input.
45
  output = chain({"question": inp, "chat_history": history})["answer"]
46
  history.append((inp, output))
 
93
  state = gr.State()
94
  agent_state = gr.State()
95
 
96
+
97
  message.submit(chat, inputs=[openai_api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
98
 
99
+
 
 
 
 
100
  def echo(name, request: gr.Request):
101
  if request:
102
  print("Request headers dictionary:", request.headers)