mirror of
https://github.com/codeflash-ai/codeflash-internal.git
synced 2026-05-04 18:25:18 +00:00
2.1 KiB
2.1 KiB
Scenario 1: Implement a Ruby Optimizer Handler
Context
The codeflash-internal monorepo currently supports Python and JavaScript/TypeScript optimization through the multi-language handler system. The team wants to add Ruby as a new supported language for the optimizer feature. The handler should integrate with the existing registry, dispatcher, and router systems.
The relevant existing code lives in:
django/aiservice/core/languages/(per-language handlers)django/aiservice/core/registry.py(LanguageRegistry, @register_handler)django/aiservice/core/dispatcher.py(get_handler_for_feature, Feature enum)django/aiservice/core/protocols/(OptimizerProtocol, LanguageHandler)django/aiservice/core/shared/optimizer_router.py(shared router that dispatches by language)
Task
-
Create a new Ruby optimizer handler at
django/aiservice/core/languages/ruby/optimizer/optimizer.pythat:- Registers itself using the
@register_handler("ruby")decorator - Sets
supports_optimizer = Trueand othersupports_*flags toFalse - Implements
OptimizerProtocolwith anoptimizer_optimize(request, data)async method - Uses
ninja.Schemafor any request/response models - Calls LLM through the proper abstraction layer
- Stores the optimization prompt as a
.mdfile alongside the module, rendered with Jinja2
- Registers itself using the
-
Add the Ruby language routing in
core/shared/optimizer_router.pyusing lazy imports with the# noqa: PLC0415suppression -
Import the Ruby handler module in
core/languages/__init__.pyso the decorator fires at startup -
Create a basic test file at
django/aiservice/tests/optimizer/test_ruby_optimizer.py
Expected Outputs
core/languages/ruby/__init__.pycore/languages/ruby/optimizer/__init__.pycore/languages/ruby/optimizer/optimizer.py— handler class with decorator, protocol, async methodcore/languages/ruby/optimizer/optimize_prompt.md— Jinja2 prompt template- Updated
core/shared/optimizer_router.py— lazy import dispatch for "ruby" - Updated
core/languages/__init__.py— import of ruby module tests/optimizer/test_ruby_optimizer.py— async test with @pytest.mark.asyncio