2023-05-13 00:05:31 +03:00
|
|
|
import streamlit as st
|
|
|
|
from langchain.chains import ConversationalRetrievalChain
|
|
|
|
from langchain.memory import ConversationBufferMemory
|
|
|
|
from langchain.llms import OpenAI
|
|
|
|
|
|
|
|
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
|
|
|
|
2023-05-13 00:58:19 +03:00
|
|
|
def chat_with_doc(openai_api_key, vector_store):
|
2023-05-13 00:05:31 +03:00
|
|
|
question = st.text_input("## Ask a question")
|
|
|
|
button = st.button("Ask")
|
|
|
|
if button:
|
2023-05-13 00:58:19 +03:00
|
|
|
qa = ConversationalRetrievalChain.from_llm(OpenAI(model_name=st.session_state['model'], openai_api_key=openai_api_key, temperature=st.session_state['temperature']), vector_store.as_retriever(), memory=memory)
|
2023-05-13 00:05:31 +03:00
|
|
|
result = qa({"question": question})
|
|
|
|
st.write(result["answer"])
|