AEO / pages /2_Generate_Personas.py
ibibek's picture
Upload 26 files
720ee15
raw
history blame
1.85 kB
import os
import sys
#from dotenv import load_dotenv
from langchain.document_loaders import PyPDFLoader
from langchain.document_loaders import UnstructuredMarkdownLoader
from langchain.document_loaders import TextLoader
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import Chroma
from langchain.chat_models import ChatOpenAI
from langchain.chains import ConversationalRetrievalChain
from langchain.text_splitter import CharacterTextSplitter
from langchain.agents.agent_toolkits import create_retriever_tool
from langchain.agents.agent_toolkits import create_conversational_retrieval_agent
from langchain.chat_models import ChatOpenAI
import streamlit as st
st.subheader("In this example you can generate fake personas")
OpenAI_Key = st.text_input(" Please enter your OpenAI key here to continue")
# only continue if the key is given
if OpenAI_Key:
os.environ['OPENAI_API_KEY'] = OpenAI_Key
vectordb = Chroma(persist_directory="./data", embedding_function=OpenAIEmbeddings())
retriever = vectordb.as_retriever()
tool = create_retriever_tool(
retriever,
"search_AEO",
"Searches and returns documents regarding adversary engagement."
)
tools = [tool]
llm = ChatOpenAI(model_name="gpt-4", temperature = 0)
agent_executor = create_conversational_retrieval_agent(llm, tools, verbose=True)
st.subheader("In this example you can generate the fake personas")
user_input = st.text_area("Enter your description here ", "", height=200)
if user_input:
st.subheader("Generated Personas")
prompt_1 = "### Instruction: Based on the Mitre Engagement Matrix please creae a fake personas with below description. ### Description" + user_input
result = agent_executor({"input":prompt_1 })
st.write(result['output'])