Spaces:
Runtime error
Runtime error
File size: 2,743 Bytes
c50003d dd285c6 9448f41 dd285c6 c50003d 9c4b6c2 155b59a c50003d f7a4d44 c50003d dd285c6 c50003d c1c00d6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
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")
# endpoint = "https://clerkie-langchain-server-bot.ishaan-jaff.repl.co/langchain_agent?user_query="
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)
|