refactor: eliminate type: ignore and extract AI helpers#34
Merged
Conversation
…AI helpers - Add TYPE_CHECKING-gated `from src.main import IdealBot` to all 9 cogs; change `bot: commands.Bot` to `bot: "IdealBot"` to remove 54 attr-defined suppressions without a runtime circular import - Extract `_has_remote_llm()` method on IdealBot to remove duplicate bot_settings checks in setup_hook and _reload_generator_poller - Define `_PROVIDER_OPENAI/GEMINI/VLLM` constants in generator.py to replace bare string literals - Extract `_build_chat_messages()` and `_strip_generated_output()` helpers from the 130-line `generate_sentence`; define `_NEXT_TURN_MARKERS` and `_ASSISTANT_TURN_MARKERS` module constants - Add `Any` return type annotations to `_build_cpu_generator` and `_build_gpu_generator`
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
# type: ignore[attr-defined]across all 9 cogs by adding aTYPE_CHECKING-gatedfrom src.main import IdealBotimport and changingbot: commands.Bottobot: "IdealBot". Safe at runtime becausefrom __future__ import annotationsmakes annotations lazy, andTYPE_CHECKINGisFalseat runtime — no circular import._has_remote_llm()logic inmain.py: the identical two-linebot_settings_dbcheck appeared in bothsetup_hookand_reload_generator_poller; extracted as anasyncmethod.generator.py:_PROVIDER_OPENAI/GEMINI/VLLMreplace bare string literals in_resolve_llmand_generate_llm.generate_sentenceinlocal.py:_build_chat_messages(),_strip_generated_output(),_NEXT_TURN_MARKERS,_ASSISTANT_TURN_MARKERS; addAnyreturn type to_build_cpu_generator/_build_gpu_generator.Test plan
pytest tests/ -x -q)# type: ignorecomments remain insrc/