improve handling of bad content types
This commit is contained in:
parent
8e91574938
commit
790d59547b
3 changed files with 36 additions and 12 deletions
|
|
@ -10,6 +10,12 @@ class DatabaseOperationError(OpenNotebookError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class UnsupportedTypeException(OpenNotebookError):
|
||||||
|
"""Raised when an unsupported type is provided."""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NoSchemaFound(OpenNotebookError):
|
class NoSchemaFound(OpenNotebookError):
|
||||||
"""Raised when a database schema is not found."""
|
"""Raised when a database schema is not found."""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ from youtube_transcript_api import YouTubeTranscriptApi # type: ignore
|
||||||
from youtube_transcript_api.formatters import TextFormatter # type: ignore
|
from youtube_transcript_api.formatters import TextFormatter # type: ignore
|
||||||
|
|
||||||
from open_notebook.config import CONFIG
|
from open_notebook.config import CONFIG
|
||||||
|
from open_notebook.exceptions import UnsupportedTypeException
|
||||||
|
|
||||||
|
|
||||||
class SourceState(TypedDict):
|
class SourceState(TypedDict):
|
||||||
|
|
@ -513,7 +514,9 @@ def file_type_edge(data: SourceState):
|
||||||
elif data.get("identified_type").startswith("audio"):
|
elif data.get("identified_type").startswith("audio"):
|
||||||
return "extract_audio"
|
return "extract_audio"
|
||||||
else:
|
else:
|
||||||
return "end"
|
raise UnsupportedTypeException(
|
||||||
|
f"Unsupported file type: {data.get('identified_type')}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
workflow = StateGraph(SourceState)
|
workflow = StateGraph(SourceState)
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ from loguru import logger
|
||||||
|
|
||||||
from open_notebook.config import UPLOADS_FOLDER
|
from open_notebook.config import UPLOADS_FOLDER
|
||||||
from open_notebook.domain import Asset, Source
|
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.content_process import graph
|
||||||
from open_notebook.graphs.multipattern import graph as transform_graph
|
from open_notebook.graphs.multipattern import graph as transform_graph
|
||||||
from open_notebook.utils import surreal_clean
|
from open_notebook.utils import surreal_clean
|
||||||
|
|
@ -138,17 +139,31 @@ def add_source(session_id):
|
||||||
logger.debug("Adding source")
|
logger.debug("Adding source")
|
||||||
with st.status("Processing...", expanded=True):
|
with st.status("Processing...", expanded=True):
|
||||||
st.write("Processing document...")
|
st.write("Processing document...")
|
||||||
result = graph.invoke(req)
|
try:
|
||||||
st.write("Saving..")
|
result = graph.invoke(req)
|
||||||
source = Source(
|
st.write("Saving..")
|
||||||
asset=Asset(url=req.get("url"), file_path=req.get("file_path")),
|
source = Source(
|
||||||
full_text=surreal_clean(result["content"]),
|
asset=Asset(url=req.get("url"), file_path=req.get("file_path")),
|
||||||
title=result.get("title"),
|
full_text=surreal_clean(result["content"]),
|
||||||
)
|
title=result.get("title"),
|
||||||
source.save()
|
)
|
||||||
source.add_to_notebook(st.session_state[session_id]["notebook"].id)
|
source.save()
|
||||||
st.write("Summarizing...")
|
source.add_to_notebook(st.session_state[session_id]["notebook"].id)
|
||||||
source.generate_toc_and_title()
|
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()
|
st.rerun()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue