Add tests for max_tokens propagation in LLM methods - #925
Conversation
This test verifies that the max_tokens parameter is correctly propagated to the generate_typed method for different extraction functions.
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
PR Summary by QodoAdd unit tests ensuring max_tokens is forwarded to LLM generate_typed()
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
1. Test not collected
|
| import unittest | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from semantica.semantic_extract.methods import ( |
There was a problem hiding this comment.
1. Test not collected 🐞 Bug ☼ Reliability
The added file tests/optimize reproduce_issue_176.py is unlikely to be collected by pytest because it doesn’t match default test_*.py / *_test.py patterns and includes a space in the filename. As a result, CI likely won’t execute these tests, so the PR won’t actually add coverage.
Agent Prompt
## Issue description
The new test module name (`optimize reproduce_issue_176.py`) won’t be discovered by pytest’s default collection rules and the space in the filename makes it awkward/brittle to run from shells/CI.
## Issue Context
`pyproject.toml` configures `testpaths` but does not override `python_files`, so pytest uses its default module patterns.
## Fix Focus Areas
- pyproject.toml[274-276]
- tests/optimize reproduce_issue_176.py[1-93]
## Suggested fix
- Rename/move the file to a pytest-discoverable name, e.g. `tests/semantic_extract/test_max_tokens_propagation.py` (or `tests/test_max_tokens_propagation.py`).
- Avoid spaces in filenames.
- (Optional) If you truly want nonstandard names, explicitly set `[tool.pytest.ini_options].python_files` in `pyproject.toml`, but renaming is preferred.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| self.assertEqual( | ||
| call_kwargs.get("max_tokens"), | ||
| self.MAX_TOKENS, | ||
| "max_tokens was not propagated correctly", |
There was a problem hiding this comment.
2. Relations max_tokens dropped 🐞 Bug ≡ Correctness
The new test asserts extract_relations_llm() forwards max_tokens into llm.generate_typed(), but extract_relations_llm() currently builds call_kwargs without max_tokens before calling generate_typed. Once the test is made discoverable, it will fail unless production code is updated (or the assertion is changed).
Agent Prompt
## Issue description
`extract_relations_llm()` does not propagate `max_tokens` to `llm.generate_typed()`, unlike `extract_entities_llm()` / `extract_triplets_llm()`. The newly added test expects `max_tokens` to be present in the `generate_typed` call kwargs.
## Issue Context
In `extract_relations_llm()`, the code constructs a limited `call_kwargs` dict (temperature/verbose/max_retries) and calls `llm.generate_typed(..., **call_kwargs)`, which drops `max_tokens`.
## Fix Focus Areas
- semantica/semantic_extract/methods.py[1904-1916]
- tests/optimize reproduce_issue_176.py[33-49]
## Suggested fix
- Include `max_tokens` (and any other intended generation limit knobs) in `call_kwargs` when present in `kwargs`, e.g.:
- `if "max_tokens" in kwargs: call_kwargs["max_tokens"] = kwargs["max_tokens"]`
- Ensure the updated behavior is consistent with `extract_entities_llm()` / `extract_triplets_llm()` so the test can pass once properly collected.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| class TestMaxTokensPropagation(unittest.TestCase): | ||
| MAX_TOKENS = 128000 | ||
|
|
||
| def setUp(self): | ||
| self.mock_llm = MagicMock() | ||
| self.mock_llm.is_available.return_value = True | ||
|
|
There was a problem hiding this comment.
3. Duplicate issue-176 test script 🐞 Bug ⚙ Maintainability
The PR adds another issue-176 max_tokens propagation test script, but the repository already contains tests/reproduce_issue_176.py covering the same three methods. Keeping multiple near-duplicates makes it unclear which one is canonical and increases the chance of inconsistent future edits.
Agent Prompt
## Issue description
There are now two scripts testing the same max_tokens propagation scenario (`tests/reproduce_issue_176.py` and the newly added `tests/optimize reproduce_issue_176.py`). This duplication is confusing and makes it easy for one to drift.
## Issue Context
The new file appears to be a cleaner refactor of the existing reproduce script.
## Fix Focus Areas
- tests/optimize reproduce_issue_176.py[1-93]
- tests/reproduce_issue_176.py[1-100]
## Suggested fix
- Choose a single canonical test module (preferably pytest-discoverable, e.g. `tests/semantic_extract/test_max_tokens_propagation.py`).
- Move/rename the better version there.
- Delete the redundant reproduce script(s) or keep *one* reproduction script outside `tests/` if it’s meant for manual runs only.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
@saiganesh47 can you please handle qodo findings, so we can proceed for the review. |
This test verifies that the max_tokens parameter is correctly propagated to the generate_typed method for different extraction functions.
Description
Type of Change
Related Issues
Closes #
Fixes #
Changes Made
Testing
python -m build)Test Commands
Documentation
Breaking Changes
Breaking Changes: [Yes/No]
Checklist
Additional Notes