Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,6 +20,7 @@ from google.oauth2 import service_account
|
|
| 20 |
import tempfile
|
| 21 |
import os
|
| 22 |
from langchain.llms import OpenAI # Import the OpenAI class
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
|
|
@@ -183,24 +184,27 @@ def get_embeddings_model():
|
|
| 183 |
|
| 184 |
# QA System Initialization (qa_system.py)
|
| 185 |
|
|
|
|
| 186 |
@st.cache_resource
|
| 187 |
def initialize_qa_system(_vector_store):
|
| 188 |
try:
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
| 191 |
api_key=os.environ.get('OPENAI_API_KEY'),
|
| 192 |
-
prompt_template="Extract the specific details relevant to the query accurately from the document without adding additional information that is not present in the text. Provide concise, clear responses that stay within the boundaries of the document's content."
|
| 193 |
)
|
| 194 |
|
| 195 |
qa_pipeline = RetrievalQA.from_chain_type(
|
| 196 |
llm=llm,
|
| 197 |
-
retriever=_vector_store.as_retriever()
|
|
|
|
| 198 |
)
|
| 199 |
return qa_pipeline
|
| 200 |
except Exception as e:
|
| 201 |
st.error(f"Error initializing QA system: {e}")
|
| 202 |
return None
|
| 203 |
-
|
| 204 |
# Streamlit App Interface (app.py)
|
| 205 |
def main():
|
| 206 |
st.title("**SYNAPTYX - RFP Analysis Agent**")
|
|
|
|
| 20 |
import tempfile
|
| 21 |
import os
|
| 22 |
from langchain.llms import OpenAI # Import the OpenAI class
|
| 23 |
+
from langchain.chat_models import ChatOpenAI # Import ChatOpenAI
|
| 24 |
|
| 25 |
|
| 26 |
|
|
|
|
| 184 |
|
| 185 |
# QA System Initialization (qa_system.py)
|
| 186 |
|
| 187 |
+
|
| 188 |
@st.cache_resource
|
| 189 |
def initialize_qa_system(_vector_store):
|
| 190 |
try:
|
| 191 |
+
# Use ChatOpenAI instead of OpenAI
|
| 192 |
+
llm = ChatOpenAI(
|
| 193 |
+
temperature=0,
|
| 194 |
+
model_name="gpt-4", # Or another OpenAI model like "gpt-3.5-turbo"
|
| 195 |
api_key=os.environ.get('OPENAI_API_KEY'),
|
|
|
|
| 196 |
)
|
| 197 |
|
| 198 |
qa_pipeline = RetrievalQA.from_chain_type(
|
| 199 |
llm=llm,
|
| 200 |
+
retriever=_vector_store.as_retriever(),
|
| 201 |
+
chain_type="stuff" # Use "stuff" chain type for chat models
|
| 202 |
)
|
| 203 |
return qa_pipeline
|
| 204 |
except Exception as e:
|
| 205 |
st.error(f"Error initializing QA system: {e}")
|
| 206 |
return None
|
| 207 |
+
|
| 208 |
# Streamlit App Interface (app.py)
|
| 209 |
def main():
|
| 210 |
st.title("**SYNAPTYX - RFP Analysis Agent**")
|