diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/.history/app_20230720012201.py b/.history/app_20230720012201.py
new file mode 100644
index 0000000000000000000000000000000000000000..8755959ea3d818db8ce7219c4d8392344baeca20
--- /dev/null
+++ b/.history/app_20230720012201.py
@@ -0,0 +1,105 @@
+import os
+from threading import Lock
+import gradio as gr
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import OpenAI, HuggingFaceHub
+
+
+def load_chain(chain_type: str, api_key: str) -> Optional[ConversationChain]:
+ if chain_type == 'openai':
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ elif chain_type == 'falcon':
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ else:
+ print(f'Invalid chain_type: {chain_type}')
+ return None
+
+ chain = ConversationChain(llm=llm)
+
+ # Unset the API keys
+ os.environ.pop('OPENAI_API_KEY', None)
+ os.environ.pop('HUGGINGFACEHUB_API_TOKEN', None)
+
+ return chain
+
+
+class ChatWrapper:
+ def __init__(self, chain=None):
+ self.chain = chain
+ self.history = []
+ self.lock = Lock()
+
+ def __call__(self, inp: str):
+ with self.lock:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ try:
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+
+ return self.history, self.history
+
+
+chat_wrapper = ChatWrapper()
+
+def update_chain(api_key: str, selection: str):
+ global chat_wrapper
+ chain = load_chain(chain_type=selection, api_key=api_key)
+ chat_wrapper = ChatWrapper(chain=chain)
+
+
+def chat(message: str):
+ global chat_wrapper
+ return chat_wrapper(message)
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("
Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your API key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="Your Message",
+ placeholder="Enter your message here",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720115617.py b/.history/app_20230720115617.py
new file mode 100644
index 0000000000000000000000000000000000000000..8755959ea3d818db8ce7219c4d8392344baeca20
--- /dev/null
+++ b/.history/app_20230720115617.py
@@ -0,0 +1,105 @@
+import os
+from threading import Lock
+import gradio as gr
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import OpenAI, HuggingFaceHub
+
+
+def load_chain(chain_type: str, api_key: str) -> Optional[ConversationChain]:
+ if chain_type == 'openai':
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ elif chain_type == 'falcon':
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ else:
+ print(f'Invalid chain_type: {chain_type}')
+ return None
+
+ chain = ConversationChain(llm=llm)
+
+ # Unset the API keys
+ os.environ.pop('OPENAI_API_KEY', None)
+ os.environ.pop('HUGGINGFACEHUB_API_TOKEN', None)
+
+ return chain
+
+
+class ChatWrapper:
+ def __init__(self, chain=None):
+ self.chain = chain
+ self.history = []
+ self.lock = Lock()
+
+ def __call__(self, inp: str):
+ with self.lock:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ try:
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+
+ return self.history, self.history
+
+
+chat_wrapper = ChatWrapper()
+
+def update_chain(api_key: str, selection: str):
+ global chat_wrapper
+ chain = load_chain(chain_type=selection, api_key=api_key)
+ chat_wrapper = ChatWrapper(chain=chain)
+
+
+def chat(message: str):
+ global chat_wrapper
+ return chat_wrapper(message)
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your API key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="Your Message",
+ placeholder="Enter your message here",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720115808.py b/.history/app_20230720115808.py
new file mode 100644
index 0000000000000000000000000000000000000000..9b79a5724153668d1d06fc3f4596bc9b8fd5988e
--- /dev/null
+++ b/.history/app_20230720115808.py
@@ -0,0 +1,165 @@
+# import gradio as gr
+# from src.main import ChatWrapper
+
+# # Initialize an empty ChatWrapper initially
+# chat_wrapper = ChatWrapper(chain_type="openai", api_key="")
+
+# def update_chain(api_key_textbox, selection):
+# global chat_wrapper # We use the global chat_wrapper here
+# chat_wrapper = ChatWrapper(selection, api_key_textbox) # Re-initialize chat_wrapper
+
+# block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+# with block:
+# with gr.Row():
+# gr.Markdown("ConversationalChain App (+Model Selection)")
+# selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai", label_width="150px")
+# api_key_textbox = gr.Textbox(label="API Key", placeholder="Paste your API key", lines=1, type="password")
+
+# chatbot = gr.Chatbot()
+
+# with gr.Row():
+# message = gr.Textbox(label="What's your question?", placeholder="What's the answer to life, the universe, and everything?", lines=1)
+# submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+# gr.Examples(examples=["Hi! How's it going?", "What should I do tonight?", "Whats 2 + 2?",], inputs=message)
+# gr.HTML("Demo application of a LangChain chain.")
+
+# state = gr.State()
+# agent_state = gr.State()
+
+# # Update the chat_wrapper when the API key or chain type is changed
+# api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+# selection.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+# # Modify the chat_wrapper to accept state and agent state, and to return a response and updated states
+# def chat(api_key, selection, message, state, agent_state):
+# print(f"chat called with api_key: {api_key}, selection: {selection}, message: {message}, state: {state}, agent_state: {agent_state}")
+# chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
+# history = chat_wrapper(message)
+# return history, state, agent_state
+
+# submit.click(chat, inputs=[api_key_textbox, selection, message, state, agent_state], outputs=[chatbot, state, agent_state])
+# message.submit(chat, inputs=[api_key_textbox, selection, message, state, agent_state], outputs=[chatbot, state, agent_state])
+
+# block.launch(debug=True)
+
+
+
+
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+import gradio as gr
+
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history, self.history
+
+
+chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
+
+def update_chain(api_key: str, selection: str):
+ global chat_wrapper
+ chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
+
+def chat(message):
+ global chat_wrapper
+ chat_wrapper(message) # Get a response to the current message
+ history = chat_wrapper.history # Access the entire chat history
+ return history, history
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720115842.py b/.history/app_20230720115842.py
new file mode 100644
index 0000000000000000000000000000000000000000..8557fa00a44526b04b55ce979fbb58f61cb0f132
--- /dev/null
+++ b/.history/app_20230720115842.py
@@ -0,0 +1,274 @@
+# import gradio as gr
+# from src.main import ChatWrapper
+
+# # Initialize an empty ChatWrapper initially
+# chat_wrapper = ChatWrapper(chain_type="openai", api_key="")
+
+# def update_chain(api_key_textbox, selection):
+# global chat_wrapper # We use the global chat_wrapper here
+# chat_wrapper = ChatWrapper(selection, api_key_textbox) # Re-initialize chat_wrapper
+
+# block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+# with block:
+# with gr.Row():
+# gr.Markdown("ConversationalChain App (+Model Selection)")
+# selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai", label_width="150px")
+# api_key_textbox = gr.Textbox(label="API Key", placeholder="Paste your API key", lines=1, type="password")
+
+# chatbot = gr.Chatbot()
+
+# with gr.Row():
+# message = gr.Textbox(label="What's your question?", placeholder="What's the answer to life, the universe, and everything?", lines=1)
+# submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+# gr.Examples(examples=["Hi! How's it going?", "What should I do tonight?", "Whats 2 + 2?",], inputs=message)
+# gr.HTML("Demo application of a LangChain chain.")
+
+# state = gr.State()
+# agent_state = gr.State()
+
+# # Update the chat_wrapper when the API key or chain type is changed
+# api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+# selection.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+# # Modify the chat_wrapper to accept state and agent state, and to return a response and updated states
+# def chat(api_key, selection, message, state, agent_state):
+# print(f"chat called with api_key: {api_key}, selection: {selection}, message: {message}, state: {state}, agent_state: {agent_state}")
+# chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
+# history = chat_wrapper(message)
+# return history, state, agent_state
+
+# submit.click(chat, inputs=[api_key_textbox, selection, message, state, agent_state], outputs=[chatbot, state, agent_state])
+# message.submit(chat, inputs=[api_key_textbox, selection, message, state, agent_state], outputs=[chatbot, state, agent_state])
+
+# block.launch(debug=True)
+
+
+
+
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+import gradio as gr
+
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history, self.history
+
+
+chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
+
+def update_chain(api_key: str, selection: str):
+ global chat_wrapper
+ chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
+
+def chat(message):
+ global chat_wrapper
+ chat_wrapper(message) # Get a response to the current message
+ history = chat_wrapper.history # Access the entire chat history
+ return history, history
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
+
+
+
+# ######## old code
+# import os
+# from threading import Lock
+# import gradio as gr
+# from typing import Any, Optional, Tuple
+# from langchain.chains import ConversationChain
+# from langchain.llms import OpenAI, HuggingFaceHub
+
+
+# def load_chain(chain_type: str, api_key: str) -> Optional[ConversationChain]:
+# if chain_type == 'openai':
+# os.environ["OPENAI_API_KEY"] = api_key
+# llm = OpenAI(temperature=0)
+# elif chain_type == 'falcon':
+# os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+# llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+# else:
+# print(f'Invalid chain_type: {chain_type}')
+# return None
+
+# chain = ConversationChain(llm=llm)
+
+# # Unset the API keys
+# os.environ.pop('OPENAI_API_KEY', None)
+# os.environ.pop('HUGGINGFACEHUB_API_TOKEN', None)
+
+# return chain
+
+
+# class ChatWrapper:
+# def __init__(self, chain=None):
+# self.chain = chain
+# self.history = []
+# self.lock = Lock()
+
+# def __call__(self, inp: str):
+# with self.lock:
+# if self.chain is None:
+# self.history.append((inp, "Please add your API key to proceed."))
+# return self.history
+
+# try:
+# output = self.chain.run(input=inp)
+# self.history.append((inp, output))
+# except Exception as e:
+# self.history.append((inp, f"An error occurred: {e}"))
+
+# return self.history, self.history
+
+
+# chat_wrapper = ChatWrapper()
+
+# def update_chain(api_key: str, selection: str):
+# global chat_wrapper
+# chain = load_chain(chain_type=selection, api_key=api_key)
+# chat_wrapper = ChatWrapper(chain=chain)
+
+
+# def chat(message: str):
+# global chat_wrapper
+# return chat_wrapper(message)
+
+# block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+# with block:
+# with gr.Row():
+# gr.Markdown("Hello-World LangChain App
")
+# selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+# api_key_textbox = gr.Textbox(
+# label="API Key",
+# placeholder="Paste your API key",
+# show_label=True,
+# lines=1,
+# type="password",
+# )
+
+# chatbot = gr.Chatbot()
+
+# with gr.Row():
+# message = gr.Textbox(
+# label="Your Message",
+# placeholder="Enter your message here",
+# lines=1,
+# )
+# submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+# gr.Examples(
+# examples=[
+# "Hi! How's it going?",
+# "What should I do tonight?",
+# "Whats 2 + 2?",
+# ],
+# inputs=message,
+# )
+
+# gr.HTML("Demo application of a LangChain chain.")
+
+# state = gr.State()
+# agent_state = gr.State()
+
+# submit.click(chat, inputs=[message], outputs=[chatbot, state])
+# message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+# api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+# block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720120047.py b/.history/app_20230720120047.py
new file mode 100644
index 0000000000000000000000000000000000000000..17f29aab4a61e68eaafbb8ab8b8d8cf3e35a5abb
--- /dev/null
+++ b/.history/app_20230720120047.py
@@ -0,0 +1,116 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+import gradio as gr
+
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history, self.history
+
+
+chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
+
+def update_chain(api_key: str, selection: str):
+ global chat_wrapper
+ chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
+
+def chat(message):
+ global chat_wrapper
+ chat_wrapper(message) # Get a response to the current message
+ history = chat_wrapper.history # Access the entire chat history
+ return history, history
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720120625.py b/.history/app_20230720120625.py
new file mode 100644
index 0000000000000000000000000000000000000000..4228fbb9bb5ade414f9d25f771309406be6d53b0
--- /dev/null
+++ b/.history/app_20230720120625.py
@@ -0,0 +1,115 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+import gradio as gr
+
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history, self.history
+
+
+chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
+
+def update_chain(api_key: str, selection: str):
+ global chat_wrapper
+ chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
+
+def chat(message):
+ global chat_wrapper
+ chat_wrapper(message) # Get a response to the current message
+ history = chat_wrapper.history # Access the entire chat history
+ return history, history
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720120933.py b/.history/app_20230720120933.py
new file mode 100644
index 0000000000000000000000000000000000000000..182990dec6a1dc4815a93cbd788a14f1f7fd2254
--- /dev/null
+++ b/.history/app_20230720120933.py
@@ -0,0 +1,60 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
+
+def update_chain(api_key: str, selection: str):
+ global chat_wrapper
+ chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
+
+def chat(message):
+ global chat_wrapper
+ chat_wrapper(message) # Get a response to the current message
+ history = chat_wrapper.history # Access the entire chat history
+ return history, history
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720130430.py b/.history/app_20230720130430.py
new file mode 100644
index 0000000000000000000000000000000000000000..be2ceac5471a78269dbd5f8fda7bca68dd0d1db6
--- /dev/null
+++ b/.history/app_20230720130430.py
@@ -0,0 +1,53 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+chat = ChatWrapper()
+
+def update_chain(api_key: str, selection: str):
+ global chat_wrapper
+ chat_wrapper = ChatWrapper(chain=selection, api_key=api_key)
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+ message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720130724.py b/.history/app_20230720130724.py
new file mode 100644
index 0000000000000000000000000000000000000000..03576d9110b9f13abb6ff5a56291ac510aa59b09
--- /dev/null
+++ b/.history/app_20230720130724.py
@@ -0,0 +1,53 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+chat = ChatWrapper()
+
+def update_chain(api_key: str, selection: str):
+ global chat
+ chat = ChatWrapper(chain=selection, api_key=api_key)
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+ message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720131115.py b/.history/app_20230720131115.py
new file mode 100644
index 0000000000000000000000000000000000000000..6cfb2e86b81bc45a1f1ed0df91afaeb5056b5cf9
--- /dev/null
+++ b/.history/app_20230720131115.py
@@ -0,0 +1,54 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+chat = ChatWrapper()
+
+def update_chain(api_key: str, selection: str):
+ global chat
+ chat = ChatWrapper(api_key=api_key, chain=selection)
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+ message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720131814.py b/.history/app_20230720131814.py
new file mode 100644
index 0000000000000000000000000000000000000000..8e2cc4930f5bb489f2859770f260b32e022b0f2e
--- /dev/null
+++ b/.history/app_20230720131814.py
@@ -0,0 +1,55 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+chat = ChatWrapper()
+
+def update_chain(api_key: str, selection: str):
+ global chat
+ chat = ChatWrapper(api_key=api_key, chain=selection)
+ return chat
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+ message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720132136.py b/.history/app_20230720132136.py
new file mode 100644
index 0000000000000000000000000000000000000000..740df948edfd57210bc84fe5699b52cbf042bdd3
--- /dev/null
+++ b/.history/app_20230720132136.py
@@ -0,0 +1,55 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+chat = ChatWrapper()
+
+def update_chain(api_key: str, selection: str):
+ global chat
+ chat = ChatWrapper(api_key=api_key, chain=selection)
+ return chat
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+ message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, message, state, agent_state], outputs=[agent_state])
+ selection.change(update_chain, inputs=[api_key_textbox, message, state, agent_state], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720132503.py b/.history/app_20230720132503.py
new file mode 100644
index 0000000000000000000000000000000000000000..ea03e25a959af25f6f7217641ff2a9710b35c851
--- /dev/null
+++ b/.history/app_20230720132503.py
@@ -0,0 +1,55 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+chat = ChatWrapper()
+
+def update_chain(api_key: str, message: str, state: str, selection: str):
+ global chat
+ chat = ChatWrapper(api_key=api_key, input=message, history=state str, chain=selection)
+ return chat
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+ message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, message, state, agent_state], outputs=[agent_state])
+ selection.change(update_chain, inputs=[api_key_textbox, message, state, agent_state], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720132518.py b/.history/app_20230720132518.py
new file mode 100644
index 0000000000000000000000000000000000000000..ea03e25a959af25f6f7217641ff2a9710b35c851
--- /dev/null
+++ b/.history/app_20230720132518.py
@@ -0,0 +1,55 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+chat = ChatWrapper()
+
+def update_chain(api_key: str, message: str, state: str, selection: str):
+ global chat
+ chat = ChatWrapper(api_key=api_key, input=message, history=state str, chain=selection)
+ return chat
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+ message.submit(chat, inputs=[api_key_textbox, message, state, agent_state], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, message, state, agent_state], outputs=[agent_state])
+ selection.change(update_chain, inputs=[api_key_textbox, message, state, agent_state], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720133035.py b/.history/app_20230720133035.py
new file mode 100644
index 0000000000000000000000000000000000000000..182990dec6a1dc4815a93cbd788a14f1f7fd2254
--- /dev/null
+++ b/.history/app_20230720133035.py
@@ -0,0 +1,60 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
+
+def update_chain(api_key: str, selection: str):
+ global chat_wrapper
+ chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
+
+def chat(message):
+ global chat_wrapper
+ chat_wrapper(message) # Get a response to the current message
+ history = chat_wrapper.history # Access the entire chat history
+ return history, history
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720133118.py b/.history/app_20230720133118.py
new file mode 100644
index 0000000000000000000000000000000000000000..675d6cfe3d8b3476c897f955bcfa6da645fbeaab
--- /dev/null
+++ b/.history/app_20230720133118.py
@@ -0,0 +1,61 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+chat_wrapper = ChatWrapper('openai') # default chain_type is 'openai'
+
+def update_chain(api_key: str, selection: str):
+ global chat_wrapper
+ chat_wrapper = ChatWrapper(chain_type=selection, api_key=api_key)
+ return chat_wrapper # This is agent state
+
+def chat(message):
+ global chat_wrapper
+ chat_wrapper(message) # Get a response to the current message
+ history = chat_wrapper.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_chain, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720133714.py b/.history/app_20230720133714.py
new file mode 100644
index 0000000000000000000000000000000000000000..18a178bd9d1252adafc2ca19949d4719e326a8e7
--- /dev/null
+++ b/.history/app_20230720133714.py
@@ -0,0 +1,61 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720134604.py b/.history/app_20230720134604.py
new file mode 100644
index 0000000000000000000000000000000000000000..101876933f1f61eb8791ee1ba782ade8e6657fd9
--- /dev/null
+++ b/.history/app_20230720134604.py
@@ -0,0 +1,62 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("Hello-World LangChain App
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("Demo application of a LangChain chain.")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720135305.py b/.history/app_20230720135305.py
new file mode 100644
index 0000000000000000000000000000000000000000..e1359db69f868395bcdb89a38713c84b3aa71668
--- /dev/null
+++ b/.history/app_20230720135305.py
@@ -0,0 +1,62 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720135438.py b/.history/app_20230720135438.py
new file mode 100644
index 0000000000000000000000000000000000000000..ab398ff312a955564af14dd5dbb871f69980fecb
--- /dev/null
+++ b/.history/app_20230720135438.py
@@ -0,0 +1,62 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720135623.py b/.history/app_20230720135623.py
new file mode 100644
index 0000000000000000000000000000000000000000..7d847ab1c9ee8774409a947c99089c6202227101
--- /dev/null
+++ b/.history/app_20230720135623.py
@@ -0,0 +1,62 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720135741.py b/.history/app_20230720135741.py
new file mode 100644
index 0000000000000000000000000000000000000000..96809dda2cf6d7b8e1dc858db09bc919a87d12d8
--- /dev/null
+++ b/.history/app_20230720135741.py
@@ -0,0 +1,66 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_label(api_key: str, selection: str):
+ label_text = "Put your HuggingFace API Key" if selection == "falcon" else "Put your OpenAI API Key"
+ return {"markdown": label_text} #update the markdown
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.Markdown("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ update_api_key_label,
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720140423.py b/.history/app_20230720140423.py
new file mode 100644
index 0000000000000000000000000000000000000000..f1779752873bc36ffb2a95ac399f654e26e2d583
--- /dev/null
+++ b/.history/app_20230720140423.py
@@ -0,0 +1,64 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ label_text = "Put your HuggingFace API Key" if selection == "falcon" else "Put your OpenAI API Key"
+ return agent, {"markdown": label_text} # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+agent_api_label = gr.Markdown()
+
+with block:
+ with gr.Row():
+ gr.Markdown("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ agent_api_label,
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state, agent_api_label])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720140424.py b/.history/app_20230720140424.py
new file mode 100644
index 0000000000000000000000000000000000000000..f1779752873bc36ffb2a95ac399f654e26e2d583
--- /dev/null
+++ b/.history/app_20230720140424.py
@@ -0,0 +1,64 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ label_text = "Put your HuggingFace API Key" if selection == "falcon" else "Put your OpenAI API Key"
+ return agent, {"markdown": label_text} # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+agent_api_label = gr.Markdown()
+
+with block:
+ with gr.Row():
+ gr.Markdown("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ agent_api_label,
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state, agent_api_label])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720141203.py b/.history/app_20230720141203.py
new file mode 100644
index 0000000000000000000000000000000000000000..2171e70de157bff34650cd58fe4df8e53281c4a4
--- /dev/null
+++ b/.history/app_20230720141203.py
@@ -0,0 +1,66 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ if selection == "falcon":
+ api_key_textbox.placeholder = "Paste your Huggingface API key"
+ else:
+ api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720141228.py b/.history/app_20230720141228.py
new file mode 100644
index 0000000000000000000000000000000000000000..ab398ff312a955564af14dd5dbb871f69980fecb
--- /dev/null
+++ b/.history/app_20230720141228.py
@@ -0,0 +1,62 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720141747.py b/.history/app_20230720141747.py
new file mode 100644
index 0000000000000000000000000000000000000000..fa893519a259853477ea029bc34c19fe47700d62
--- /dev/null
+++ b/.history/app_20230720141747.py
@@ -0,0 +1,62 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ # api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720141944.py b/.history/app_20230720141944.py
new file mode 100644
index 0000000000000000000000000000000000000000..ab398ff312a955564af14dd5dbb871f69980fecb
--- /dev/null
+++ b/.history/app_20230720141944.py
@@ -0,0 +1,62 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720142413.py b/.history/app_20230720142413.py
new file mode 100644
index 0000000000000000000000000000000000000000..86a160c146434aead3432c15ebfdf56861310984
--- /dev/null
+++ b/.history/app_20230720142413.py
@@ -0,0 +1,70 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection):
+ if selection == 'falcon':
+ api_key_textbox.placeholder = "Paste your HuggingFace API key hf_...)"
+ else:
+ api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ # API_KEY_TEXTBOX if selection if Falcon then "HuggingFace API Key" else "OpenAI API Key
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder="Paste your OpenAI API key (sk-...)",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_api_key_palceholder, inputs=[selection])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720142550.py b/.history/app_20230720142550.py
new file mode 100644
index 0000000000000000000000000000000000000000..0d02e2f6af80f9bfbf02803cf09482dbe5a41d92
--- /dev/null
+++ b/.history/app_20230720142550.py
@@ -0,0 +1,71 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection):
+ if selection == 'falcon':
+ api_key_textbox.placeholder = "Paste your HuggingFace API key hf_...)"
+ else:
+ api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
+ return api_key_textbox.placeholder
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ # Updating api_key_textbox placeholder based on selection
+ placeholder=update_api_key_palceholder
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_api_key_palceholder, inputs=[selection])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720142627.py b/.history/app_20230720142627.py
new file mode 100644
index 0000000000000000000000000000000000000000..e54a36f5dc84b08fb4dd05f0b2a823b0e9e087d6
--- /dev/null
+++ b/.history/app_20230720142627.py
@@ -0,0 +1,71 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection):
+ if selection == 'falcon':
+ api_key_textbox.placeholder = "Paste your HuggingFace API key hf_...)"
+ else:
+ api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
+ return api_key_textbox.placeholder
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ # Updating api_key_textbox placeholder based on selection
+ placeholder= update_api_key_palceholder(),
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_api_key_palceholder, inputs=[selection])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720142635.py b/.history/app_20230720142635.py
new file mode 100644
index 0000000000000000000000000000000000000000..7002689d732fb0919da2fcc7f0daf7a17b25b01c
--- /dev/null
+++ b/.history/app_20230720142635.py
@@ -0,0 +1,71 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection):
+ if selection == 'falcon':
+ api_key_textbox.placeholder = "Paste your HuggingFace API key hf_...)"
+ else:
+ api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
+ return api_key_textbox.placeholder
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ # Updating api_key_textbox placeholder based on selection
+ placeholder= update_api_key_palceholder,
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_api_key_palceholder, inputs=[selection])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720142718.py b/.history/app_20230720142718.py
new file mode 100644
index 0000000000000000000000000000000000000000..02b300b35c3cd1782d1758d978a29d47c9d5e14f
--- /dev/null
+++ b/.history/app_20230720142718.py
@@ -0,0 +1,69 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection):
+ if selection == 'falcon':
+ api_key_textbox.placeholder = "Paste your HuggingFace API key hf_...)"
+ else:
+ api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ # Updating api_key_textbox placeholder based on selection
+ placeholder= update_api_key_palceholder,
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_api_key_palceholder, inputs=[selection])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720142924.py b/.history/app_20230720142924.py
new file mode 100644
index 0000000000000000000000000000000000000000..0ed4396b31663f15e7f5cd460dc0be97c1272d17
--- /dev/null
+++ b/.history/app_20230720142924.py
@@ -0,0 +1,69 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection):
+ if selection == 'falcon':
+ api_key_textbox.placeholder = "Paste your HuggingFace API key hf_...)"
+ else:
+ api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
+ api_key_textbox.refresh()
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= "Paste your API key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_api_key_palceholder, inputs=[selection])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720143034.py b/.history/app_20230720143034.py
new file mode 100644
index 0000000000000000000000000000000000000000..c3e280be341da3d46527c15a40e57bda3997d350
--- /dev/null
+++ b/.history/app_20230720143034.py
@@ -0,0 +1,68 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection):
+ if selection == 'falcon':
+ "Paste your HuggingFace API key hf_...)"
+ else:
+ "Paste your OpenAI API key (sk-...)"
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= "Paste your API key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_api_key_palceholder, inputs=[selection])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720143041.py b/.history/app_20230720143041.py
new file mode 100644
index 0000000000000000000000000000000000000000..f3b22f2a7a12be895d2048e700fd0a0465282846
--- /dev/null
+++ b/.history/app_20230720143041.py
@@ -0,0 +1,68 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection):
+ if selection == 'falcon':
+ "Paste your HuggingFace API key hf_...)"
+ else:
+ "Paste your OpenAI API key (sk-...)"
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= update_api_key_palceholder,
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_api_key_palceholder, inputs=[selection])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720143109.py b/.history/app_20230720143109.py
new file mode 100644
index 0000000000000000000000000000000000000000..33730aa4b58a2a1dddaa2b0def37a9977e2b8202
--- /dev/null
+++ b/.history/app_20230720143109.py
@@ -0,0 +1,68 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection):
+ if selection == 'falcon':
+ "Paste your HuggingFace API key hf_...)"
+ else:
+ "Paste your OpenAI API key (sk-...)"
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= update_api_key_palceholder(selection.value),
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_api_key_palceholder, inputs=[selection])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720143123.py b/.history/app_20230720143123.py
new file mode 100644
index 0000000000000000000000000000000000000000..0f754b131a540019f0447ad156eb82aa27a4738c
--- /dev/null
+++ b/.history/app_20230720143123.py
@@ -0,0 +1,68 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection):
+ if selection == 'falcon':
+ "Paste your HuggingFace API key hf_...)"
+ else:
+ "Paste your OpenAI API key (sk-...)"
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= update_api_key_palceholder(selection.value),
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ # selection.change(update_api_key_palceholder, inputs=[selection])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720143149.py b/.history/app_20230720143149.py
new file mode 100644
index 0000000000000000000000000000000000000000..33730aa4b58a2a1dddaa2b0def37a9977e2b8202
--- /dev/null
+++ b/.history/app_20230720143149.py
@@ -0,0 +1,68 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection):
+ if selection == 'falcon':
+ "Paste your HuggingFace API key hf_...)"
+ else:
+ "Paste your OpenAI API key (sk-...)"
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= update_api_key_palceholder(selection.value),
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_api_key_palceholder, inputs=[selection])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720143312.py b/.history/app_20230720143312.py
new file mode 100644
index 0000000000000000000000000000000000000000..5c73e662b7c7b0071d35af40900daa75bbd8baa3
--- /dev/null
+++ b/.history/app_20230720143312.py
@@ -0,0 +1,67 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection: str):
+ if selection == 'falcon':
+ "Paste your HuggingFace API key hf_...)"
+ else:
+ "Paste your OpenAI API key (sk-...)"
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= update_api_key_palceholder(selection.value),
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720143545.py b/.history/app_20230720143545.py
new file mode 100644
index 0000000000000000000000000000000000000000..9ea9ebed9586d77069fdba84f8ec05a7147e11ba
--- /dev/null
+++ b/.history/app_20230720143545.py
@@ -0,0 +1,72 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection):
+ if selection == 'falcon':
+ api_key_textbox.placeholder = "Paste your HuggingFace API key (hf_...)"
+ else:
+ api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
+
+ # Manually update the placeholder text in the HTML
+ api_key_textbox.render()
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= "Paste Your API Key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_api_key_palceholder, inputs=[selection])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720143613.py b/.history/app_20230720143613.py
new file mode 100644
index 0000000000000000000000000000000000000000..64220b89be25c1b85fbd2ae8c4e8397bfab5c59f
--- /dev/null
+++ b/.history/app_20230720143613.py
@@ -0,0 +1,72 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+def update_api_key_palceholder(selection):
+ if selection == 'falcon':
+ api_key_textbox.placeholder = "Paste your HuggingFace API key (hf_...)"
+ else:
+ api_key_textbox.placeholder = "Paste your OpenAI API key (sk-...)"
+
+ # Manually update the placeholder text in the HTML
+ return api_key_textbox.render()
+
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= "Paste Your API Key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_api_key_palceholder, inputs=[selection])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720143706.py b/.history/app_20230720143706.py
new file mode 100644
index 0000000000000000000000000000000000000000..2c259a1dc0e1752a1cb5cea1a0de2189f594144e
--- /dev/null
+++ b/.history/app_20230720143706.py
@@ -0,0 +1,61 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= "Paste Your API Key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720143740.py b/.history/app_20230720143740.py
new file mode 100644
index 0000000000000000000000000000000000000000..2432e4f89dd50cbfbea41d2346cd3c25f130cdb8
--- /dev/null
+++ b/.history/app_20230720143740.py
@@ -0,0 +1,63 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= "Paste Your API Key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+ gr.HTML("For Falcon use HuggingFace API Token, for OpenAI use OpenAI API Key")
+
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720143814.py b/.history/app_20230720143814.py
new file mode 100644
index 0000000000000000000000000000000000000000..a5714f179d7cdc5ea3e93f70ac62dc09716d1311
--- /dev/null
+++ b/.history/app_20230720143814.py
@@ -0,0 +1,63 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= "Paste Your API Key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+ gr.HTML("For Falcon use HuggingFace API Token, for OpenAI use OpenAI API Key")
+
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720143901.py b/.history/app_20230720143901.py
new file mode 100644
index 0000000000000000000000000000000000000000..b3065358b0c497477e12da6c4980254b821bb1e1
--- /dev/null
+++ b/.history/app_20230720143901.py
@@ -0,0 +1,61 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
For Falcon use HuggingFace API Token, for OpenAI use OpenAI API Key")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= "Paste Your API Key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720144009.py b/.history/app_20230720144009.py
new file mode 100644
index 0000000000000000000000000000000000000000..ae6c28bf043edbe00586fd3648bbabbca5c9e5cc
--- /dev/null
+++ b/.history/app_20230720144009.py
@@ -0,0 +1,61 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
For Falcon use HuggingFace API Token, for OpenAI use OpenAI API Key")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= "Paste Your API Key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720144049.py b/.history/app_20230720144049.py
new file mode 100644
index 0000000000000000000000000000000000000000..c3ffd35e40eee423040578715dab8c2b0d5279d0
--- /dev/null
+++ b/.history/app_20230720144049.py
@@ -0,0 +1,61 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
For Falcon use HuggingFace API Token, for OpenAI use OpenAI API Key")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= "Paste Your API Key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/app_20230720144115.py b/.history/app_20230720144115.py
new file mode 100644
index 0000000000000000000000000000000000000000..fbf412220c15fa80c300189f87f48cb3c5cb8a7f
--- /dev/null
+++ b/.history/app_20230720144115.py
@@ -0,0 +1,61 @@
+import gradio as gr
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
For Falcon use HuggingFace API Token, for OpenAI use OpenAI API Key")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= "Paste Your API Key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+
+block.launch(debug=True)
\ No newline at end of file
diff --git a/.history/src/main_20230720001200.py b/.history/src/main_20230720001200.py
new file mode 100644
index 0000000000000000000000000000000000000000..230429a74766767a09970acb004bb5ee621e5c0a
--- /dev/null
+++ b/.history/src/main_20230720001200.py
@@ -0,0 +1,113 @@
+# import os
+# from typing import Any, Optional, Tuple
+# from langchain.chains import ConversationChain
+# from langchain.llms import HuggingFaceHub
+# from langchain.llms import OpenAI
+# from threading import Lock
+
+
+# def load_chain_openai(api_key: str):
+# os.environ["OPENAI_API_KEY"] = api_key # Setting up Key
+# llm = OpenAI(temperature=0)
+# chain = ConversationChain(llm=llm)
+# os.environ["OPENAI_API_KEY"] = "" # Unsetting Key to not leave the sensitive information needlessly in the environment
+# return chain
+
+# def load_chain_falcon(api_key: str):
+# os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key # Setting up Key
+# llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.5})
+# chain = ConversationChain(llm=llm)
+# os.environ["HUGGINGFACEHUB_API_TOKEN"] = "" # Unsetting Key to not leave the sensitive information needlessly in the environment
+# return chain
+
+# # Class for the Gradio app
+# class ChatWrapper:
+# def __init__(self, chain_type: str, api_key: str = ''):
+# self.api_key = api_key
+# self.chain_type = chain_type
+# self.history = []
+# self.lock = Lock()
+
+# if self.api_key:
+# if chain_type == 'openai':
+# self.chain = load_chain_openai(self.api_key)
+# elif chain_type == 'falcon':
+# self.chain = load_chain_falcon(self.api_key)
+# else:
+# raise ValueError(f'Invalid chain_type: {chain_type}')
+# else:
+# self.chain = None
+
+# def __call__(self, inp: str, chain: Optional[ConversationChain] = None):
+# try:
+# with self.lock:
+# if chain is not None:
+# self.chain = chain
+# elif self.chain is None:
+# self.history.append((inp, "Please add your API key to proceed."))
+# return self.history
+
+# output = self.chain.run(input=inp)
+# self.history.append((inp, output))
+# except Exception as e:
+# print(f"Error: {e}")
+# self.history.append((inp, f"An error occurred: {e}"))
+
+# return self.history
+
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+import gradio as gr
+
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history, self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720120907.py b/.history/src/main_20230720120907.py
new file mode 100644
index 0000000000000000000000000000000000000000..b85a5d15116f4385c05b062eeafcff1ffcd6dc5b
--- /dev/null
+++ b/.history/src/main_20230720120907.py
@@ -0,0 +1,54 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history, self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720122456.py b/.history/src/main_20230720122456.py
new file mode 100644
index 0000000000000000000000000000000000000000..305354e984a2e79b579babb517bcf6f8fae15d92
--- /dev/null
+++ b/.history/src/main_20230720122456.py
@@ -0,0 +1,54 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720125534.py b/.history/src/main_20230720125534.py
new file mode 100644
index 0000000000000000000000000000000000000000..675828b38651a87cbf0478c23c0c4e02a1b1da18
--- /dev/null
+++ b/.history/src/main_20230720125534.py
@@ -0,0 +1,53 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self):
+ self.lock = Lock()
+
+ def __call__(
+ self, api_key: str, inp: str, history: Optional[Tuple[str, str]], chain: Optional[ConversationChain]
+ ):
+ self.lock.acquire()
+ if self.api_key:
+ if chain == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain}')
+ else:
+ self.chain = None
+
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history, self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720125820.py b/.history/src/main_20230720125820.py
new file mode 100644
index 0000000000000000000000000000000000000000..cf5e6df8503f4e5f7d5776b2c1582a02543788e1
--- /dev/null
+++ b/.history/src/main_20230720125820.py
@@ -0,0 +1,54 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self):
+ self.lock = Lock()
+
+ def __call__(
+ self, api_key: str, inp: str, history: Optional[Tuple[str, str]], chain: Optional[ConversationChain]
+ ):
+ self.lock.acquire()
+ self.api_key = api_key
+ if self.api_key:
+ if chain == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain}')
+ else:
+ self.chain = None
+
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history, self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720125943.py b/.history/src/main_20230720125943.py
new file mode 100644
index 0000000000000000000000000000000000000000..1340e949286e26b66c44dc701f6fdc58656150ee
--- /dev/null
+++ b/.history/src/main_20230720125943.py
@@ -0,0 +1,55 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self):
+ self.lock = Lock()
+
+ def __call__(
+ self, api_key: str, inp: str, history: Optional[Tuple[str, str]], chain: Optional[ConversationChain]
+ ):
+ self.lock.acquire()
+ self.api_key = api_key
+ if self.api_key:
+ if chain == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain}')
+ else:
+ self.chain = None
+
+ self.history = history or []
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history, self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720131220.py b/.history/src/main_20230720131220.py
new file mode 100644
index 0000000000000000000000000000000000000000..a72ae5175861d5c78cd2e7cd87d90413ba9817d4
--- /dev/null
+++ b/.history/src/main_20230720131220.py
@@ -0,0 +1,55 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self):
+ self.lock = Lock()
+
+ def __call__(
+ self, api_key: str, inp: str, history: Optional[Tuple[str, str]], chain: Optional[ConversationChain]
+ ):
+ self.lock.acquire()
+ self.api_key = api_key
+ if self.api_key:
+ if chain == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain: {chain}')
+ else:
+ self.chain = None
+
+ self.history = history or []
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history, self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720131449.py b/.history/src/main_20230720131449.py
new file mode 100644
index 0000000000000000000000000000000000000000..95b4f257d6ee7cb84dd2d5ddd1a655875b8e6ee5
--- /dev/null
+++ b/.history/src/main_20230720131449.py
@@ -0,0 +1,55 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self):
+ self.lock = Lock()
+
+ def __call__(
+ self, api_key: str, inp: str, history: Optional[Tuple[str, str]], chain: Optional[ConversationChain]
+ ):
+ self.lock.acquire()
+ self.api_key = self.api_key
+ if self.api_key:
+ if chain == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain: {chain}')
+ else:
+ self.chain = None
+
+ self.history = history or []
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history, self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720131556.py b/.history/src/main_20230720131556.py
new file mode 100644
index 0000000000000000000000000000000000000000..a72ae5175861d5c78cd2e7cd87d90413ba9817d4
--- /dev/null
+++ b/.history/src/main_20230720131556.py
@@ -0,0 +1,55 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self):
+ self.lock = Lock()
+
+ def __call__(
+ self, api_key: str, inp: str, history: Optional[Tuple[str, str]], chain: Optional[ConversationChain]
+ ):
+ self.lock.acquire()
+ self.api_key = api_key
+ if self.api_key:
+ if chain == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain: {chain}')
+ else:
+ self.chain = None
+
+ self.history = history or []
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history, self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720132836.py b/.history/src/main_20230720132836.py
new file mode 100644
index 0000000000000000000000000000000000000000..305354e984a2e79b579babb517bcf6f8fae15d92
--- /dev/null
+++ b/.history/src/main_20230720132836.py
@@ -0,0 +1,54 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.lock.release()
+
+ return self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720134043.py b/.history/src/main_20230720134043.py
new file mode 100644
index 0000000000000000000000000000000000000000..8e6b9ac7658d8115fea2ad4eaa4b2e2f565fffad
--- /dev/null
+++ b/.history/src/main_20230720134043.py
@@ -0,0 +1,55 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.api_key = '' # API key is cleared after running the chain
+ self.lock.release()
+
+ return self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720134412.py b/.history/src/main_20230720134412.py
new file mode 100644
index 0000000000000000000000000000000000000000..ff66005d08a26529b019c6f4039d4c9004636cd4
--- /dev/null
+++ b/.history/src/main_20230720134412.py
@@ -0,0 +1,55 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9, "min_length": 50"})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.api_key = '' # API key is cleared after running the chain
+ self.lock.release()
+
+ return self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720134442.py b/.history/src/main_20230720134442.py
new file mode 100644
index 0000000000000000000000000000000000000000..8e6b9ac7658d8115fea2ad4eaa4b2e2f565fffad
--- /dev/null
+++ b/.history/src/main_20230720134442.py
@@ -0,0 +1,55 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.api_key = '' # API key is cleared after running the chain
+ self.lock.release()
+
+ return self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720134505.py b/.history/src/main_20230720134505.py
new file mode 100644
index 0000000000000000000000000000000000000000..469808edb69cca1f8a5b2a9113c3093be8058a03
--- /dev/null
+++ b/.history/src/main_20230720134505.py
@@ -0,0 +1,55 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.api_key = '' # API key is cleared after running each chain
+ self.lock.release()
+
+ return self.history
\ No newline at end of file
diff --git a/.history/src/main_20230720134509.py b/.history/src/main_20230720134509.py
new file mode 100644
index 0000000000000000000000000000000000000000..469808edb69cca1f8a5b2a9113c3093be8058a03
--- /dev/null
+++ b/.history/src/main_20230720134509.py
@@ -0,0 +1,55 @@
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
+
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.api_key = '' # API key is cleared after running each chain
+ self.lock.release()
+
+ return self.history
\ No newline at end of file
diff --git a/app.py b/app.py
index 994c2163be90103db6f4d1af129a00449015b46a..fbf412220c15fa80c300189f87f48cb3c5cb8a7f 100644
--- a/app.py
+++ b/app.py
@@ -1,7 +1,61 @@
-# gradio_interface.py
-
import gradio as gr
-from src.main import greet
+from src.main import ChatWrapper
+
+agent = ChatWrapper('openai', '') # default agnet_state
+
+def update_agent(api_key: str, selection: str):
+ global agent
+ agent = ChatWrapper(chain_type=selection, api_key=api_key)
+ return agent # This is agent state
+
+def chat(message):
+ global agent
+ agent(message) # Get a response to the current message
+ history = agent.history # Access the entire chat history
+ return history, history # Return the history twice to update both the chatbot and the state
+
+block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
+
+with block:
+ with gr.Row():
+ gr.HTML("ConversationalChain App 🤖
For Falcon use HuggingFace API Token, for OpenAI use OpenAI API Key")
+ selection = gr.Dropdown(label="Select Agent", choices=["falcon", "openai"], default="openai")
+ api_key_textbox = gr.Textbox(
+ label="API Key",
+ placeholder= "Paste Your API Key",
+ show_label=True,
+ lines=1,
+ type="password",
+ )
+
+ chatbot = gr.Chatbot()
+
+ with gr.Row():
+ message = gr.Textbox(
+ label="What's your question?",
+ placeholder="What's the answer to life, the universe, and everything?",
+ lines=1,
+ )
+ submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
+
+ gr.Examples(
+ examples=[
+ "Hi! How's it going?",
+ "What should I do tonight?",
+ "Whats 2 + 2?",
+ ],
+ inputs=message,
+ )
+
+ gr.HTML("View more at ai.rohankataria.com")
+
+ state = gr.State()
+ agent_state = gr.State()
+
+ submit.click(chat, inputs=[message], outputs=[chatbot, state])
+ message.submit(chat, inputs=[message], outputs=[chatbot, state])
+
+ api_key_textbox.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
+ selection.change(update_agent, inputs=[api_key_textbox, selection], outputs=[agent_state])
-iface = gr.Interface(fn=greet, inputs="text", outputs="text")
-iface.launch()
\ No newline at end of file
+block.launch(debug=True)
\ No newline at end of file
diff --git a/src/__pycache__/main.cpython-311.pyc b/src/__pycache__/main.cpython-311.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..93359609ef9c33f3e9c8f791a6613d0dbf671f4c
Binary files /dev/null and b/src/__pycache__/main.cpython-311.pyc differ
diff --git a/src/main.py b/src/main.py
index 020fba201445431111e0c1f3b99098718ae2342d..469808edb69cca1f8a5b2a9113c3093be8058a03 100644
--- a/src/main.py
+++ b/src/main.py
@@ -1,4 +1,55 @@
-# main.py
+import os
+from typing import Any, Optional, Tuple
+from langchain.chains import ConversationChain
+from langchain.llms import HuggingFaceHub
+from langchain.llms import OpenAI
+from threading import Lock
-def greet(name):
- return "Hello " + name + "!!"
\ No newline at end of file
+def load_chain_openai(api_key: str):
+ os.environ["OPENAI_API_KEY"] = api_key
+ llm = OpenAI(temperature=0)
+ chain = ConversationChain(llm=llm)
+ os.environ["OPENAI_API_KEY"] = ""
+ return chain
+
+
+def load_chain_falcon(api_key: str):
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = api_key
+ llm = HuggingFaceHub(repo_id="tiiuae/falcon-7b-instruct", model_kwargs={"temperature": 0.9})
+ chain = ConversationChain(llm=llm)
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = ""
+ return chain
+
+class ChatWrapper:
+ def __init__(self, chain_type: str, api_key: str = ''):
+ self.api_key = api_key
+ self.chain_type = chain_type
+ self.history = []
+ self.lock = Lock()
+
+ if self.api_key:
+ if chain_type == 'openai':
+ self.chain = load_chain_openai(self.api_key)
+ elif chain_type == 'falcon':
+ self.chain = load_chain_falcon(self.api_key)
+ else:
+ raise ValueError(f'Invalid chain_type: {chain_type}')
+ else:
+ self.chain = None
+
+ def __call__(self, inp: str):
+ self.lock.acquire()
+ try:
+ if self.chain is None:
+ self.history.append((inp, "Please add your API key to proceed."))
+ return self.history
+
+ output = self.chain.run(input=inp)
+ self.history.append((inp, output))
+ except Exception as e:
+ self.history.append((inp, f"An error occurred: {e}"))
+ finally:
+ self.api_key = '' # API key is cleared after running each chain
+ self.lock.release()
+
+ return self.history
\ No newline at end of file