-
Notifications
You must be signed in to change notification settings - Fork 0
Rest api #20
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
Merged
Rest api #20
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,40 @@ | ||
| from typing import List, Tuple, Optional | ||
| from dataclasses import dataclass | ||
|
|
||
| @dataclass | ||
| class LoaderConfig: | ||
| path: str | ||
| file_extensions: Optional[List[str]] = None | ||
| uri_replacement: Optional[Tuple[str, str]] = None | ||
|
|
||
|
|
||
| @dataclass | ||
| class WebLoaderConfig: | ||
| url: str | ||
| uri_replacement: Optional[Tuple[str, str]] = None | ||
|
|
||
|
|
||
| DOC_LOADER_CONFIGS = [ | ||
| LoaderConfig( | ||
| path="/Users/nullchimp/Projects/customer-security-trust/FAQ", | ||
| file_extensions=['.md'], | ||
| uri_replacement=( | ||
| "/Users/nullchimp/Projects/customer-security-trust/FAQ", | ||
| "https://github.com/github/customer-security-trust/blob/main/FAQ" | ||
| ) | ||
| ), | ||
| LoaderConfig( | ||
| path="/Users/nullchimp/Projects/github-docs/content-copilot", | ||
| file_extensions=['.md'] | ||
| ) | ||
| ] | ||
|
|
||
| WEB_LOADER_CONFIGS = [ | ||
| WebLoaderConfig( | ||
| url="http://localhost:4000/en/enterprise-cloud@latest", | ||
| uri_replacement=( | ||
| "http://localhost:4000", | ||
| "https://docs.github.com" | ||
| ) | ||
| ) | ||
| ] |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| import uuid | ||
| from core.rag.schema import DocumentChunk | ||
|
|
||
| from . import EmbeddingService | ||
|
|
||
This file contains hidden or 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 hidden or 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,114 @@ | ||
| import pytest | ||
| from unittest.mock import Mock, patch | ||
| from scripts.loader_config import DOC_LOADER_CONFIGS, WEB_LOADER_CONFIGS, LoaderConfig, WebLoaderConfig | ||
|
|
||
|
|
||
| def test_loader_config_structure(): | ||
| assert len(DOC_LOADER_CONFIGS) >= 1 | ||
| assert all(isinstance(config, LoaderConfig) for config in DOC_LOADER_CONFIGS) | ||
|
|
||
| first_config = DOC_LOADER_CONFIGS[0] | ||
| assert first_config.path | ||
| assert first_config.file_extensions | ||
| assert first_config.uri_replacement | ||
|
|
||
|
|
||
| def test_web_loader_config_structure(): | ||
| assert len(WEB_LOADER_CONFIGS) >= 1 | ||
| assert all(isinstance(config, WebLoaderConfig) for config in WEB_LOADER_CONFIGS) | ||
|
|
||
| first_config = WEB_LOADER_CONFIGS[0] | ||
| assert first_config.url | ||
| assert first_config.uri_replacement | ||
|
|
||
|
|
||
| def test_loader_config_uri_replacement(): | ||
| config = LoaderConfig( | ||
| path="/test/path", | ||
| file_extensions=['.md'], | ||
| uri_replacement=("/old/path", "https://new.url") | ||
| ) | ||
|
|
||
| assert config.uri_replacement[0] == "/old/path" | ||
| assert config.uri_replacement[1] == "https://new.url" | ||
|
|
||
|
|
||
| def test_web_loader_config_uri_replacement(): | ||
| config = WebLoaderConfig( | ||
| url="http://localhost:4000/test", | ||
| uri_replacement=("http://localhost:4000", "https://docs.github.com") | ||
| ) | ||
|
|
||
| assert config.uri_replacement[0] == "http://localhost:4000" | ||
| assert config.uri_replacement[1] == "https://docs.github.com" | ||
|
|
||
|
|
||
| def test_doc_loader_config_validation(): | ||
| """Test that DOC_LOADER_CONFIGS has valid configuration for doc_loader.py logic""" | ||
| from scripts.loader_config import DOC_LOADER_CONFIGS | ||
|
|
||
| config = DOC_LOADER_CONFIGS[0] | ||
| assert config.path == "/Users/nullchimp/Projects/customer-security-trust/FAQ" | ||
| assert config.file_extensions == ['.md'] | ||
| assert config.uri_replacement is not None | ||
| assert config.uri_replacement == ( | ||
| "/Users/nullchimp/Projects/customer-security-trust/FAQ", | ||
| "https://github.com/github/customer-security-trust/blob/main/FAQ" | ||
| ) | ||
|
|
||
| # Test that the second config doesn't have URI replacement | ||
| config2 = DOC_LOADER_CONFIGS[1] | ||
| assert config2.path == "/Users/nullchimp/Projects/github-docs/content-copilot" | ||
| assert config2.file_extensions == ['.md'] | ||
| assert config2.uri_replacement is None | ||
|
|
||
|
|
||
| def test_doc_loader_uri_replacement_logic(): | ||
| config = DOC_LOADER_CONFIGS[0] | ||
|
|
||
| # Simulate source URI that would come from DocumentLoader | ||
| mock_source_uri = "/Users/nullchimp/Projects/customer-security-trust/FAQ/security-faq.md" | ||
|
|
||
| if config.uri_replacement: | ||
| old_pattern, new_pattern = config.uri_replacement | ||
| # This is the actual logic from doc_loader.py | ||
| new_uri = mock_source_uri.replace(old_pattern, new_pattern) | ||
|
|
||
| expected_uri = "https://github.com/github/customer-security-trust/blob/main/FAQ/security-faq.md" | ||
| assert new_uri == expected_uri | ||
|
|
||
|
|
||
| def test_web_loader_uri_replacement_logic(): | ||
| config = WEB_LOADER_CONFIGS[0] | ||
|
|
||
| # Simulate source URI that would come from WebLoader | ||
| mock_source_uri = "http://localhost:4000/en/enterprise-cloud@latest" | ||
| mock_source_name = "some-page.md" | ||
|
|
||
| if config.uri_replacement: | ||
| old_pattern, new_pattern = config.uri_replacement | ||
| # This is the actual logic from url_loader.py | ||
| new_uri = f"{mock_source_uri.replace(old_pattern, new_pattern)}" | ||
|
|
||
| expected_uri = "https://docs.github.com/en/enterprise-cloud@latest" | ||
| assert new_uri == expected_uri | ||
|
|
||
|
|
||
| def test_config_has_expected_structure(): | ||
| # Test that we have the expected number of configs | ||
| assert len(DOC_LOADER_CONFIGS) == 2 | ||
| assert len(WEB_LOADER_CONFIGS) == 1 | ||
|
|
||
| # Test first doc loader config (with URI replacement) | ||
| first_doc_config = DOC_LOADER_CONFIGS[0] | ||
| assert first_doc_config.uri_replacement is not None | ||
|
|
||
| # Test second doc loader config (without URI replacement) | ||
| second_doc_config = DOC_LOADER_CONFIGS[1] | ||
| assert second_doc_config.path == "/Users/nullchimp/Projects/github-docs/content-copilot" | ||
| assert second_doc_config.uri_replacement is None | ||
|
|
||
| # Test web loader config | ||
| web_config = WEB_LOADER_CONFIGS[0] | ||
| assert web_config.url == "http://localhost:4000/en/enterprise-cloud@latest" | ||
| assert web_config.uri_replacement is not None |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new history tracking in process_query isn't covered by existing tests. Please add unit tests to verify that history is correctly updated when requests succeed or fail.