diff --git a/open_notebook/exceptions.py b/open_notebook/exceptions.py index 4111399..45a5ea4 100644 --- a/open_notebook/exceptions.py +++ b/open_notebook/exceptions.py @@ -10,6 +10,12 @@ class DatabaseOperationError(OpenNotebookError): pass +class UnsupportedTypeException(OpenNotebookError): + """Raised when an unsupported type is provided.""" + + pass + + class NoSchemaFound(OpenNotebookError): """Raised when a database schema is not found.""" diff --git a/open_notebook/graphs/content_process.py b/open_notebook/graphs/content_process.py index 7475814..04a0d66 100644 --- a/open_notebook/graphs/content_process.py +++ b/open_notebook/graphs/content_process.py @@ -16,6 +16,7 @@ from youtube_transcript_api import YouTubeTranscriptApi # type: ignore from youtube_transcript_api.formatters import TextFormatter # type: ignore from open_notebook.config import CONFIG +from open_notebook.exceptions import UnsupportedTypeException class SourceState(TypedDict): @@ -513,7 +514,9 @@ def file_type_edge(data: SourceState): elif data.get("identified_type").startswith("audio"): return "extract_audio" else: - return "end" + raise UnsupportedTypeException( + f"Unsupported file type: {data.get('identified_type')}" + ) workflow = StateGraph(SourceState) diff --git a/stream_app/source.py b/stream_app/source.py index bd4b030..20855e1 100644 --- a/stream_app/source.py +++ b/stream_app/source.py @@ -9,6 +9,7 @@ from loguru import logger from open_notebook.config import UPLOADS_FOLDER from open_notebook.domain import Asset, Source +from open_notebook.exceptions import UnsupportedTypeException from open_notebook.graphs.content_process import graph from open_notebook.graphs.multipattern import graph as transform_graph from open_notebook.utils import surreal_clean @@ -138,17 +139,31 @@ def add_source(session_id): logger.debug("Adding source") with st.status("Processing...", expanded=True): st.write("Processing document...") - result = graph.invoke(req) - st.write("Saving..") - source = Source( - asset=Asset(url=req.get("url"), file_path=req.get("file_path")), - full_text=surreal_clean(result["content"]), - title=result.get("title"), - ) - source.save() - source.add_to_notebook(st.session_state[session_id]["notebook"].id) - st.write("Summarizing...") - source.generate_toc_and_title() + try: + result = graph.invoke(req) + st.write("Saving..") + source = Source( + asset=Asset(url=req.get("url"), file_path=req.get("file_path")), + full_text=surreal_clean(result["content"]), + title=result.get("title"), + ) + source.save() + source.add_to_notebook(st.session_state[session_id]["notebook"].id) + st.write("Summarizing...") + source.generate_toc_and_title() + except UnsupportedTypeException: + st.warning( + "This type of content is not supported yet. If you think it should be, let us know on the project Issues's page" + ) + st.link_button( + "Go to Github Issues", + url="https://www.github.com/lfnovo/open_notebook/issues", + ) + st.stop() + + except Exception as e: + st.error(e) + return st.rerun()