feat: Move LLM classifier algo#90
Conversation
From `libsy-examples` to `libsy`. Bring the three `examples/` binaries along. Signed-off-by: Graham King <grahamk@nvidia.com>
|
@coderabbitai full review |
✅ Action performedFull review finished. |
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (7)
💤 Files with no reviewable changes (1)
WalkthroughThe LLM classifier is moved into ChangesLLM API and examples
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/libsy/examples/research_agent.rs`:
- Line 18: Update the import example in crates/libsy/README.md to use
libsy::LlmClassifierOrchAlgo instead of
libsy_examples::llm_class::LlmClassifierOrchAlgo, matching the migrated API and
the import shown in research_agent.rs.
In `@crates/libsy/examples/streaming_agent.rs`:
- Around line 11-13: Update the example command in the streaming_agent module
documentation to use the libsy package name instead of libsy-examples, while
keeping the streaming_agent example target unchanged.
In `@crates/libsy/src/algorithms/llm_class.rs`:
- Line 23: Update CLASSIFIER_PROMPT_PREAMBLE or the create_run_task
concatenation so the classifier prompt always includes a separator before
user_prompt, preserving readable text such as “...[0, 1]. prove it”. Add an
assertion verifying the exact assembled prompt shape.
In `@crates/libsy/src/lib.rs`:
- Around line 64-65: Re-export ClassifierTier alongside ClassifierDecision and
LlmClassifierOrchAlgo in the public exports of the crate root. Keep the
algorithms module private while making the ClassifierDecision::tier field’s type
nameable by downstream crates.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 2cd64387-a977-4563-9c9b-44b8deee5ee3
📒 Files selected for processing (7)
crates/libsy-examples/src/lib.rscrates/libsy/examples/research_agent.rscrates/libsy/examples/research_agent_core.rscrates/libsy/examples/streaming_agent.rscrates/libsy/src/algorithms.rscrates/libsy/src/algorithms/llm_class.rscrates/libsy/src/lib.rs
💤 Files with no reviewable changes (1)
- crates/libsy-examples/src/lib.rs
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/libsy/examples/research_agent.rs`:
- Line 18: Update the import example in crates/libsy/README.md to use
libsy::LlmClassifierOrchAlgo instead of
libsy_examples::llm_class::LlmClassifierOrchAlgo, matching the migrated API and
the import shown in research_agent.rs.
In `@crates/libsy/examples/streaming_agent.rs`:
- Around line 11-13: Update the example command in the streaming_agent module
documentation to use the libsy package name instead of libsy-examples, while
keeping the streaming_agent example target unchanged.
In `@crates/libsy/src/algorithms/llm_class.rs`:
- Line 23: Update CLASSIFIER_PROMPT_PREAMBLE or the create_run_task
concatenation so the classifier prompt always includes a separator before
user_prompt, preserving readable text such as “...[0, 1]. prove it”. Add an
assertion verifying the exact assembled prompt shape.
In `@crates/libsy/src/lib.rs`:
- Around line 64-65: Re-export ClassifierTier alongside ClassifierDecision and
LlmClassifierOrchAlgo in the public exports of the crate root. Keep the
algorithms module private while making the ClassifierDecision::tier field’s type
nameable by downstream crates.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 2cd64387-a977-4563-9c9b-44b8deee5ee3
📒 Files selected for processing (7)
crates/libsy-examples/src/lib.rscrates/libsy/examples/research_agent.rscrates/libsy/examples/research_agent_core.rscrates/libsy/examples/streaming_agent.rscrates/libsy/src/algorithms.rscrates/libsy/src/algorithms/llm_class.rscrates/libsy/src/lib.rs
💤 Files with no reviewable changes (1)
- crates/libsy-examples/src/lib.rs
🛑 Comments failed to post (4)
crates/libsy/examples/research_agent.rs (1)
18-18: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Update the README import path in the same migration.
crates/libsy/README.mdstill documentslibsy_examples::llm_class::LlmClassifierOrchAlgo; after this API move, users following that example will get a broken import. Change it tolibsy::LlmClassifierOrchAlgo.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/libsy/examples/research_agent.rs` at line 18, Update the import example in crates/libsy/README.md to use libsy::LlmClassifierOrchAlgo instead of libsy_examples::llm_class::LlmClassifierOrchAlgo, matching the migrated API and the import shown in research_agent.rs.crates/libsy/examples/streaming_agent.rs (1)
11-13: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash set -eu sed -n '/^\[package\]/,/^\[/p' crates/libsy/Cargo.tomlRepository: NVIDIA-NeMo/Switchyard
Length of output: 393
🏁 Script executed:
#!/bin/bash set -eu echo "== crates/libsy/examples/streaming_agent.rs ==" sed -n '1,120p' crates/libsy/examples/streaming_agent.rs echo echo "== Algorithm::run references ==" rg -n "Algorithm::run|LlmResponse::Stream|aggregate|stream" crates/libsy -g '*.rs'Repository: NVIDIA-NeMo/Switchyard
Length of output: 23636
Use
libsyin the example command.
crates/libsy/Cargo.tomlnames the packagelibsy, socargo run -p libsy --example streaming_agentis the correct invocation.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/libsy/examples/streaming_agent.rs` around lines 11 - 13, Update the example command in the streaming_agent module documentation to use the libsy package name instead of libsy-examples, while keeping the streaming_agent example target unchanged.crates/libsy/src/algorithms/llm_class.rs (1)
23-23: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Preserve a separator before the user prompt.
create_run_taskconcatenates this constant directly withuser_prompt, so the classifier receives text such as...[0, 1].prove it. Add a trailing newline/space here or insert an explicit separator at the call site, and add an assertion covering the exact prompt shape.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/libsy/src/algorithms/llm_class.rs` at line 23, Update CLASSIFIER_PROMPT_PREAMBLE or the create_run_task concatenation so the classifier prompt always includes a separator before user_prompt, preserving readable text such as “...[0, 1]. prove it”. Add an assertion verifying the exact assembled prompt shape.crates/libsy/src/lib.rs (1)
64-65: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash set -eu rg -n 'ClassifierTier|ClassifierDecision|pub use algorithms::llm_class' crates/libsy/srcRepository: NVIDIA-NeMo/Switchyard
Length of output: 2091
🏁 Script executed:
#!/bin/bash set -eu echo "== lib.rs ==" sed -n '1,120p' crates/libsy/src/lib.rs echo echo "== llm_class.rs (type definitions) ==" sed -n '1,90p' crates/libsy/src/algorithms/llm_class.rs echo echo "== any re-exports of ClassifierTier in repo ==" rg -n 'ClassifierTier' crates/libsy/srcRepository: NVIDIA-NeMo/Switchyard
Length of output: 10912
🏁 Script executed:
python3 - <<'PY' from pathlib import Path src = r''' mod m { pub enum E { A } } pub struct S { pub x: Option<m::E>, } pub fn make() -> S { S { x: Some(m::E::A) } } ''' Path('/tmp/private_type_public_field.rs').write_text(src) import subprocess, sys p = subprocess.run(['rustc', '--crate-type=lib', '/tmp/private_type_public_field.rs', '-o', '/tmp/private_type_public_field.rlib'], capture_output=True, text=True) print('exit', p.returncode) print(p.stderr) PYRepository: NVIDIA-NeMo/Switchyard
Length of output: 715
Re-export
ClassifierTierwithClassifierDecision. Downstream crates can’t nameClassifierTierfrom the publicClassifierDecision::tierfield becausealgorithmsis private. Re-export the tier type, or maketierprivate and expose an accessor.Proposed fix
-pub use algorithms::llm_class::{ClassifierDecision, LlmClassifierOrchAlgo}; +pub use algorithms::llm_class::{ + ClassifierDecision, ClassifierTier, LlmClassifierOrchAlgo, +};📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.mod algorithms; pub use algorithms::llm_class::{ ClassifierDecision, ClassifierTier, LlmClassifierOrchAlgo, };🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/libsy/src/lib.rs` around lines 64 - 65, Re-export ClassifierTier alongside ClassifierDecision and LlmClassifierOrchAlgo in the public exports of the crate root. Keep the algorithms module private while making the ClassifierDecision::tier field’s type nameable by downstream crates.
|
@grahamking Does it work end to end with libsy example proxy ? |
I don't know. For the example proxy I'd need to merge this #79 and the PR it builds on, into here wouldn't I? The two |
Signed-off-by: Graham King <grahamk@nvidia.com>
It's hardcoded in the demo. Currently you have to change the code in #86 to use LlmClassifier instead of Random. |
From
libsy-examplestolibsy. Bring the threeexamples/binariesalong.
Signed-off-by: Graham King grahamk@nvidia.com
Summary by CodeRabbit
LlmClassifierOrchAlgoandClassifierDecisionAPIs for classifying requests and routing them to strong or weak models.