diff --git a/.history/app_20230720012201.py b/.history/app_20230720012201.py
deleted file mode 100644
index 8755959ea3d818db8ce7219c4d8392344baeca20..0000000000000000000000000000000000000000
--- a/.history/app_20230720012201.py
+++ /dev/null
@@ -1,105 +0,0 @@
-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
deleted file mode 100644
index 8755959ea3d818db8ce7219c4d8392344baeca20..0000000000000000000000000000000000000000
--- a/.history/app_20230720115617.py
+++ /dev/null
@@ -1,105 +0,0 @@
-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
deleted file mode 100644
index 9b79a5724153668d1d06fc3f4596bc9b8fd5988e..0000000000000000000000000000000000000000
--- a/.history/app_20230720115808.py
+++ /dev/null
@@ -1,165 +0,0 @@
-# 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
deleted file mode 100644
index 8557fa00a44526b04b55ce979fbb58f61cb0f132..0000000000000000000000000000000000000000
--- a/.history/app_20230720115842.py
+++ /dev/null
@@ -1,274 +0,0 @@
-# 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
deleted file mode 100644
index 17f29aab4a61e68eaafbb8ab8b8d8cf3e35a5abb..0000000000000000000000000000000000000000
--- a/.history/app_20230720120047.py
+++ /dev/null
@@ -1,116 +0,0 @@
-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
deleted file mode 100644
index 4228fbb9bb5ade414f9d25f771309406be6d53b0..0000000000000000000000000000000000000000
--- a/.history/app_20230720120625.py
+++ /dev/null
@@ -1,115 +0,0 @@
-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
deleted file mode 100644
index 182990dec6a1dc4815a93cbd788a14f1f7fd2254..0000000000000000000000000000000000000000
--- a/.history/app_20230720120933.py
+++ /dev/null
@@ -1,60 +0,0 @@
-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
deleted file mode 100644
index be2ceac5471a78269dbd5f8fda7bca68dd0d1db6..0000000000000000000000000000000000000000
--- a/.history/app_20230720130430.py
+++ /dev/null
@@ -1,53 +0,0 @@
-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
deleted file mode 100644
index 03576d9110b9f13abb6ff5a56291ac510aa59b09..0000000000000000000000000000000000000000
--- a/.history/app_20230720130724.py
+++ /dev/null
@@ -1,53 +0,0 @@
-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
deleted file mode 100644
index 6cfb2e86b81bc45a1f1ed0df91afaeb5056b5cf9..0000000000000000000000000000000000000000
--- a/.history/app_20230720131115.py
+++ /dev/null
@@ -1,54 +0,0 @@
-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
deleted file mode 100644
index 8e2cc4930f5bb489f2859770f260b32e022b0f2e..0000000000000000000000000000000000000000
--- a/.history/app_20230720131814.py
+++ /dev/null
@@ -1,55 +0,0 @@
-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
deleted file mode 100644
index 740df948edfd57210bc84fe5699b52cbf042bdd3..0000000000000000000000000000000000000000
--- a/.history/app_20230720132136.py
+++ /dev/null
@@ -1,55 +0,0 @@
-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
deleted file mode 100644
index ea03e25a959af25f6f7217641ff2a9710b35c851..0000000000000000000000000000000000000000
--- a/.history/app_20230720132503.py
+++ /dev/null
@@ -1,55 +0,0 @@
-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
deleted file mode 100644
index ea03e25a959af25f6f7217641ff2a9710b35c851..0000000000000000000000000000000000000000
--- a/.history/app_20230720132518.py
+++ /dev/null
@@ -1,55 +0,0 @@
-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
deleted file mode 100644
index 182990dec6a1dc4815a93cbd788a14f1f7fd2254..0000000000000000000000000000000000000000
--- a/.history/app_20230720133035.py
+++ /dev/null
@@ -1,60 +0,0 @@
-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
deleted file mode 100644
index 675d6cfe3d8b3476c897f955bcfa6da645fbeaab..0000000000000000000000000000000000000000
--- a/.history/app_20230720133118.py
+++ /dev/null
@@ -1,61 +0,0 @@
-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
deleted file mode 100644
index 18a178bd9d1252adafc2ca19949d4719e326a8e7..0000000000000000000000000000000000000000
--- a/.history/app_20230720133714.py
+++ /dev/null
@@ -1,61 +0,0 @@
-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
deleted file mode 100644
index 101876933f1f61eb8791ee1ba782ade8e6657fd9..0000000000000000000000000000000000000000
--- a/.history/app_20230720134604.py
+++ /dev/null
@@ -1,62 +0,0 @@
-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
deleted file mode 100644
index e1359db69f868395bcdb89a38713c84b3aa71668..0000000000000000000000000000000000000000
--- a/.history/app_20230720135305.py
+++ /dev/null
@@ -1,62 +0,0 @@
-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
deleted file mode 100644
index ab398ff312a955564af14dd5dbb871f69980fecb..0000000000000000000000000000000000000000
--- a/.history/app_20230720135438.py
+++ /dev/null
@@ -1,62 +0,0 @@
-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
deleted file mode 100644
index 7d847ab1c9ee8774409a947c99089c6202227101..0000000000000000000000000000000000000000
--- a/.history/app_20230720135623.py
+++ /dev/null
@@ -1,62 +0,0 @@
-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
deleted file mode 100644
index 96809dda2cf6d7b8e1dc858db09bc919a87d12d8..0000000000000000000000000000000000000000
--- a/.history/app_20230720135741.py
+++ /dev/null
@@ -1,66 +0,0 @@
-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
deleted file mode 100644
index f1779752873bc36ffb2a95ac399f654e26e2d583..0000000000000000000000000000000000000000
--- a/.history/app_20230720140423.py
+++ /dev/null
@@ -1,64 +0,0 @@
-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
deleted file mode 100644
index f1779752873bc36ffb2a95ac399f654e26e2d583..0000000000000000000000000000000000000000
--- a/.history/app_20230720140424.py
+++ /dev/null
@@ -1,64 +0,0 @@
-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
deleted file mode 100644
index 2171e70de157bff34650cd58fe4df8e53281c4a4..0000000000000000000000000000000000000000
--- a/.history/app_20230720141203.py
+++ /dev/null
@@ -1,66 +0,0 @@
-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
deleted file mode 100644
index ab398ff312a955564af14dd5dbb871f69980fecb..0000000000000000000000000000000000000000
--- a/.history/app_20230720141228.py
+++ /dev/null
@@ -1,62 +0,0 @@
-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
deleted file mode 100644
index fa893519a259853477ea029bc34c19fe47700d62..0000000000000000000000000000000000000000
--- a/.history/app_20230720141747.py
+++ /dev/null
@@ -1,62 +0,0 @@
-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
deleted file mode 100644
index ab398ff312a955564af14dd5dbb871f69980fecb..0000000000000000000000000000000000000000
--- a/.history/app_20230720141944.py
+++ /dev/null
@@ -1,62 +0,0 @@
-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
deleted file mode 100644
index 86a160c146434aead3432c15ebfdf56861310984..0000000000000000000000000000000000000000
--- a/.history/app_20230720142413.py
+++ /dev/null
@@ -1,70 +0,0 @@
-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
deleted file mode 100644
index 0d02e2f6af80f9bfbf02803cf09482dbe5a41d92..0000000000000000000000000000000000000000
--- a/.history/app_20230720142550.py
+++ /dev/null
@@ -1,71 +0,0 @@
-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
deleted file mode 100644
index e54a36f5dc84b08fb4dd05f0b2a823b0e9e087d6..0000000000000000000000000000000000000000
--- a/.history/app_20230720142627.py
+++ /dev/null
@@ -1,71 +0,0 @@
-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
deleted file mode 100644
index 7002689d732fb0919da2fcc7f0daf7a17b25b01c..0000000000000000000000000000000000000000
--- a/.history/app_20230720142635.py
+++ /dev/null
@@ -1,71 +0,0 @@
-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
deleted file mode 100644
index 02b300b35c3cd1782d1758d978a29d47c9d5e14f..0000000000000000000000000000000000000000
--- a/.history/app_20230720142718.py
+++ /dev/null
@@ -1,69 +0,0 @@
-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
deleted file mode 100644
index 0ed4396b31663f15e7f5cd460dc0be97c1272d17..0000000000000000000000000000000000000000
--- a/.history/app_20230720142924.py
+++ /dev/null
@@ -1,69 +0,0 @@
-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
deleted file mode 100644
index c3e280be341da3d46527c15a40e57bda3997d350..0000000000000000000000000000000000000000
--- a/.history/app_20230720143034.py
+++ /dev/null
@@ -1,68 +0,0 @@
-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
deleted file mode 100644
index f3b22f2a7a12be895d2048e700fd0a0465282846..0000000000000000000000000000000000000000
--- a/.history/app_20230720143041.py
+++ /dev/null
@@ -1,68 +0,0 @@
-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
deleted file mode 100644
index 33730aa4b58a2a1dddaa2b0def37a9977e2b8202..0000000000000000000000000000000000000000
--- a/.history/app_20230720143109.py
+++ /dev/null
@@ -1,68 +0,0 @@
-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
deleted file mode 100644
index 0f754b131a540019f0447ad156eb82aa27a4738c..0000000000000000000000000000000000000000
--- a/.history/app_20230720143123.py
+++ /dev/null
@@ -1,68 +0,0 @@
-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
deleted file mode 100644
index 33730aa4b58a2a1dddaa2b0def37a9977e2b8202..0000000000000000000000000000000000000000
--- a/.history/app_20230720143149.py
+++ /dev/null
@@ -1,68 +0,0 @@
-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
deleted file mode 100644
index 5c73e662b7c7b0071d35af40900daa75bbd8baa3..0000000000000000000000000000000000000000
--- a/.history/app_20230720143312.py
+++ /dev/null
@@ -1,67 +0,0 @@
-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
deleted file mode 100644
index 9ea9ebed9586d77069fdba84f8ec05a7147e11ba..0000000000000000000000000000000000000000
--- a/.history/app_20230720143545.py
+++ /dev/null
@@ -1,72 +0,0 @@
-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
deleted file mode 100644
index 64220b89be25c1b85fbd2ae8c4e8397bfab5c59f..0000000000000000000000000000000000000000
--- a/.history/app_20230720143613.py
+++ /dev/null
@@ -1,72 +0,0 @@
-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
deleted file mode 100644
index 2c259a1dc0e1752a1cb5cea1a0de2189f594144e..0000000000000000000000000000000000000000
--- a/.history/app_20230720143706.py
+++ /dev/null
@@ -1,61 +0,0 @@
-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
deleted file mode 100644
index 2432e4f89dd50cbfbea41d2346cd3c25f130cdb8..0000000000000000000000000000000000000000
--- a/.history/app_20230720143740.py
+++ /dev/null
@@ -1,63 +0,0 @@
-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
deleted file mode 100644
index a5714f179d7cdc5ea3e93f70ac62dc09716d1311..0000000000000000000000000000000000000000
--- a/.history/app_20230720143814.py
+++ /dev/null
@@ -1,63 +0,0 @@
-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
deleted file mode 100644
index b3065358b0c497477e12da6c4980254b821bb1e1..0000000000000000000000000000000000000000
--- a/.history/app_20230720143901.py
+++ /dev/null
@@ -1,61 +0,0 @@
-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
deleted file mode 100644
index ae6c28bf043edbe00586fd3648bbabbca5c9e5cc..0000000000000000000000000000000000000000
--- a/.history/app_20230720144009.py
+++ /dev/null
@@ -1,61 +0,0 @@
-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
deleted file mode 100644
index c3ffd35e40eee423040578715dab8c2b0d5279d0..0000000000000000000000000000000000000000
--- a/.history/app_20230720144049.py
+++ /dev/null
@@ -1,61 +0,0 @@
-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
deleted file mode 100644
index fbf412220c15fa80c300189f87f48cb3c5cb8a7f..0000000000000000000000000000000000000000
--- a/.history/app_20230720144115.py
+++ /dev/null
@@ -1,61 +0,0 @@
-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
deleted file mode 100644
index 230429a74766767a09970acb004bb5ee621e5c0a..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720001200.py
+++ /dev/null
@@ -1,113 +0,0 @@
-# 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
deleted file mode 100644
index b85a5d15116f4385c05b062eeafcff1ffcd6dc5b..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720120907.py
+++ /dev/null
@@ -1,54 +0,0 @@
-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
deleted file mode 100644
index 305354e984a2e79b579babb517bcf6f8fae15d92..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720122456.py
+++ /dev/null
@@ -1,54 +0,0 @@
-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
deleted file mode 100644
index 675828b38651a87cbf0478c23c0c4e02a1b1da18..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720125534.py
+++ /dev/null
@@ -1,53 +0,0 @@
-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
deleted file mode 100644
index cf5e6df8503f4e5f7d5776b2c1582a02543788e1..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720125820.py
+++ /dev/null
@@ -1,54 +0,0 @@
-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
deleted file mode 100644
index 1340e949286e26b66c44dc701f6fdc58656150ee..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720125943.py
+++ /dev/null
@@ -1,55 +0,0 @@
-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
deleted file mode 100644
index a72ae5175861d5c78cd2e7cd87d90413ba9817d4..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720131220.py
+++ /dev/null
@@ -1,55 +0,0 @@
-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
deleted file mode 100644
index 95b4f257d6ee7cb84dd2d5ddd1a655875b8e6ee5..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720131449.py
+++ /dev/null
@@ -1,55 +0,0 @@
-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
deleted file mode 100644
index a72ae5175861d5c78cd2e7cd87d90413ba9817d4..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720131556.py
+++ /dev/null
@@ -1,55 +0,0 @@
-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
deleted file mode 100644
index 305354e984a2e79b579babb517bcf6f8fae15d92..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720132836.py
+++ /dev/null
@@ -1,54 +0,0 @@
-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
deleted file mode 100644
index 8e6b9ac7658d8115fea2ad4eaa4b2e2f565fffad..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720134043.py
+++ /dev/null
@@ -1,55 +0,0 @@
-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
deleted file mode 100644
index ff66005d08a26529b019c6f4039d4c9004636cd4..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720134412.py
+++ /dev/null
@@ -1,55 +0,0 @@
-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
deleted file mode 100644
index 8e6b9ac7658d8115fea2ad4eaa4b2e2f565fffad..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720134442.py
+++ /dev/null
@@ -1,55 +0,0 @@
-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
deleted file mode 100644
index 469808edb69cca1f8a5b2a9113c3093be8058a03..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720134505.py
+++ /dev/null
@@ -1,55 +0,0 @@
-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
deleted file mode 100644
index 469808edb69cca1f8a5b2a9113c3093be8058a03..0000000000000000000000000000000000000000
--- a/.history/src/main_20230720134509.py
+++ /dev/null
@@ -1,55 +0,0 @@
-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