Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vectorstore/* filter=lfs diff=lfs merge=lfs -text
vectorstore/*.sqlite filter=lfs diff=lfs merge=lfs -text
vectorstore/**/*.bin filter=lfs diff=lfs merge=lfs -text
15 changes: 13 additions & 2 deletions src/paper_query/data/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@
from paper_query.llm import setup_model


def pypdf_loader(file_path: str) -> Document:
def pypdf_loader(file_path: str, interpret_images: bool = False, **image_kwargs) -> Document:
"""Function to load a PDF file, optionally interpreting images."""
if interpret_images and "model" not in image_kwargs:
raise ValueError("When interpret_images is True, 'model' must be provided in image_kwargs.")

if interpret_images:
return _pypdf_loader_w_images(file_path, **image_kwargs)
else:
return _pypdf_loader(file_path)


def _pypdf_loader(file_path: str) -> Document:
"""Function to load text from a PDF file."""
logger.debug("Loading PDF file using PyPDFLoader")
return PyPDFLoader(file_path, mode="single").load()[0]


def pypdf_loader_w_images(
def _pypdf_loader_w_images(
file_path: str, model: str, provider: str, max_tokens: int = 1024
) -> Document:
"""Function to load text from a PDF file with images."""
Expand Down
3 changes: 2 additions & 1 deletion src/paper_query/llm/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os

from langchain.chat_models import init_chat_model
from langchain_core.language_models.chat_models import BaseChatModel
from loguru import logger


def setup_model(model_name: str, model_provider: str, **kwargs):
def setup_model(model_name: str, model_provider: str, **kwargs) -> BaseChatModel:
"""Initialize the chat model."""
logger.info(f"Initializing {model_name} model from {model_provider}")
if model_provider == "openai":
Expand Down
16 changes: 9 additions & 7 deletions src/paper_query/ui/strain_relief_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def strain_relief_chatbot():
"""Chatbot for the StrainRelief paper."""
initialize_session_state()

st.title("The StrainRelief Chatbot")
st.title("StrainReliefChat")
chat_tab, about_tab = st.tabs(["Chat", "About"])

st.sidebar.title("API Configuration")
Expand All @@ -46,12 +46,14 @@ def strain_relief_chatbot():
# Display current model
st.sidebar.markdown(f"Using **{st.session_state.model_name}** model.")

st.session_state.chatbot = HybridQueryChatbot(
model_name=st.session_state.model_name.lower(),
model_provider="openai",
paper_path=str(assets_dir / "strainrelief_preprint.pdf"),
references_dir=str(assets_dir / "references"),
)
# Only instantiate chatbot once and store in session state
if st.session_state.chatbot is None:
st.session_state.chatbot = HybridQueryChatbot(
model_name=st.session_state.model_name.lower(),
model_provider="openai",
paper_path=str(assets_dir / "strainrelief_preprint.pdf"),
references_dir=str(assets_dir / "references"),
)

with chat_tab:
if "messages" not in st.session_state:
Expand Down
5 changes: 2 additions & 3 deletions test/data/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
from paper_query.data.loaders import (
code_loader,
pypdf_loader,
pypdf_loader_w_images,
references_loader,
)


def test_pypdf_loader(test_assets_dir):
"""Test the pypdf_loader function."""
path = test_assets_dir / "example_pdf.pdf"
doc = pypdf_loader(path)
doc = pypdf_loader(path, interpret_images=False)
assert isinstance(doc, Document)


Expand All @@ -22,7 +21,7 @@ def test_pypdf_loader_w_images(test_assets_dir):
"""Test the pypdf_loader_w_images function."""
path = test_assets_dir / "example_pdf.pdf"
# TODO: change to free model
doc = pypdf_loader_w_images(path, "gpt-4.1-nano", "openai")
doc = pypdf_loader(path, interpret_images=True, model="gpt-4.1-nano", provider="openai")
assert isinstance(doc, Document)


Expand Down
Git LFS file not shown
3 changes: 3 additions & 0 deletions vectorstore/30412df4-0651-48bc-86f1-8c77209061b8/header.bin
Git LFS file not shown
Binary file not shown.
3 changes: 3 additions & 0 deletions vectorstore/30412df4-0651-48bc-86f1-8c77209061b8/length.bin
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions vectorstore/chroma.sqlite3
Git LFS file not shown
Loading