import datetime import os import gradio as gr import langchain import weaviate from langchain.vectorstores import Weaviate from chain import get_new_chain1 WEAVIATE_URL = "https://tro.weaviate.network/" def get_weaviate_store(): client = weaviate.Client( url=WEAVIATE_URL, additional_headers={"X-OpenAI-Api-Key": os.environ["OPENAI_API_KEY"]}, ) return Weaviate(client, "Paragraphs", "content") def set_openai_api_key(api_key, agent): if api_key: os.environ["OPENAI_API_KEY"] = api_key vectorstore = get_weaviate_store() # Calls Vector DB qa_chain = get_new_chain1(vectorstore) # inputs Charmed Game DB into new Quest chain os.environ["OPENAI_API_KEY"] = "" return qa_chain def chat(inp, history, agent): # inp: User Input history = history or [] if agent is None: history.append((inp, "Please paste your OpenAI key to use")) return history, history print("\n==== date/time: " + str(datetime.datetime.now()) + " ====") print("inp: " + inp) history = history or [] output = agent({"game_description": inp, "chat_history": history}) # agent takes in input and history if any game_environment = output["game_environment"] # answer is appended to chat history history.append((inp, game_environment)) # print(history) return history, history block = gr.Blocks(css=".gradio-container {background-color: darkpurple}") with block: with gr.Row(): gr.Markdown("