Skip to content

Commit

Permalink
Added an error check when embedding change causes read error
Browse files Browse the repository at this point in the history
  • Loading branch information
3coins committed May 1, 2023
1 parent e45f1ae commit 72b69ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/jupyter-ai/jupyter_ai/actors/ask.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,19 @@ def _process_message(self, message: HumanChatMessage):

self.get_llm_chain()

result = self.llm_chain({"question": query, "chat_history": self.chat_history})
response = result['answer']
self.chat_history.append((query, response))
self.reply(response, message)
try:
result = self.llm_chain({"question": query, "chat_history": self.chat_history})
response = result['answer']
self.chat_history.append((query, response))
self.reply(response, message)
except AssertionError as e:
self.log.error(e)
response = """Sorry, an error occurred while reading the from the learned documents.
If you have changed the embedding provider, try deleting the existing index by running
`/learn -d` command and then re-submitting the `learn <directory>` to learn the documents,
and then asking the question again.
"""
self.reply(response, message)


class Retriever(BaseRetriever):
Expand Down
1 change: 1 addition & 0 deletions packages/jupyter-ai/jupyter_ai/actors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def get_embeddings(self):

if provider.__class__.__name__ != self.embeddings.__class__.__name__:
self.embeddings = provider(**embedding_params)

return self.embeddings

def create_llm_chain(self, provider: Type[BaseProvider], provider_params: Dict[str, str]):
Expand Down

0 comments on commit 72b69ca

Please sign in to comment.