-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docs and tests for WebScraperStage (#1349)
Closes #1283 Authors: - Christopher Harris (https://github.com/cwharris) Approvers: - Devin Robison (https://github.com/drobison00) URL: #1349
- Loading branch information
Showing
4 changed files
with
108 additions
and
15 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
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,28 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pytest | ||
|
||
from _utils import import_or_skip | ||
|
||
|
||
@pytest.fixture(name="nemollm", autouse=True, scope='session') | ||
def nemollm_fixture(fail_missing: bool): | ||
""" | ||
All of the tests in this subdir require nemollm | ||
""" | ||
skip_reason = ("Tests for the WebScraperStage require the langchain package to be installed, to install this run:\n" | ||
"`mamba env update -n ${CONDA_DEFAULT_ENV} --file docker/conda/environments/cuda11.8_examples.yml`") | ||
yield import_or_skip("langchain", reason=skip_reason, fail_missing=fail_missing) |
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,49 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import types | ||
|
||
import pytest | ||
|
||
import cudf | ||
|
||
from _utils import TEST_DIRS | ||
from _utils import assert_results | ||
from morpheus.config import Config | ||
from morpheus.pipeline import LinearPipeline | ||
from morpheus.stages.input.in_memory_source_stage import InMemorySourceStage | ||
from morpheus.stages.output.compare_dataframe_stage import CompareDataFrameStage | ||
|
||
|
||
@pytest.mark.slow | ||
@pytest.mark.use_python | ||
@pytest.mark.use_cudf | ||
@pytest.mark.import_mod(os.path.join(TEST_DIRS.examples_dir, 'llm/common/web_scraper_stage.py')) | ||
def test_http_client_source_stage_pipe(config: Config, mock_rest_server: str, import_mod: types.ModuleType): | ||
url = f"{mock_rest_server}/www/index" | ||
|
||
df = cudf.DataFrame({"link": [url]}) | ||
|
||
df_expected = cudf.DataFrame({"link": [url], "page_content": "website title some paragraph"}) | ||
|
||
pipe = LinearPipeline(config) | ||
pipe.set_source(InMemorySourceStage(config, [df])) | ||
pipe.add_stage(import_mod.WebScraperStage(config, chunk_size=config.feature_length)) | ||
comp_stage = pipe.add_stage(CompareDataFrameStage(config, compare_df=df_expected)) | ||
pipe.run() | ||
|
||
print(comp_stage.get_messages()) | ||
|
||
assert_results(comp_stage.get_results()) |
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,4 @@ | ||
HTTP/1.1 200 OK | ||
Content-Type: application/json | ||
|
||
<!DOCTYPE html><html><body><title>website title</title><p>some paragraph</p></body></html> |