-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
960 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
basic tests | ||
# Please enter the commit message for your changes. Lines starting | ||
# with '#' will be ignored, and an empty message aborts the commit. | ||
# | ||
# On branch text_view | ||
# Changes to be committed: | ||
# modified: backend/danswer/server/query_and_chat/query_backend.py | ||
# modified: backend/tests/integration/common_utils/managers/file.py | ||
# modified: backend/tests/integration/tests/file/test_file_detection.py | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import mimetypes | ||
from typing import cast | ||
from typing import IO | ||
from typing import List | ||
from typing import Tuple | ||
|
||
import requests | ||
|
||
from danswer.file_store.models import FileDescriptor | ||
from tests.integration.common_utils.constants import API_SERVER_URL | ||
from tests.integration.common_utils.constants import GENERAL_HEADERS | ||
from tests.integration.common_utils.test_models import DATestUser | ||
|
||
|
||
class FileManager: | ||
@staticmethod | ||
def upload_files( | ||
files: List[Tuple[str, IO]], | ||
user_performing_action: DATestUser | None = None, | ||
) -> Tuple[List[FileDescriptor], str]: | ||
headers = ( | ||
user_performing_action.headers | ||
if user_performing_action | ||
else GENERAL_HEADERS | ||
) | ||
headers.pop("Content-Type", None) | ||
|
||
files_param = [] | ||
for filename, file_obj in files: | ||
mime_type, _ = mimetypes.guess_type(filename) | ||
if mime_type is None: | ||
mime_type = "application/octet-stream" | ||
files_param.append(("files", (filename, file_obj, mime_type))) | ||
|
||
response = requests.post( | ||
f"{API_SERVER_URL}/chat/file", | ||
files=files_param, | ||
headers=headers, | ||
) | ||
|
||
if not response.ok: | ||
return ( | ||
cast(List[FileDescriptor], []), | ||
f"Failed to upload files - {response.json().get('detail', 'Unknown error')}", | ||
) | ||
|
||
response_json = response.json() | ||
return response_json.get("files", cast(List[FileDescriptor], [])), "" | ||
|
||
@staticmethod | ||
def fetch_uploaded_file( | ||
file_id: str, | ||
user_performing_action: DATestUser | None = None, | ||
) -> bytes: | ||
response = requests.get( | ||
f"{API_SERVER_URL}/chat/file/{file_id}", | ||
headers=user_performing_action.headers | ||
if user_performing_action | ||
else GENERAL_HEADERS, | ||
) | ||
response.raise_for_status() | ||
return response.content |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.