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 gradio as gr """# Space Implementation""" clerkieExamples=["how do I use langchain?", "How do I create an agent with custom LLMChain?"] import requests import random import gradio as gr import openai import re def chat(message, history): print(message) history = history or [] endpoint = 'https://clerkie-langchain-server-bot.ishaan-jaff.repl.co/langchain_agent?user_query=' response = requests.get(endpoint + message).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(css=".gradio-container {background-color: #0d1116;}") as demo: user_state=gr.State([]) gr.Markdown("""# Welcome to Clerkie LangChain 🤖""") gr.Markdown("""Clerkie LangChain can answer questions about the langchain code repo""") gr.Markdown("""### [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)