Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Several Exceptions in Workflow Usage #12075

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
4 changes: 3 additions & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ RUN \
fonts-noto-cjk \
# install libmagic to support the use of python-magic guess MIMETYPE
libmagic1 \
# install libreoffice to support the use of convert ppt file to pptx file
libreoffice \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to avoid installing this library? It's too large.

&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -81,4 +83,4 @@ RUN chmod +x /entrypoint.sh
ARG COMMIT_SHA
ENV COMMIT_SHA=${COMMIT_SHA}

ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
5 changes: 4 additions & 1 deletion api/controllers/files/image_preview.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from urllib.parse import quote

from flask import Response, request
from flask_restful import Resource, reqparse # type: ignore
from werkzeug.exceptions import NotFound
Expand Down Expand Up @@ -71,7 +73,8 @@ def get(self, file_id):
if upload_file.size > 0:
response.headers["Content-Length"] = str(upload_file.size)
if args["as_attachment"]:
response.headers["Content-Disposition"] = f"attachment; filename={upload_file.name}"
safe_filename = quote(upload_file.name)
response.headers["Content-Disposition"] = f"attachment; filename*=UTF-8''{safe_filename}"

return response

Expand Down
4 changes: 2 additions & 2 deletions api/core/app/apps/completion/app_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ def generate_more_like_this(
# parse files
file_extra_config = FileUploadConfigManager.convert(override_model_config_dict)
if file_extra_config:
file_objs = file_factory.build_from_mappings(
mappings=message.message_files,
file_objs = file_factory.build_from_message_files(
message_files=message.message_files,
tenant_id=app_model.tenant_id,
config=file_extra_config,
)
Expand Down
7 changes: 6 additions & 1 deletion api/core/workflow/nodes/document_extractor/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from collections.abc import Mapping, Sequence
from typing import Any, cast

import chardet
import docx
import pandas as pd
import pypdfium2 # type: ignore
Expand Down Expand Up @@ -292,7 +293,11 @@ def _extract_text_from_file(file: File):

def _extract_text_from_csv(file_content: bytes) -> str:
try:
csv_file = io.StringIO(file_content.decode("utf-8", "ignore"))
detected_encoding = chardet.detect(file_content)["encoding"]
if detected_encoding is None:
csv_file = io.StringIO(file_content.decode("utf-8", "ignore"))
else:
csv_file = io.StringIO(file_content.decode(detected_encoding, "replace"))
csv_reader = csv.reader(csv_file)
rows = list(csv_reader)

Expand Down
2 changes: 1 addition & 1 deletion api/core/workflow/nodes/list_operator/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def _endswith(value: str) -> Callable[[str], bool]:


def _is(value: str) -> Callable[[str], bool]:
return lambda x: x is value
return lambda x: x == value


def _in(value: str | Sequence[str]) -> Callable[[str], bool]:
Expand Down