-
Notifications
You must be signed in to change notification settings - Fork 749
CLI Fixes #322
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
Merged
CLI Fixes #322
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
010f6e1
Added CLI tests
whitead 93b2add
Got confused on recording vs vcr
whitead a1f1d31
Added tests and they fail
whitead 580798d
Fixed field problem
whitead 4f1aa80
rename agents.main.search->agents.main.index_search, make table forma…
mskarlin b554bd7
add exception for python 3.10 handling, lock with pytest-mock
mskarlin d49c4ce
try CI with just one python version
mskarlin 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
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
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,65 @@ | ||
import io | ||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from paperqa.settings import Settings | ||
from paperqa.utils import pqa_directory | ||
|
||
try: | ||
from paperqa.agents import ask, build_index, main, search_query | ||
from paperqa.agents.models import AnswerResponse | ||
except ImportError: | ||
pytest.skip("agents module is not installed", allow_module_level=True) | ||
|
||
|
||
def test_can_modify_settings(): | ||
old_argv = sys.argv | ||
old_stdout = sys.stdout | ||
captured_output = io.StringIO() | ||
try: | ||
sys.argv = "paperqa -s debug --llm=my-model-foo save unit_test".split() | ||
main() | ||
|
||
sys.stdout = captured_output | ||
assert Settings.from_name("unit_test").llm == "my-model-foo" | ||
|
||
sys.argv = "paperqa -s unit_test view".split() | ||
main() | ||
|
||
output = captured_output.getvalue().strip() | ||
assert "my-model-foo" in output | ||
finally: | ||
sys.argv = old_argv | ||
sys.stdout = old_stdout | ||
os.unlink(pqa_directory("settings") / "unit_test.json") | ||
|
||
|
||
def test_cli_ask(agent_index_dir: Path, stub_data_dir: Path): | ||
settings = Settings.from_name("debug") | ||
settings.index_directory = agent_index_dir | ||
settings.paper_directory = stub_data_dir | ||
response = ask( | ||
"How can you use XAI for chemical property prediction?", settings=settings | ||
) | ||
assert response.answer.formatted_answer | ||
|
||
search_result = search_query( | ||
" ".join(response.answer.formatted_answer.split()[:5]), | ||
"answers", | ||
settings, | ||
) | ||
found_answer = search_result[0][0] | ||
assert isinstance(found_answer, AnswerResponse) | ||
assert found_answer.model_dump_json() == response.model_dump_json() | ||
|
||
|
||
def test_cli_can_build_and_search_index(agent_index_dir: Path, stub_data_dir: Path): | ||
settings = Settings.from_name("debug") | ||
settings.index_directory = agent_index_dir | ||
index_name = "test" | ||
build_index(index_name, stub_data_dir, settings) | ||
search_result = search_query("XAI", index_name, settings) | ||
assert search_result |
Oops, something went wrong.
Oops, something went wrong.
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.
Can you add a comment here saying after Python>=3.11
TimeoutError
replacesasyncio.exceptions.TimeoutError