umangchaudhry commited on
Commit
44b202b
·
1 Parent(s): 15f1c45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -7,10 +7,12 @@ from langchain.embeddings.openai import OpenAIEmbeddings
7
  from langchain.vectorstores import DeepLake
8
  from langchain.chat_models import ChatOpenAI
9
  from langchain.chains import ConversationalRetrievalChain
 
10
 
11
  def set_api_key(key):
12
  os.environ["OPENAI_API_KEY"] = key
13
- return f"Key Successfully Set to: {key}"
 
14
 
15
  def get_api_key():
16
  api_key = os.getenv("OPENAI_API_KEY")
@@ -25,13 +27,13 @@ def respond(message, chat_history):
25
  db = DeepLake(dataset_path="./documentation_db", embedding_function=embeddings, read_only=True)
26
  #Set retriever settings
27
  retriever = db.as_retriever(search_kwargs={"distance_metric":'cos',
28
- "fetch_k":20,
29
  "maximal_marginal_relevance":True,
30
- "k":20})
31
 
32
  # Create ChatOpenAI and ConversationalRetrievalChain
33
  model = ChatOpenAI(model='gpt-3.5-turbo')
34
- qa = ConversationalRetrievalChain.from_llm(model, retriever)
35
 
36
  chat_history=[]
37
  bot_message = qa({"question": message, "chat_history": chat_history})
@@ -41,8 +43,11 @@ def respond(message, chat_history):
41
 
42
  with gr.Blocks() as demo:
43
  with gr.Tab("OpenAI API Key Submission"):
44
- api_input = gr.Textbox(label = "API Key", placeholder = "Please provide your OpenAI API key here")
45
- api_submission_conf = gr.Textbox(label = "Submission Confirmation")
 
 
 
46
  api_submit_button = gr.Button("Submit")
47
 
48
  with gr.Tab("Coding Assistant"):
 
7
  from langchain.vectorstores import DeepLake
8
  from langchain.chat_models import ChatOpenAI
9
  from langchain.chains import ConversationalRetrievalChain
10
+ from langchain.llms import OpenAI
11
 
12
  def set_api_key(key):
13
  os.environ["OPENAI_API_KEY"] = key
14
+ time.sleep(600)
15
+ os.environ["OPENAI_API_KEY"] = ""
16
 
17
  def get_api_key():
18
  api_key = os.getenv("OPENAI_API_KEY")
 
27
  db = DeepLake(dataset_path="./documentation_db", embedding_function=embeddings, read_only=True)
28
  #Set retriever settings
29
  retriever = db.as_retriever(search_kwargs={"distance_metric":'cos',
30
+ "fetch_k":10,
31
  "maximal_marginal_relevance":True,
32
+ "k":10})
33
 
34
  # Create ChatOpenAI and ConversationalRetrievalChain
35
  model = ChatOpenAI(model='gpt-3.5-turbo')
36
+ qa = ConversationalRetrievalChain.from_llm(model, retriever, OpenAI(temperature=0))
37
 
38
  chat_history=[]
39
  bot_message = qa({"question": message, "chat_history": chat_history})
 
43
 
44
  with gr.Blocks() as demo:
45
  with gr.Tab("OpenAI API Key Submission"):
46
+ api_input = gr.Textbox(label = "API Key - Your key will be active for 10 minutes. The bar below shows the time left.",
47
+ placeholder = "Please provide your OpenAI API key here.")
48
+ api_submission_conf = gr.Textbox(label = "API Key Status",
49
+ placeholder = "Your API Key has been reset or has not be set yet. Please re-enter your key.",
50
+ interactive = False)
51
  api_submit_button = gr.Button("Submit")
52
 
53
  with gr.Tab("Coding Assistant"):