Skip to content

Commit

Permalink
updated pipeline to avoid corner case with empty item
Browse files Browse the repository at this point in the history
  • Loading branch information
exowanderer committed Nov 8, 2024
1 parent 22e1300 commit ccc02d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions wikidatachat/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,13 @@ async def api(
logger.debug(f'{answer=}')

# Return the processed answer and sources.
return {
"answer": answer.data.content,
"sources": sources
}
if hasattr(answer.data, 'content'):
return {
"answer": answer.data.content,
"sources": sources
}
else:
return {
"answer": '',
"sources": sources
}
2 changes: 2 additions & 0 deletions wikidatachat/vector_store_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tqdm import tqdm

from haystack import Document # , Pipeline
from haystack.utils import ComponentDevice
from haystack.components.embedders import SentenceTransformersDocumentEmbedder
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
Expand Down Expand Up @@ -189,6 +190,7 @@ def make_embedder(embedding_model: str = EMBEDDING_MODEL, device: str = 'cpu'):
"""
# Use GPU if available, otherwise fallback to CPU.
device = "cuda" if torch.cuda.is_available() else device
device = ComponentDevice.from_str(device)

logger.info( # Log the name of the embedding model being used.
'GPU is available. Using GPU.'
Expand Down

0 comments on commit ccc02d9

Please sign in to comment.