Update functions.py
Browse files- functions.py +3 -42
functions.py
CHANGED
@@ -30,10 +30,7 @@ from langchain.embeddings import HuggingFaceEmbeddings, HuggingFaceBgeEmbeddings
|
|
30 |
from langchain.vectorstores import FAISS
|
31 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
32 |
from langchain.chat_models import ChatOpenAI
|
33 |
-
from langchain.
|
34 |
-
from langchain.chains import ConversationalRetrievalChain, QAGenerationChain, LLMChain
|
35 |
-
from langchain.memory import ConversationBufferMemory
|
36 |
-
from langchain.chains.question_answering import load_qa_chain
|
37 |
|
38 |
from langchain.callbacks import StreamlitCallbackHandler
|
39 |
from langchain.agents import OpenAIFunctionsAgent, AgentExecutor
|
@@ -66,43 +63,6 @@ time_str = time.strftime("%d%m%Y-%H%M%S")
|
|
66 |
HTML_WRAPPER = """<div style="overflow-x: auto; border: 1px solid #e6e9ef; border-radius: 0.25rem; padding: 1rem;
|
67 |
margin-bottom: 2.5rem">{}</div> """
|
68 |
|
69 |
-
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True, output_key='answer')
|
70 |
-
|
71 |
-
|
72 |
-
#Stuff Chain Type Prompt template
|
73 |
-
|
74 |
-
@st.cache_data
|
75 |
-
def load_prompt():
|
76 |
-
|
77 |
-
system_template="""Use only the following pieces of earnings context to answer the users question accurately.
|
78 |
-
Do not use any information not provided in the earnings context and remember you are a to speak like a finance expert.
|
79 |
-
If you don't know the answer, just say 'There is no relevant answer in the given earnings call transcript',
|
80 |
-
don't try to make up an answer.
|
81 |
-
|
82 |
-
ALWAYS return a "SOURCES" part in your answer.
|
83 |
-
The "SOURCES" part should be a reference to the source of the document from which you got your answer.
|
84 |
-
|
85 |
-
Remember, do not reference any information not given in the context.
|
86 |
-
|
87 |
-
If the answer is not available in the given context just say 'There is no relevant answer in the given earnings call transcript'
|
88 |
-
|
89 |
-
Follow the below format when answering:
|
90 |
-
|
91 |
-
Question: {question}
|
92 |
-
SOURCES: [xyz]
|
93 |
-
|
94 |
-
Begin!
|
95 |
-
----------------
|
96 |
-
{context}"""
|
97 |
-
|
98 |
-
messages = [
|
99 |
-
SystemMessagePromptTemplate.from_template(system_template),
|
100 |
-
HumanMessagePromptTemplate.from_template("{question}")
|
101 |
-
]
|
102 |
-
prompt = ChatPromptTemplate.from_messages(messages)
|
103 |
-
|
104 |
-
return prompt
|
105 |
-
|
106 |
|
107 |
###################### Functions #######################################################################################
|
108 |
|
@@ -597,7 +557,8 @@ def create_vectorstore(corpus, title, embedding_model, chunk_size=1000, overlap=
|
|
597 |
vectorstore = FAISS.from_texts(texts, embeddings, metadatas=[{"source": i} for i in range(len(texts))])
|
598 |
|
599 |
return vectorstore
|
600 |
-
|
|
|
601 |
def create_memory_and_agent(query,_docsearch):
|
602 |
|
603 |
'''Embed text and generate semantic search scores'''
|
|
|
30 |
from langchain.vectorstores import FAISS
|
31 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
32 |
from langchain.chat_models import ChatOpenAI
|
33 |
+
from langchain.chains import QAGenerationChain
|
|
|
|
|
|
|
34 |
|
35 |
from langchain.callbacks import StreamlitCallbackHandler
|
36 |
from langchain.agents import OpenAIFunctionsAgent, AgentExecutor
|
|
|
63 |
HTML_WRAPPER = """<div style="overflow-x: auto; border: 1px solid #e6e9ef; border-radius: 0.25rem; padding: 1rem;
|
64 |
margin-bottom: 2.5rem">{}</div> """
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
###################### Functions #######################################################################################
|
68 |
|
|
|
557 |
vectorstore = FAISS.from_texts(texts, embeddings, metadatas=[{"source": i} for i in range(len(texts))])
|
558 |
|
559 |
return vectorstore
|
560 |
+
|
561 |
+
@st.cache_data
|
562 |
def create_memory_and_agent(query,_docsearch):
|
563 |
|
564 |
'''Embed text and generate semantic search scores'''
|