krrishD's picture
Update app.py
a091111
from langchain import OpenAI, LLMChain
from langchain.agents import initialize_agent, Tool, ZeroShotAgent, AgentExecutor
from langchain.prompts import PromptTemplate
from langchain.prompts.few_shot import FewShotPromptTemplate
import requests
import random
import openai
import re
import gradio as gr
import os
"""# Space Implementation"""
clerkieExamples=["how do I use langchain?", "How do I create an agent with custom LLMChain?"]
def chat(message, history):
print(message)
history = history or []
endpoint = os.environ.get("langchain_bot_api_endpoint")
user_query = endpoint + message
print("user_query: ", user_query)
response = requests.get(user_query).json()["response"]["output"]
# split on code
split_string = response.split("Code")
explanation = split_string[0]
history.append((message, explanation))
code_and_possible_links = "Code " + split_string[1]
if "Here is a list of documents that I viewed" in code_and_possible_links:
split_string = code_and_possible_links.split("Here")
code_sample = split_string[0]
history.append(("", code_sample))
relevant_links = "Here " + split_string[1]
history.append(("", relevant_links))
else:
history.append(("", code_and_possible_links))
return history, history
def set_text(inp):
return inp
def clear(arg):
return ""
with gr.Blocks() as demo:
user_state=gr.State([])
gr.Markdown("""# Hi, I'm Clerkie πŸ€–""")
gr.Markdown("""I can help you get started / answer any question you have about the [Langchain: Build AI apps with LLMs](https://github.com/hwchase17/langchain). If I fail to answer your question, please email me @ clerkieai@gmail.com, and I will make sure you get an answer within an hour.""")
gr.Markdown("""### Want some help handling support questions for your open source project/devtool/etc.? Let me know πŸ‘‰ [clerkie.co](https://clerkie.co/)""")
with gr.Row():
with gr.Column():
output = gr.Chatbot().style(color_map=("orange", "green"))
inp = gr.Textbox(placeholder="Enter your question here")
print(type(inp))
btn = gr.Button("Send")
inp.submit(chat, [inp, user_state], [output, user_state])
inp.submit(clear, inp, inp)
btn.click(chat, [inp, user_state], [output, user_state])
btn.click(clear, inp, inp)
gr.Markdown("""### need help? got feedback? have thoughts? etc. ➜ Join the [Discord](https://discord.gg/KvG3azf39U)""")
gr.Examples(clerkieExamples,
inputs=inp,
cache_examples=False,
)
if __name__ == "__main__":
demo.launch(debug=True)