adaptive-memory-multi-model-router 2.14.49 → 2.14.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +82 -0
- package/.env.example +303 -0
- package/.github/DISCUSSIONS_WELCOME.md +27 -0
- package/.github/DISCUSSION_TEMPLATE.yml +5 -0
- package/.github/FUNDING.yml +2 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +94 -0
- package/.github/ISSUE_TEMPLATE/config.yml +17 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +71 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +71 -0
- package/.github/dependabot.yml +9 -0
- package/.github/workflows/ci.yml +263 -0
- package/.github/workflows/codeql.yml +38 -0
- package/.github/workflows/npm-publish.yml +20 -0
- package/.github/workflows/pages.yml +37 -0
- package/.github/workflows/stale.yml +54 -0
- package/.publish-tick +1 -0
- package/.well-known/ai-plugin.json +16 -0
- package/AGENT_COUNCIL_FINDINGS.md +142 -0
- package/ARCHITECTURE.md +346 -0
- package/AUDIT_REPORT.md +28 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +50 -0
- package/CONTRIBUTORS.md +20 -0
- package/Dockerfile +53 -0
- package/Dockerfile.proxy +33 -0
- package/HEALTH_REPORT.md +118 -0
- package/IMPROVEMENT_PLAN.md +107 -0
- package/LANDING.md +43 -0
- package/LAUNCH-PAIN-DRIVEN.md +339 -0
- package/LAUNCH.md +337 -0
- package/LAUNCH_CHECKLIST.md +141 -0
- package/LAUNCH_SNAPSHOT.md +260 -0
- package/MANIFESTO.md +41 -0
- package/POPULARITY_BOOSTERS.md +285 -0
- package/PR_STATUS_REPORT.md +148 -0
- package/README.md +25 -14
- package/REDESIGN.md +95 -0
- package/RUNKIT.md +83 -0
- package/SECURITY.md +29 -0
- package/SUBMISSIONS.md +43 -0
- package/_schema.html +53 -0
- package/ai-plugin.json +16 -0
- package/articles/AI_AGENT_LLM_ROUTING.md +150 -0
- package/articles/CHINESE_DIRECTORIES.md +100 -0
- package/articles/CHINESE_SUBMISSIONS_READY.md +322 -0
- package/articles/COMPETITOR_ALERTS.md +31 -0
- package/articles/COMPLETE_POSTING_DIRECTORY.md +147 -0
- package/articles/CONTENT_STRUCTURE.md +292 -0
- package/articles/DEVTO_COST_GUIDE.md +473 -0
- package/articles/DEVTO_FINAL.md +416 -0
- package/articles/DEVTO_MULTI_PROVIDER.md +542 -0
- package/articles/DEVTO_READY.md +255 -0
- package/articles/DEVTO_V2_ANNOUNCEMENT.md +160 -0
- package/articles/DEVTO_VIRAL_GROWTH.md +280 -0
- package/articles/FRESH_devto.md +460 -0
- package/articles/FRESH_devto_2026_05.md +73 -0
- package/articles/FRESH_hackernews.md +14 -0
- package/articles/FRESH_reddit_ml.md +90 -0
- package/articles/FRESH_reddit_node.md +198 -0
- package/articles/FRESH_reddit_sideproject.md +72 -0
- package/articles/FRESH_reddit_webdev.md +130 -0
- package/articles/FROM_ZERO_TO_10K.md +107 -0
- package/articles/HN_10X_BETTER.md +430 -0
- package/articles/HN_ACCOUNT_GUIDE.md +21 -0
- package/articles/HN_CHINESE_STYLE.md +308 -0
- package/articles/HN_FINAL.md +148 -0
- package/articles/HN_POSTED_VERSION.md +56 -0
- package/articles/HN_POST_READY.md +137 -0
- package/articles/HN_RESEARCH.md +364 -0
- package/articles/HN_SHOW_routerarena.md +17 -0
- package/articles/HN_TIMING_GUIDE.md +52 -0
- package/articles/INDIEHACKERS_POST.md +52 -0
- package/articles/INDIEHACKERS_READY.md +120 -0
- package/articles/LLM_BENCHMARK_DEEP_DIVE.md +153 -0
- package/articles/MASTER_POSTING_DIRECTORY.md +189 -0
- package/articles/NEWSLETTER_SEND_NOW.md +259 -0
- package/articles/NEWSLETTER_SUBMISSIONS.md +112 -0
- package/articles/PAIN-DRIVEN-devto-v2.md +308 -0
- package/articles/PAIN-DRIVEN-devto-v3.md +268 -0
- package/articles/PAIN-DRIVEN-devto.md +242 -0
- package/articles/PAIN-DRIVEN-hackernews-v2.md +138 -0
- package/articles/PAIN-DRIVEN-hackernews-v3.md +151 -0
- package/articles/PAIN-DRIVEN-hackernews.md +131 -0
- package/articles/PAIN-DRIVEN-reddit-v2.md +301 -0
- package/articles/PAIN-DRIVEN-reddit-v3.md +236 -0
- package/articles/PAIN-DRIVEN-reddit.md +218 -0
- package/articles/PAIN-DRIVEN-twitter-v2.md +110 -0
- package/articles/PAIN-DRIVEN-twitter-v3.md +121 -0
- package/articles/PAIN-DRIVEN-twitter.md +120 -0
- package/articles/PORTKEY_VS_A3M.md +147 -0
- package/articles/POSTING_KIT_2026_05.md +67 -0
- package/articles/PRESS_KIT_routerarena.md +77 -0
- package/articles/PRODUCTHUNT_LISTING.md +48 -0
- package/articles/PRODUCTHUNT_READY.md +106 -0
- package/articles/PR_PLAN_vault.md +125 -0
- package/articles/REDDIT_FINAL.md +232 -0
- package/articles/REDDIT_POST.md +67 -0
- package/articles/REDDIT_SUBMISSION_READY.md +348 -0
- package/articles/ROUTERARENA_9677.md +78 -0
- package/articles/ROUTERARENA_LEADER.md +45 -0
- package/articles/SHOW_HN_FINAL.md +29 -0
- package/articles/TWEETS_10K_DOWNLOADS.md +47 -0
- package/articles/TWEETS_BENCHMARK_FIRST.md +46 -0
- package/articles/TWEETS_MCP_PLAY.md +51 -0
- package/articles/TWEETS_SEQUENTIAL_BROKEN.md +49 -0
- package/articles/TWEETS_WHY_BUILD.md +54 -0
- package/articles/TWEETS_routerarena_leader.md +53 -0
- package/articles/TWEET_STORM_READY.md +165 -0
- package/articles/TWITTER_FINAL.md +167 -0
- package/articles/WHY_10X_BETTER.md +261 -0
- package/articles/WHY_CHINESE_STYLE_BETTER.md +323 -0
- package/articles/ai-discoverability-llm-routing.md +210 -0
- package/articles/devto-llm-routing.md +138 -0
- package/articles/hackernews-show-hn.md +54 -0
- package/articles/hashnode-llm-cost-optimization.md +125 -0
- package/articles/hn_show_2026_05.md +11 -0
- package/articles/medium-building-llm-router.md +205 -0
- package/articles/reddit-ml.md +76 -0
- package/articles/twitter-thread-cost-savings.md +50 -0
- package/articles/youtube-tutorial-script.md +262 -0
- package/assets/a3m_3blue1brown.mp4 +0 -0
- package/assets/banner.svg +109 -0
- package/assets/chart-cost-v2.svg +91 -0
- package/assets/chart-cost-v3.svg +143 -0
- package/assets/chart-features-v2.svg +132 -0
- package/assets/chart-features-v3.svg +211 -0
- package/assets/chart-growth-v2.svg +122 -0
- package/assets/chart-growth-v3.svg +189 -0
- package/assets/cost-comparison.svg +134 -0
- package/assets/cost-simple.svg +64 -0
- package/assets/demo-hn.gif +0 -0
- package/assets/feature-matrix.svg +136 -0
- package/assets/growth-chart-animated.svg +76 -0
- package/assets/growth-chart.svg +82 -0
- package/assets/growth-simple.svg +69 -0
- package/assets/hero-diagram.svg +81 -0
- package/assets/logo-new.svg +21 -0
- package/assets/logo.svg +68 -0
- package/assets/provider-comparison.svg +121 -0
- package/assets/social-preview-new.svg +100 -0
- package/assets/social-preview.svg +194 -0
- package/assets/social-v2.svg +130 -0
- package/assets/social-v3.svg +212 -0
- package/benchmark-provider-results.json +245 -0
- package/benchmark-results.json +54 -0
- package/council-votes/architecture-vote.md +121 -0
- package/council-votes/coverage-vote.md +93 -0
- package/data/adaptive-benchmark.json +92 -0
- package/data/benchmark-results.json +47 -0
- package/data/labeled-benchmark.json +88 -0
- package/demo/3blue1brown_video.py +285 -0
- package/demo/3blue1brown_video_v2.py +310 -0
- package/demo/IMPROVED_PROMPTS.md +229 -0
- package/demo/VEO3_PROMPTS.md +269 -0
- package/demo/VIDEO_PRODUCTION_GUIDE.md +333 -0
- package/demo/a3m_3blue1brown.mp4 +0 -0
- package/demo/asciinema-demo.sh +195 -0
- package/demo/demo-hn.tape +74 -0
- package/demo/demo-script.md +53 -0
- package/demo/demo-script.sh +62 -0
- package/demo/demo.svg +75 -0
- package/demo/frame1_ai_data_center.png +0 -0
- package/demo/frame1_sunset_video.mp4 +0 -0
- package/demo/frame2_cost_comparison.png +0 -0
- package/demo/frame2_cost_comparison_fallback.png +0 -0
- package/demo/frame3_parallel_execution.png +0 -0
- package/demo/frame3_parallel_execution_fallback.png +0 -0
- package/demo/frame4_providers.png +0 -0
- package/demo/frame4_providers_fallback.png +0 -0
- package/demo/frame5_endcard.png +0 -0
- package/demo/frame5_endcard_fallback.png +0 -0
- package/demo/new_frame1_hook.png +0 -0
- package/demo/new_frame2_proof.png +0 -0
- package/demo/new_frame3_wow.png +0 -0
- package/demo/new_frame4_social.png +0 -0
- package/demo/new_frame5_cta.png +0 -0
- package/demo/package.json +13 -0
- package/demo/product-video-final.mp4 +0 -0
- package/demo/product-video-hype-v1.mp4 +0 -0
- package/demo/product-video-v1.mp4 +0 -0
- package/demo/public/index.html +762 -0
- package/demo/recording.cast +55 -0
- package/demo/server.js +405 -0
- package/demo-new.tape +71 -0
- package/demo-real.sh +198 -0
- package/demo-simple.tape +205 -0
- package/demo.html +520 -0
- package/demo.sh +85 -0
- package/demo.tape +259 -0
- package/dist/analytics/costAnalytics.d.ts.map +1 -0
- package/dist/analytics/costAnalytics.js.map +1 -0
- package/dist/benchmark/comprehensive.js.map +1 -0
- package/dist/benchmark/reproducible.d.ts.map +1 -0
- package/dist/benchmark/reproducible.js.map +1 -0
- package/dist/cache/prefixCache.d.ts.map +1 -0
- package/dist/cache/prefixCache.js.map +1 -0
- package/dist/cache/responseCache.d.ts.map +1 -0
- package/dist/cache/responseCache.js.map +1 -0
- package/dist/cache/semanticCache.d.ts.map +1 -0
- package/dist/cache/semanticCache.js.map +1 -0
- package/dist/cli/setupWizard.d.ts.map +1 -0
- package/dist/cli/setupWizard.js.map +1 -0
- package/dist/cost/budgetEnforcer.d.ts.map +1 -0
- package/dist/cost/budgetEnforcer.js.map +1 -0
- package/dist/cost/costTracker.d.ts.map +1 -0
- package/dist/cost/costTracker.js.map +1 -0
- package/dist/ensemble/multiRoundDialog.js.map +1 -0
- package/dist/ensemble/shapleyValue.js.map +1 -0
- package/dist/integrations/langchainAdapter.d.ts.map +1 -0
- package/dist/integrations/langchainAdapter.js.map +1 -0
- package/dist/integrations/oauth.d.ts.map +1 -0
- package/dist/integrations/oauth.js.map +1 -0
- package/dist/integrations/scienceAdapter.js.map +1 -0
- package/dist/memory/autoFetch.d.ts.map +1 -0
- package/dist/memory/autoFetch.js.map +1 -0
- package/dist/memory/episodicMemory.d.ts.map +1 -0
- package/dist/memory/episodicMemory.js.map +1 -0
- package/dist/memory/hybridMemory.js.map +1 -0
- package/dist/memory/memoryTree.d.ts.map +1 -0
- package/dist/memory/memoryTree.js.map +1 -0
- package/dist/memory/obsidianVault.d.ts.map +1 -0
- package/dist/memory/obsidianVault.js.map +1 -0
- package/dist/memory/reasoningBank.js.map +1 -0
- package/dist/observability/changeWatch.d.ts.map +1 -0
- package/dist/observability/changeWatch.js.map +1 -0
- package/dist/observability/fatigueDetector.d.ts.map +1 -0
- package/dist/observability/fatigueDetector.js.map +1 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/observability/middleware.d.ts.map +1 -0
- package/dist/observability/middleware.js.map +1 -0
- package/dist/observability/tracer.d.ts.map +1 -0
- package/dist/observability/tracer.js.map +1 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/observability/types.js.map +1 -0
- package/dist/orchestration/haloOrchestrator.d.ts.map +1 -0
- package/dist/orchestration/haloOrchestrator.js.map +1 -0
- package/dist/orchestration/mctsWorkflow.d.ts.map +1 -0
- package/dist/orchestration/mctsWorkflow.js.map +1 -0
- package/dist/providers/localProvider.d.ts.map +1 -0
- package/dist/providers/localProvider.js.map +1 -0
- package/dist/providers/providerConfig.d.ts.map +1 -0
- package/dist/providers/providerConfig.js.map +1 -0
- package/dist/providers/registry.d.ts.map +1 -0
- package/dist/providers/registry.js.map +1 -0
- package/dist/routing/advancedRouter.d.ts.map +1 -0
- package/dist/routing/advancedRouter.js +1 -1
- package/dist/routing/advancedRouter.js.map +1 -0
- package/dist/routing/crossModelValidation.d.ts.map +1 -0
- package/dist/routing/crossModelValidation.js.map +1 -0
- package/dist/routing/providerHealth.d.ts.map +1 -0
- package/dist/routing/providerHealth.js.map +1 -0
- package/dist/routing/providerRetry.d.ts.map +1 -0
- package/dist/routing/providerRetry.js.map +1 -0
- package/dist/scripts/banner.js +29 -0
- package/dist/security/guardrails.d.ts.map +1 -0
- package/dist/security/guardrails.js.map +1 -0
- package/dist/server/dashboard.d.ts.map +1 -0
- package/dist/server/dashboard.js.map +1 -0
- package/dist/server/modelMapper.d.ts.map +1 -0
- package/dist/server/modelMapper.js.map +1 -0
- package/dist/server/proxyServer.d.ts.map +1 -0
- package/dist/server/proxyServer.js.map +1 -0
- package/dist/skills/__tests__/skill_manager.test.d.ts +2 -0
- package/dist/skills/__tests__/skill_manager.test.d.ts.map +1 -0
- package/dist/skills/__tests__/skill_manager.test.js +268 -0
- package/dist/skills/__tests__/skill_manager.test.js.map +1 -0
- package/dist/tools/tmlpdTools.d.ts.map +1 -0
- package/dist/tools/tmlpdTools.js.map +1 -0
- package/dist/tui/dashboard.d.ts.map +1 -0
- package/dist/tui/dashboard.js.map +1 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/index.js.map +1 -0
- package/dist/utils/batchProcessor.d.ts.map +1 -0
- package/dist/utils/batchProcessor.js.map +1 -0
- package/dist/utils/compression.d.ts.map +1 -0
- package/dist/utils/compression.js.map +1 -0
- package/dist/utils/costUtils.d.ts.map +1 -0
- package/dist/utils/costUtils.js.map +1 -0
- package/dist/utils/reliability.d.ts.map +1 -0
- package/dist/utils/reliability.js.map +1 -0
- package/dist/utils/sorting.d.ts.map +1 -0
- package/dist/utils/sorting.js.map +1 -0
- package/dist/utils/speculativeDecoding.d.ts.map +1 -0
- package/dist/utils/speculativeDecoding.js.map +1 -0
- package/dist/utils/tokenUtils.d.ts.map +1 -0
- package/dist/utils/tokenUtils.js.map +1 -0
- package/docs/.nojekyll +0 -0
- package/docs/ANALYSIS_PRINCIPLES.md +162 -0
- package/docs/API.md +855 -0
- package/docs/ARCHITECTURAL-IMPROVEMENTS-2025.md +1391 -0
- package/docs/ARCHITECTURAL-IMPROVEMENTS-REVISED-2025.md +1051 -0
- package/docs/BENCHMARK.md +170 -0
- package/docs/CHINESE_PROVIDER_RELIABILITY.md +37 -0
- package/docs/CITATIONS.md +74 -0
- package/docs/CLAIMS_AND_EVIDENCE.md +58 -0
- package/docs/CONFIGURATION.md +476 -0
- package/docs/COUNCIL_DECISION.json +816 -0
- package/docs/COUNCIL_SUMMARY.md +319 -0
- package/docs/COUNCIL_V2.2_DECISION.md +416 -0
- package/docs/ENGINEERING_SPEC.md +55 -0
- package/docs/FACTORY_RESET.md +34 -0
- package/docs/GEO.md +66 -0
- package/docs/GEO_OPTIMIZATION.md +30 -0
- package/docs/GEO_ROOT_CAUSE.md +136 -0
- package/docs/GEO_STATUS.md +85 -0
- package/docs/GEO_TEST_RESULTS.md +176 -0
- package/docs/HN_CHECKLIST.md +38 -0
- package/docs/HN_FOUNDER_COMMENT.md +17 -0
- package/docs/HN_SUBMISSION_FINAL.md +180 -0
- package/docs/HN_SUBMISSION_V3.md +56 -0
- package/docs/IMPROVEMENT_ROADMAP.md +515 -0
- package/docs/INTEGRATIONS.md +420 -0
- package/docs/LANGCHAIN_INTEGRATION.md +147 -0
- package/docs/LLM_COUNCIL_DECISION.md +508 -0
- package/docs/MIDDLEWARE_CHAIN.md +35 -0
- package/docs/PROMO_CHECKLIST.md +200 -0
- package/docs/QUICKSTART.md +271 -0
- package/docs/QUICK_START.md +43 -0
- package/docs/QUICK_START_VISIBILITY.md +782 -0
- package/docs/REDDIT_GAP_ANALYSIS.md +299 -0
- package/docs/RELEASE_CHECKLIST.md +32 -0
- package/docs/REPRODUCIBILITY.md +63 -0
- package/docs/RESEARCH_BACKED_IMPROVEMENTS.md +1180 -0
- package/docs/ROUTING_RUBRIC.md +197 -0
- package/docs/SEO_AUDIT.md +186 -0
- package/docs/SOCIAL_LISTENING.md +219 -0
- package/docs/TMLPD_QNA.md +751 -0
- package/docs/TMLPD_V2.1_COMPLETE.md +763 -0
- package/docs/TMLPD_V2.2_RESEARCH_ROADMAP.md +754 -0
- package/docs/UPDATE_TOPICS.md +15 -0
- package/docs/USE_CASES.md +59 -0
- package/docs/V2.2_IMPLEMENTATION_COMPLETE.md +446 -0
- package/docs/V2_IMPLEMENTATION_GUIDE.md +388 -0
- package/docs/VERCEL_AI_SDK.md +209 -0
- package/docs/VISIBILITY_ADOPTION_PLAN.md +1005 -0
- package/docs/_config.yml +49 -0
- package/docs/ai-plugin.json +16 -0
- package/docs/api.html +513 -0
- package/docs/architecture-diagram.md +40 -0
- package/docs/benchmark-chart.png +0 -0
- package/docs/benchmark.html +387 -0
- package/docs/blog/routerarena-9677.html +92 -0
- package/docs/blog/routerarena-number-one.html +73 -0
- package/docs/cli-cheatsheet.md +339 -0
- package/docs/compare.md +109 -0
- package/docs/comparison-litellm.md +88 -0
- package/docs/comparison.md +108 -0
- package/docs/cost-chart-ascii.md +42 -0
- package/docs/cost-comparison-chart.svg +88 -0
- package/docs/curl-examples.md +247 -0
- package/docs/demo-auto.html +264 -0
- package/docs/demo.html +416 -0
- package/docs/geo/GENERATIVE_ENGINE_OPTIMIZATION.md +232 -0
- package/docs/index.html +507 -0
- package/docs/launch-content/LAUNCH_EXECUTION_CHECKLIST.md +421 -0
- package/docs/launch-content/README.md +457 -0
- package/docs/launch-content/assets/cost_comparison_100_tasks.png +0 -0
- package/docs/launch-content/assets/cumulative_savings.png +0 -0
- package/docs/launch-content/assets/parallel_speedup.png +0 -0
- package/docs/launch-content/assets/provider_pricing_comparison.png +0 -0
- package/docs/launch-content/assets/task_breakdown_comparison.png +0 -0
- package/docs/launch-content/generate_charts.py +313 -0
- package/docs/launch-content/hn_show_post.md +139 -0
- package/docs/launch-content/partner_outreach_templates.md +745 -0
- package/docs/launch-content/reddit_posts.md +467 -0
- package/docs/launch-content/twitter_thread.txt +460 -0
- package/{llms.txt.bak → docs/llms.txt} +6 -6
- package/docs/npm-downloads-chart.svg +43 -0
- package/docs/openapi.json +139 -0
- package/docs/openapi.yaml +1318 -0
- package/docs/quick-start.html +366 -0
- package/docs/robots.txt +52 -0
- package/docs/sitemap.xml +57 -0
- package/docs/styles.css +682 -0
- package/docs/well-known/ai-plugin.json +16 -0
- package/docs/wellknown/ai-plugin.json +16 -0
- package/docs-site/assets/og-banner.svg +194 -0
- package/docs-site/index.html +632 -0
- package/eval/README.md +46 -0
- package/eval/baselines/main.json +12 -0
- package/eval/benchmark_dataset.jsonl +16 -0
- package/eval/check_golden_routes.js +64 -0
- package/eval/datasets/catalog.json +33 -0
- package/eval/datasets/slices/cn_provider_reliability_v1.jsonl +3 -0
- package/eval/datasets/slices/cost_pressure_v1.jsonl +3 -0
- package/eval/datasets/slices/safety_guardrails_v1.jsonl +3 -0
- package/eval/evals.json +199 -0
- package/eval/fault_injection_thresholds.json +3 -0
- package/eval/generate_report.js +128 -0
- package/eval/golden_routes.json +114 -0
- package/eval/lib/experiment_registry.js +24 -0
- package/eval/run_eval.js +197 -0
- package/eval/run_fault_injection.js +201 -0
- package/eval/run_shadow_eval.js +85 -0
- package/eval/thresholds.json +9 -0
- package/examples/QUICKSTART.md +183 -0
- package/examples/README.md +61 -0
- package/examples/a3m-sdk.js +124 -0
- package/examples/basic-route.js +54 -0
- package/examples/chat-loop.js +202 -0
- package/examples/classify-then-route.js +102 -0
- package/examples/cost-compare.js +120 -0
- package/examples/ensemble.js +160 -0
- package/examples/whatsapp-telegram-bridge-demo.js +302 -0
- package/examples/whatsapp-telegram-bridge.js +269 -0
- package/hf-space/README.md +23 -0
- package/hf-space/app.py +240 -0
- package/hf-space/requirements.txt +1 -0
- package/huggingface_space/README.md +35 -0
- package/huggingface_space/app.py +126 -0
- package/huggingface_space/create_space.py +208 -0
- package/huggingface_space/requirements.txt +1 -0
- package/index.html +1 -1
- package/mcp-server/README.md +188 -0
- package/mcp-server/package.json +29 -0
- package/mcp-server/src/index.ts +744 -0
- package/mcp-server/tsconfig.json +19 -0
- package/openclaw-alexa-bridge/ALL_REMAINING_FIXES_PLAN.md +313 -0
- package/openclaw-alexa-bridge/REMAINING_FIXES_SUMMARY.md +277 -0
- package/openclaw-alexa-bridge/src/alexa_handler_no_tmlpd.js +1234 -0
- package/openclaw-alexa-bridge/test_fixes.js +77 -0
- package/package.json +76 -272
- package/playground/README.md +51 -0
- package/playground/codesandbox.json +12 -0
- package/playground/index.js +39 -0
- package/proxy/README.md +227 -0
- package/proxy/package-lock.json +831 -0
- package/proxy/package.json +17 -0
- package/proxy/rate-limit.js +145 -0
- package/proxy/rate-limit.test.js +311 -0
- package/proxy/server.js +970 -0
- package/python/README.md +102 -0
- package/python/a3m/__init__.py +6 -0
- package/python/a3m/client.py +190 -0
- package/python/a3m/models.py +40 -0
- package/python/a3m/sync_client.py +61 -0
- package/python/examples.py +53 -0
- package/python/integrations.py +330 -0
- package/python/pyproject.toml +23 -0
- package/python/setup.py +28 -0
- package/python/tmlpd.py +369 -0
- package/qna/REDDIT_GAP_ANALYSIS.md +299 -0
- package/qna/TMLPD_QNA.md +751 -0
- package/research/FINDING_001_safety.md +28 -0
- package/research/FINDING_002_error_diversity.md +32 -0
- package/research/FINDING_003_confidence_weighted_voting.md +32 -0
- package/research/FINDING_004_cross_model_semantic_detection.md +37 -0
- package/research/FINDING_005_knowledge_gap_orthogonality.md +34 -0
- package/research/HALLUCINATION_RESEARCH.md +27 -0
- package/research/ensemble-voting.md +324 -0
- package/research/loss-functions.md +545 -0
- package/research-log.md +49 -0
- package/scripts/banner.js +29 -0
- package/scripts/benchmark-local-routerarena.ts +176 -0
- package/scripts/benchmark.js +145 -0
- package/scripts/benchmark.sh +61 -0
- package/scripts/compare-providers.sh +230 -0
- package/scripts/content-planner.js +25 -0
- package/scripts/create-labeled-benchmark.ts +105 -0
- package/scripts/cross_post.py +443 -0
- package/scripts/local-router-benchmark.ts +154 -0
- package/scripts/post-all.sh +41 -0
- package/scripts/publish_fcc.py +106 -0
- package/scripts/push-to-gitee.sh +25 -0
- package/scripts/routerarena_ensemble.js +144 -0
- package/scripts/routing-benchmark-v2.js +373 -0
- package/scripts/routing-benchmark-v3.js +118 -0
- package/scripts/routing-benchmark.js +462 -0
- package/scripts/run-labeled-benchmark.mjs +104 -0
- package/scripts/run-mmlu-benchmark.js +176 -0
- package/scripts/run-provider-benchmark.js +244 -0
- package/scripts/update-npm-badges.js +158 -0
- package/skill/SKILL.md +238 -0
- package/src/__tests__/integration/tmpld_integration.test.py +540 -0
- package/src/ensemble.ts +2 -0
- package/src/routing/advancedRouter.ts +1 -1
- package/src/skills/__tests__/skill_manager.test.ts +328 -0
- package/submissions/benchmarks/ALL_PLATFORMS_SUBMISSION.md +94 -0
- package/submissions/benchmarks/LLMROUTERBENCH_SUBMISSION.md +121 -0
- package/submissions/benchmarks/MMRBENCH_SUBMISSION.md +94 -0
- package/submissions/benchmarks/ROUTERARENA_UPDATE.md +83 -0
- package/submissions/benchmarks/ROUTERBENCH_SUBMISSION.md +225 -0
- package/test-council/1-structure-tests.test.js +353 -0
- package/test-council/1-structure-tests.test.ts +353 -0
- package/test-council/2-edge-case-tests.test.ts +361 -0
- package/test-council/3-performance-tests.test.ts +652 -0
- package/test-council/4-integration-tests.test.ts +391 -0
- package/test-council/5-agent-council-eval.test.ts +413 -0
- package/test-council/AGENT_COUNCIL_ARCHITECTURE.md +349 -0
- package/test-council/TEST_COUNCIL_REPORT.md +201 -0
- package/test-council/agents/edge-case-agent.ts +363 -0
- package/test-council/agents/performance-agent.ts +426 -0
- package/test-council/agents/structure-agent.ts +227 -0
- package/test-council/council.md +183 -0
- package/tests/__mocks__/tokenUtils.ts +8 -0
- package/tests/memory/episodicMemory.test.ts +227 -0
- package/tests/package-lock.json +1785 -0
- package/tests/package.json +19 -0
- package/tests/routing/ensembleVoting.test.ts +236 -0
- package/tests/routing/providerRetry.test.ts +360 -0
- package/tests/routing/queryTypePresets.test.ts +208 -0
- package/tests/security/guardrailEngine.test.ts +700 -0
- package/tests/tsconfig.json +21 -0
- package/tests/vitest.config.ts +18 -0
- package/tmlpd-pi-extension/README.md +66 -0
- package/tmlpd-pi-extension/dist/cache/prefixCache.d.ts +114 -0
- package/tmlpd-pi-extension/dist/cache/prefixCache.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/cache/prefixCache.js +285 -0
- package/tmlpd-pi-extension/dist/cache/prefixCache.js.map +1 -0
- package/tmlpd-pi-extension/dist/cache/responseCache.d.ts +58 -0
- package/tmlpd-pi-extension/dist/cache/responseCache.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/cache/responseCache.js +153 -0
- package/tmlpd-pi-extension/dist/cache/responseCache.js.map +1 -0
- package/tmlpd-pi-extension/dist/cli.js +59 -0
- package/tmlpd-pi-extension/dist/cost/costTracker.d.ts +95 -0
- package/tmlpd-pi-extension/dist/cost/costTracker.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/cost/costTracker.js +240 -0
- package/tmlpd-pi-extension/dist/cost/costTracker.js.map +1 -0
- package/tmlpd-pi-extension/dist/index.d.ts +723 -0
- package/tmlpd-pi-extension/dist/index.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/index.js +239 -0
- package/tmlpd-pi-extension/dist/index.js.map +1 -0
- package/tmlpd-pi-extension/dist/memory/episodicMemory.d.ts +82 -0
- package/tmlpd-pi-extension/dist/memory/episodicMemory.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/memory/episodicMemory.js +145 -0
- package/tmlpd-pi-extension/dist/memory/episodicMemory.js.map +1 -0
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.d.ts +102 -0
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.js +207 -0
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.js.map +1 -0
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.d.ts +85 -0
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.js +210 -0
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.js.map +1 -0
- package/tmlpd-pi-extension/dist/providers/localProvider.d.ts +102 -0
- package/tmlpd-pi-extension/dist/providers/localProvider.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/providers/localProvider.js +338 -0
- package/tmlpd-pi-extension/dist/providers/localProvider.js.map +1 -0
- package/tmlpd-pi-extension/dist/providers/registry.d.ts +55 -0
- package/tmlpd-pi-extension/dist/providers/registry.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/providers/registry.js +138 -0
- package/tmlpd-pi-extension/dist/providers/registry.js.map +1 -0
- package/tmlpd-pi-extension/dist/routing/advancedRouter.d.ts +68 -0
- package/tmlpd-pi-extension/dist/routing/advancedRouter.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/routing/advancedRouter.js +332 -0
- package/tmlpd-pi-extension/dist/routing/advancedRouter.js.map +1 -0
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.d.ts +101 -0
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.js +368 -0
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/batchProcessor.d.ts +96 -0
- package/tmlpd-pi-extension/dist/utils/batchProcessor.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/batchProcessor.js +170 -0
- package/tmlpd-pi-extension/dist/utils/batchProcessor.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/compression.d.ts +61 -0
- package/tmlpd-pi-extension/dist/utils/compression.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/compression.js +281 -0
- package/tmlpd-pi-extension/dist/utils/compression.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/reliability.d.ts +74 -0
- package/tmlpd-pi-extension/dist/utils/reliability.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/reliability.js +177 -0
- package/tmlpd-pi-extension/dist/utils/reliability.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.d.ts +117 -0
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.js +246 -0
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/tokenUtils.d.ts +50 -0
- package/tmlpd-pi-extension/dist/utils/tokenUtils.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/tokenUtils.js +124 -0
- package/tmlpd-pi-extension/dist/utils/tokenUtils.js.map +1 -0
- package/tmlpd-pi-extension/examples/QUICKSTART.md +183 -0
- package/tmlpd-pi-extension/package-lock.json +79 -0
- package/tmlpd-pi-extension/package.json +172 -0
- package/tmlpd-pi-extension/python/examples.py +53 -0
- package/tmlpd-pi-extension/python/integrations.py +330 -0
- package/tmlpd-pi-extension/python/setup.py +28 -0
- package/tmlpd-pi-extension/python/tmlpd.py +369 -0
- package/tmlpd-pi-extension/qna/REDDIT_GAP_ANALYSIS.md +299 -0
- package/tmlpd-pi-extension/qna/TMLPD_QNA.md +751 -0
- package/tmlpd-pi-extension/skill/SKILL.md +238 -0
- package/tmlpd-pi-extension/src/cache/responseCache.ts +147 -0
- package/tmlpd-pi-extension/src/cost/costTracker.ts +302 -0
- package/tmlpd-pi-extension/src/index.ts +232 -0
- package/tmlpd-pi-extension/src/memory/episodicMemory.ts +257 -0
- package/tmlpd-pi-extension/src/orchestration/haloOrchestrator.ts +266 -0
- package/tmlpd-pi-extension/src/orchestration/mctsWorkflow.ts +262 -0
- package/tmlpd-pi-extension/src/providers/localProvider.ts +406 -0
- package/tmlpd-pi-extension/src/providers/registry.ts +164 -0
- package/tmlpd-pi-extension/src/routing/ensembleVoting.ts +159 -0
- package/tmlpd-pi-extension/src/routing/queryTypePresets.ts +136 -0
- package/tmlpd-pi-extension/src/tools/tmlpdTools.ts +433 -0
- package/tmlpd-pi-extension/src/utils/batchProcessor.ts +232 -0
- package/tmlpd-pi-extension/src/utils/compression.ts +325 -0
- package/tmlpd-pi-extension/src/utils/reliability.ts +221 -0
- package/tmlpd-pi-extension/src/utils/tokenUtils.ts +145 -0
- package/tmlpd-pi-extension/tsconfig.json +18 -0
- package/tsconfig.build.json +29 -0
- package/tsconfig.json +18 -0
- package/README.md.bak +0 -1185
- package/src/routing/advancedRouter.ts.bak +0 -650
- package/test.js.bak +0 -376
- /package/{llms-full.txt.bak → docs/llms-full.txt} +0 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# A3M Router Usage Examples
|
|
2
|
+
|
|
3
|
+
Practical examples showing how to use the **Adaptive Memory Multi-Model Router** in real-world scenarios.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install adaptive-memory-multi-model-router
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Set at least one API key in your environment:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
export OPENAI_API_KEY=sk-...
|
|
15
|
+
export GROQ_API_KEY=gsk_...
|
|
16
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
17
|
+
export GEMINI_API_KEY=...
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Examples
|
|
21
|
+
|
|
22
|
+
| # | File | Description |
|
|
23
|
+
|----|--------------------------|-----------------------------------------------------------------------------|
|
|
24
|
+
| 1 | `basic-route.js` | Route a query to the best provider. Shows the routing decision with model, cost, confidence, and reasoning. |
|
|
25
|
+
| 2 | `ensemble.js` | Query multiple providers in parallel and merge results. A3M's signature capability. |
|
|
26
|
+
| 3 | `classify-then-route.js` | Classify a query's domain first (code, math, creative, etc.), then route to the optimal provider for that domain. |
|
|
27
|
+
| 4 | `chat-loop.js` | Interactive terminal chat loop with auto-routing, cost tracking, and guardrails. |
|
|
28
|
+
| 5 | `cost-compare.js` | Compare estimated costs across providers for the same prompt. Find the cheapest and fastest routes. |
|
|
29
|
+
| 6 | `a3m-sdk.js` | Use the TypeScript SDK class — `route()`, `analyze()`, `recommend()`, batch routing, and the proxy server. |
|
|
30
|
+
|
|
31
|
+
## Running Examples
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Route a query (dry-run — no API call)
|
|
35
|
+
node examples/basic-route.js
|
|
36
|
+
|
|
37
|
+
# Ensemble across multiple providers
|
|
38
|
+
node examples/ensemble.js
|
|
39
|
+
|
|
40
|
+
# Classify then route
|
|
41
|
+
node examples/classify-then-route.js
|
|
42
|
+
|
|
43
|
+
# Interactive chat loop
|
|
44
|
+
node examples/chat-loop.js
|
|
45
|
+
|
|
46
|
+
# Cost comparison
|
|
47
|
+
node examples/cost-compare.js
|
|
48
|
+
|
|
49
|
+
# SDK showcase
|
|
50
|
+
node examples/a3m-sdk.js
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## What Makes A3M Unique
|
|
54
|
+
|
|
55
|
+
- **Parallel ensemble voting** — query multiple LLMs and compare results (no other router does this)
|
|
56
|
+
- **RouteLLM-style routing** — learned cost-quality tradeoff based on arXiv:2404.06035
|
|
57
|
+
- **47+ providers** — free, cheap, mid, premium, enterprise tiers
|
|
58
|
+
- **Semantic cache** — returns cached responses for semantically similar queries
|
|
59
|
+
- **Budget enforcement** — hard caps per API key with monthly reset
|
|
60
|
+
- **Guardrails** — prompt injection detection, PII redaction, content filtering
|
|
61
|
+
- **LangChain adapter** — drop-in replacement for ChatOpenAI
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* a3m-sdk.js — TypeScript SDK class showcase.
|
|
4
|
+
*
|
|
5
|
+
* The A3MRouter class provides a clean API: route() for model selection,
|
|
6
|
+
* analyze() for query features, recommend() for task-based suggestions,
|
|
7
|
+
* serve() for the OpenAI-compatible proxy server, and routeBatch().
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* node examples/a3m-sdk.js
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const { A3MRouter, createSDK } = require('../dist/sdk.js');
|
|
14
|
+
|
|
15
|
+
function main() {
|
|
16
|
+
console.log('A3M Router — SDK Class Showcase');
|
|
17
|
+
console.log('=' .repeat(50));
|
|
18
|
+
console.log('');
|
|
19
|
+
|
|
20
|
+
// Create SDK instance
|
|
21
|
+
const router = createSDK({
|
|
22
|
+
defaultModel: 'auto',
|
|
23
|
+
maxCostPerQuery: 0.01,
|
|
24
|
+
preferSpeedOverQuality: false,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// 1. route() — get model selection for a query
|
|
28
|
+
console.log('-- route() — Model Selection --');
|
|
29
|
+
const result = router.route('Explain quantum entanglement simply');
|
|
30
|
+
console.log(' Query: Explain quantum entanglement simply');
|
|
31
|
+
console.log(' Model: ', result.model);
|
|
32
|
+
console.log(' Tier: ', result.tier);
|
|
33
|
+
console.log(' Cost: $', result.cost.toFixed(6));
|
|
34
|
+
console.log(' Complexity:', result.complexity.toFixed(2));
|
|
35
|
+
console.log(' Reasoning: ', result.reasoning);
|
|
36
|
+
console.log(' Free: ', result.isFree);
|
|
37
|
+
console.log(' Expert: ', result.isExpert);
|
|
38
|
+
console.log(' Fallbacks: ', result.fallbackModels.join(', '));
|
|
39
|
+
console.log('');
|
|
40
|
+
|
|
41
|
+
// 2. analyze() — extract query features
|
|
42
|
+
console.log('-- analyze() — Query Features --');
|
|
43
|
+
const features = router.analyze('Write a Python script to merge two sorted arrays');
|
|
44
|
+
console.log(' Query: Write a Python script to merge two sorted arrays');
|
|
45
|
+
console.log(' Complexity: ', features.complexity.toFixed(2));
|
|
46
|
+
console.log(' Has code: ', features.has_code);
|
|
47
|
+
console.log(' Has math: ', features.has_math);
|
|
48
|
+
console.log(' Multilingual: ', features.is_multilingual);
|
|
49
|
+
console.log(' Creative: ', features.is_creative);
|
|
50
|
+
console.log(' Reasoning: ', features.requires_reasoning);
|
|
51
|
+
console.log(' Detected domain: ', features.detected_domain);
|
|
52
|
+
console.log(' Domain score: ', features.domain_score.toFixed(2));
|
|
53
|
+
console.log('');
|
|
54
|
+
|
|
55
|
+
// 3. recommend() — model recommendation for a task
|
|
56
|
+
console.log('-- recommend() — Task-Based Recommendations --');
|
|
57
|
+
const tasks = [
|
|
58
|
+
'code generation',
|
|
59
|
+
'summarization',
|
|
60
|
+
'creative writing',
|
|
61
|
+
'data analysis',
|
|
62
|
+
'translation',
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
for (const task of tasks) {
|
|
66
|
+
const rec = router.recommend(task);
|
|
67
|
+
console.log(` ${task.padEnd(20)} -> ${rec.model.padEnd(36)} tier=${rec.tier} cost=$${rec.cost.toFixed(6)}`);
|
|
68
|
+
}
|
|
69
|
+
console.log('');
|
|
70
|
+
|
|
71
|
+
// 4. routeBatch() — multiple queries at once
|
|
72
|
+
console.log('-- routeBatch() — Batch Routing --');
|
|
73
|
+
const queries = [
|
|
74
|
+
'What is 2+2?',
|
|
75
|
+
'Explain the water cycle',
|
|
76
|
+
'Write a SQL query to find duplicate emails',
|
|
77
|
+
'Translate "Hello" to French',
|
|
78
|
+
'Summarize the theory of relativity',
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
const batchResults = router.routeBatch(queries);
|
|
82
|
+
for (let i = 0; i < queries.length; i++) {
|
|
83
|
+
console.log(` [${i + 1}] ${queries[i].substring(0, 40).padEnd(42)} -> ${batchResults[i].model.substring(0, 36).padEnd(38)} tier=${batchResults[i].tier.padEnd(7)} comp=${batchResults[i].complexity.toFixed(2)}`);
|
|
84
|
+
}
|
|
85
|
+
console.log('');
|
|
86
|
+
|
|
87
|
+
// 5. Different complexity classes
|
|
88
|
+
console.log('-- Complexity Classification --');
|
|
89
|
+
const testQueries = [
|
|
90
|
+
['Simple', 'Hello, how are you?'],
|
|
91
|
+
['Moderate', 'Explain what a database is'],
|
|
92
|
+
['Complex', 'Compare gradient descent vs stochastic gradient descent'],
|
|
93
|
+
['Expert', 'Prove the Riemann-Roch theorem and explain its implications'],
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
for (const [label, q] of testQueries) {
|
|
97
|
+
const r = router.route(q);
|
|
98
|
+
console.log(` ${label.padEnd(10)} comp=${r.complexity.toFixed(2)} tier=${r.tier.padEnd(7)} model=${r.model}`);
|
|
99
|
+
}
|
|
100
|
+
console.log('');
|
|
101
|
+
|
|
102
|
+
// 6. Proxy server (dry-run — uncomment to start)
|
|
103
|
+
console.log('-- serve() — Proxy Server --');
|
|
104
|
+
console.log(' To start the OpenAI-compatible proxy server, uncomment:');
|
|
105
|
+
console.log(' const url = await router.serve(8787);');
|
|
106
|
+
console.log(' // Use any OpenAI SDK with baseURL = url');
|
|
107
|
+
console.log(' const client = new OpenAI({ baseURL: url });');
|
|
108
|
+
console.log(' const response = await client.chat.completions.create({');
|
|
109
|
+
console.log(' model: "auto",');
|
|
110
|
+
console.log(' messages: [{ role: "user", content: "Hello" }]');
|
|
111
|
+
console.log(' });');
|
|
112
|
+
console.log('');
|
|
113
|
+
|
|
114
|
+
// 7. Config options
|
|
115
|
+
console.log('-- SDK Configuration --');
|
|
116
|
+
const cheapRouter = createSDK({ preferSpeedOverQuality: true, maxCostPerQuery: 0.001 });
|
|
117
|
+
const r1 = cheapRouter.route('What is the meaning of life?');
|
|
118
|
+
console.log(' Speed-preferring config (maxCost=$0.001):');
|
|
119
|
+
console.log(' Model: ', r1.model);
|
|
120
|
+
console.log(' Cost: $', r1.cost.toFixed(6));
|
|
121
|
+
console.log(' Tier: ', r1.tier);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
main();
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* basic-route.js — Route a query to the best provider.
|
|
4
|
+
*
|
|
5
|
+
* A3M Router analyzes the query and returns a RouteDecision:
|
|
6
|
+
* which model to use, estimated cost, confidence, and reasoning.
|
|
7
|
+
* This is a dry-run — no API call is made.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* node examples/basic-route.js
|
|
11
|
+
* QUERY="Explain quantum computing" node examples/basic-route.js
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const { routeQuery, extractQueryFeatures } = require('../dist/index.js');
|
|
15
|
+
|
|
16
|
+
const query = process.env.QUERY || 'Explain machine learning simply in 3 sentences';
|
|
17
|
+
|
|
18
|
+
function main() {
|
|
19
|
+
console.log('Query:', query);
|
|
20
|
+
console.log('');
|
|
21
|
+
|
|
22
|
+
// 1. Extract query features for insight
|
|
23
|
+
const features = extractQueryFeatures(query);
|
|
24
|
+
console.log('-- Query Features --');
|
|
25
|
+
console.log(' Complexity: ', features.complexity.toFixed(2));
|
|
26
|
+
console.log(' Has code: ', features.has_code);
|
|
27
|
+
console.log(' Has math: ', features.has_math);
|
|
28
|
+
console.log(' Requires reason: ', features.requires_reasoning);
|
|
29
|
+
console.log(' Is creative: ', features.is_creative);
|
|
30
|
+
console.log('');
|
|
31
|
+
|
|
32
|
+
// 2. Route the query (no API call — pure routing decision)
|
|
33
|
+
const decision = routeQuery(query);
|
|
34
|
+
|
|
35
|
+
console.log('-- Route Decision --');
|
|
36
|
+
console.log(' Model: ', decision.primary_model);
|
|
37
|
+
console.log(' Fallback models: ', decision.fallback_models.join(', '));
|
|
38
|
+
console.log(' Confidence: ', (decision.confidence * 100).toFixed(1) + '%');
|
|
39
|
+
console.log(' Est. cost: ', '$' + decision.estimated_cost.toFixed(6));
|
|
40
|
+
console.log(' Est. latency: ', decision.estimated_latency_ms + 'ms');
|
|
41
|
+
console.log(' Reasoning: ', decision.reasoning);
|
|
42
|
+
console.log('');
|
|
43
|
+
|
|
44
|
+
// 3. Route with a budget multiplier (1.0 = balanced, <1 = cost-focused, >1 = quality-focused)
|
|
45
|
+
const cheap = routeQuery(query, undefined, 0.3);
|
|
46
|
+
const premium = routeQuery(query, undefined, 2.0);
|
|
47
|
+
|
|
48
|
+
console.log('-- Budget Tuning --');
|
|
49
|
+
console.log(' Cost-focused (0.3): ', cheap.primary_model, '($' + cheap.estimated_cost.toFixed(6) + ')');
|
|
50
|
+
console.log(' Balanced (1.0): ', decision.primary_model, '($' + decision.estimated_cost.toFixed(6) + ')');
|
|
51
|
+
console.log(' Quality (2.0): ', premium.primary_model, '($' + premium.estimated_cost.toFixed(6) + ')');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
main();
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* chat-loop.js — Interactive terminal chat loop with auto-routing,
|
|
4
|
+
* cost tracking, and guardrails.
|
|
5
|
+
*
|
|
6
|
+
* A full-featured REPL that routes each message through A3M,
|
|
7
|
+
* tracks cumulative cost, and checks input/output safety.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* node examples/chat-loop.js
|
|
11
|
+
*
|
|
12
|
+
* Commands in chat:
|
|
13
|
+
* /cost — Show current session cost
|
|
14
|
+
* /route — Show the route decision for the last query
|
|
15
|
+
* /providers — List available providers
|
|
16
|
+
* /clear — Reset conversation and cost
|
|
17
|
+
* /help — Show commands
|
|
18
|
+
* /quit — Exit
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const readline = require('readline');
|
|
22
|
+
const {
|
|
23
|
+
routeQuery,
|
|
24
|
+
extractQueryFeatures,
|
|
25
|
+
CostTracker,
|
|
26
|
+
GuardrailEngine,
|
|
27
|
+
getAvailableProviders,
|
|
28
|
+
findCheapestAvailableProvider,
|
|
29
|
+
findFastestAvailableProvider,
|
|
30
|
+
} = require('../dist/index.js');
|
|
31
|
+
|
|
32
|
+
class ChatLoop {
|
|
33
|
+
constructor() {
|
|
34
|
+
this.costTracker = new CostTracker({ daily_limit: 1.0 }); // $1/day soft limit
|
|
35
|
+
this.guardrails = new GuardrailEngine({
|
|
36
|
+
promptInjection: true,
|
|
37
|
+
piiDetection: true,
|
|
38
|
+
contentFilter: true,
|
|
39
|
+
maxLength: 4000,
|
|
40
|
+
languageDetection: false,
|
|
41
|
+
outputFilter: false,
|
|
42
|
+
outputPII: false,
|
|
43
|
+
hallucinationCheck: false,
|
|
44
|
+
});
|
|
45
|
+
this.history = [];
|
|
46
|
+
this.lastDecision = null;
|
|
47
|
+
this.rl = readline.createInterface({
|
|
48
|
+
input: process.stdin,
|
|
49
|
+
output: process.stdout,
|
|
50
|
+
prompt: '\x1b[36mA3M> \x1b[0m',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
start() {
|
|
55
|
+
console.log('');
|
|
56
|
+
console.log(' A3M Router — Interactive Chat');
|
|
57
|
+
console.log(' ' + '-'.repeat(36));
|
|
58
|
+
console.log(' Type a message to route it through A3M.');
|
|
59
|
+
console.log(' Type /help for commands.');
|
|
60
|
+
console.log('');
|
|
61
|
+
|
|
62
|
+
this.rl.prompt();
|
|
63
|
+
|
|
64
|
+
this.rl.on('line', async (line) => {
|
|
65
|
+
const input = line.trim();
|
|
66
|
+
if (!input) { this.rl.prompt(); return; }
|
|
67
|
+
|
|
68
|
+
if (input.startsWith('/')) {
|
|
69
|
+
await this.handleCommand(input);
|
|
70
|
+
} else {
|
|
71
|
+
await this.handleMessage(input);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.rl.prompt();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
this.rl.on('close', () => {
|
|
78
|
+
console.log('\nGoodbye!');
|
|
79
|
+
this.printCostSummary();
|
|
80
|
+
process.exit(0);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async handleCommand(cmd) {
|
|
85
|
+
switch (cmd) {
|
|
86
|
+
case '/cost':
|
|
87
|
+
this.printCostSummary();
|
|
88
|
+
break;
|
|
89
|
+
|
|
90
|
+
case '/route':
|
|
91
|
+
if (this.lastDecision) {
|
|
92
|
+
console.log(' Last route decision:');
|
|
93
|
+
console.log(' Model: ', this.lastDecision.primary_model);
|
|
94
|
+
console.log(' Confidence: ', (this.lastDecision.confidence * 100).toFixed(1) + '%');
|
|
95
|
+
console.log(' Cost: $', this.lastDecision.estimated_cost.toFixed(6));
|
|
96
|
+
console.log(' Reasoning: ', this.lastDecision.reasoning);
|
|
97
|
+
} else {
|
|
98
|
+
console.log(' No messages routed yet.');
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
|
|
102
|
+
case '/providers':
|
|
103
|
+
const providers = getAvailableProviders();
|
|
104
|
+
const entries = Object.entries(providers);
|
|
105
|
+
console.log(' Available providers (' + entries.length + '):');
|
|
106
|
+
for (const [id, p] of entries.slice(0, 10)) {
|
|
107
|
+
const cheap = findCheapestAvailableProvider(id);
|
|
108
|
+
const fast = findFastestAvailableProvider();
|
|
109
|
+
console.log(` ${id.padEnd(16)} tier=${p.tier.padEnd(10)} models=${p.models.length}`);
|
|
110
|
+
}
|
|
111
|
+
if (entries.length > 10) {
|
|
112
|
+
console.log(` ... and ${entries.length - 10} more`);
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
|
|
116
|
+
case '/clear':
|
|
117
|
+
this.history = [];
|
|
118
|
+
this.costTracker.reset();
|
|
119
|
+
this.lastDecision = null;
|
|
120
|
+
console.log(' Session cleared.');
|
|
121
|
+
break;
|
|
122
|
+
|
|
123
|
+
case '/help':
|
|
124
|
+
console.log(' Commands:');
|
|
125
|
+
console.log(' /cost — Show session cost');
|
|
126
|
+
console.log(' /route — Show last route decision');
|
|
127
|
+
console.log(' /providers — List available providers');
|
|
128
|
+
console.log(' /clear — Reset conversation');
|
|
129
|
+
console.log(' /help — This message');
|
|
130
|
+
console.log(' /quit — Exit');
|
|
131
|
+
break;
|
|
132
|
+
|
|
133
|
+
case '/quit':
|
|
134
|
+
this.rl.close();
|
|
135
|
+
break;
|
|
136
|
+
|
|
137
|
+
default:
|
|
138
|
+
console.log(' Unknown command. Type /help.');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async handleMessage(text) {
|
|
143
|
+
// 1. Guardrails — check input safety
|
|
144
|
+
const inputCheck = await this.guardrails.checkInput(text);
|
|
145
|
+
if (inputCheck.blocked) {
|
|
146
|
+
console.log(` \x1b[31m[BLOCKED]\x1b[0m ${inputCheck.reason || 'Input rejected by guardrails'}`);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const safeText = inputCheck.modified || text;
|
|
151
|
+
|
|
152
|
+
// 2. Extract features
|
|
153
|
+
const features = extractQueryFeatures(safeText);
|
|
154
|
+
const complexityLabel = features.complexity < 0.2 ? 'simple' :
|
|
155
|
+
features.complexity < 0.45 ? 'moderate' :
|
|
156
|
+
features.complexity < 0.65 ? 'complex' : 'expert';
|
|
157
|
+
|
|
158
|
+
// 3. Route the query
|
|
159
|
+
this.lastDecision = routeQuery(safeText);
|
|
160
|
+
|
|
161
|
+
console.log(` [${complexityLabel}] -> ${this.lastDecision.primary_model} (${(this.lastDecision.confidence * 100).toFixed(0)}% conf, $${this.lastDecision.estimated_cost.toFixed(6)})`);
|
|
162
|
+
|
|
163
|
+
// 4. Record cost
|
|
164
|
+
this.costTracker.record(
|
|
165
|
+
this.lastDecision.primary_model.split('/')[0] || 'unknown',
|
|
166
|
+
this.lastDecision.primary_model,
|
|
167
|
+
Math.ceil(safeText.length / 4),
|
|
168
|
+
100 // estimated output tokens
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// 5. Track history
|
|
172
|
+
this.history.push({ role: 'user', content: safeText });
|
|
173
|
+
|
|
174
|
+
// 6. Check budget
|
|
175
|
+
const summary = this.costTracker.getSummary();
|
|
176
|
+
const remaining = this.costTracker.getRemainingBudget();
|
|
177
|
+
if (remaining.daily !== null && remaining.daily < 0.05) {
|
|
178
|
+
console.log(` \x1b[33m[WARN]\x1b[0m Daily budget nearly exhausted: $${remaining.daily.toFixed(4)} remaining`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
printCostSummary() {
|
|
183
|
+
const summary = this.costTracker.getSummary();
|
|
184
|
+
const remaining = this.costTracker.getRemainingBudget();
|
|
185
|
+
console.log(' -- Cost Summary --');
|
|
186
|
+
console.log(' Total spent: $' + summary.total_cost.toFixed(6));
|
|
187
|
+
console.log(' Requests: ', summary.request_count);
|
|
188
|
+
console.log(' Avg/request: $' + summary.average_cost_per_request.toFixed(6));
|
|
189
|
+
console.log(' Daily remaining: $' + (remaining.daily !== null ? remaining.daily.toFixed(6) : 'unlimited'));
|
|
190
|
+
console.log(' Monthly remain: $' + (remaining.monthly !== null ? remaining.monthly.toFixed(6) : 'unlimited'));
|
|
191
|
+
if (Object.keys(summary.by_provider).length > 0) {
|
|
192
|
+
console.log(' By provider:');
|
|
193
|
+
for (const [prov, cost] of Object.entries(summary.by_provider)) {
|
|
194
|
+
console.log(` ${prov}: $${cost.toFixed(6)}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Start the chat loop
|
|
201
|
+
const chat = new ChatLoop();
|
|
202
|
+
chat.start();
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* classify-then-route.js — Classify a query's domain first, then route to optimal provider.
|
|
4
|
+
*
|
|
5
|
+
* A3M Router's extractQueryFeatures() analyzes the query for code, math,
|
|
6
|
+
* creativity, reasoning needs, and more. Use this to make smarter routing
|
|
7
|
+
* decisions or to surface domain info to the user.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* node examples/classify-then-route.js
|
|
11
|
+
* QUERY="Write a Python function to sort a list" node examples/classify-then-route.js
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const { routeQuery, extractQueryFeatures, MODEL_PROFILES, getAvailableProviders } = require('../dist/index.js');
|
|
15
|
+
|
|
16
|
+
const query = process.env.QUERY || 'Write a poem about artificial intelligence in the style of Shakespeare';
|
|
17
|
+
|
|
18
|
+
function classifyAndRoute(query) {
|
|
19
|
+
// 1. Extract features
|
|
20
|
+
const features = extractQueryFeatures(query);
|
|
21
|
+
|
|
22
|
+
// 2. Determine domain
|
|
23
|
+
const domain = features.has_code ? 'code' :
|
|
24
|
+
features.has_math ? 'math' :
|
|
25
|
+
features.is_creative ? 'creative' :
|
|
26
|
+
features.requires_reasoning ? 'reasoning' :
|
|
27
|
+
'general';
|
|
28
|
+
|
|
29
|
+
// 3. Find the best model for this domain using MODEL_PROFILES
|
|
30
|
+
const profiles = Object.entries(MODEL_PROFILES)
|
|
31
|
+
.filter(([_, p]) => p.strengths?.length > 0)
|
|
32
|
+
.map(([name, p]) => ({
|
|
33
|
+
name,
|
|
34
|
+
provider: p.provider,
|
|
35
|
+
cost: p.cost_per_1k_input + p.cost_per_1k_output,
|
|
36
|
+
quality: p.quality_score,
|
|
37
|
+
strengths: p.strengths,
|
|
38
|
+
domainMatch: p.strengths.some(s => s.toLowerCase().includes(domain)),
|
|
39
|
+
}))
|
|
40
|
+
.sort((a, b) => {
|
|
41
|
+
// Prefer domain-matched, then higher quality, then lower cost
|
|
42
|
+
if (a.domainMatch !== b.domainMatch) return a.domainMatch ? -1 : 1;
|
|
43
|
+
if (a.quality !== b.quality) return b.quality - a.quality;
|
|
44
|
+
return a.cost - b.cost;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// 4. Get A3M's route decision
|
|
48
|
+
const decision = routeQuery(query);
|
|
49
|
+
|
|
50
|
+
return { features, domain, bestProfiles: profiles.slice(0, 5), decision };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function printResult(result) {
|
|
54
|
+
console.log('Query:', query);
|
|
55
|
+
console.log('');
|
|
56
|
+
|
|
57
|
+
console.log('-- Classification --');
|
|
58
|
+
console.log(' Domain: ', result.domain);
|
|
59
|
+
console.log(' Complexity: ', result.features.complexity.toFixed(2));
|
|
60
|
+
console.log(' Has code: ', result.features.has_code);
|
|
61
|
+
console.log(' Has math: ', result.features.has_math);
|
|
62
|
+
console.log(' Creative: ', result.features.is_creative);
|
|
63
|
+
console.log(' Needs reasoning: ', result.features.requires_reasoning);
|
|
64
|
+
console.log(' Multilingual: ', result.features.is_multilingual);
|
|
65
|
+
console.log('');
|
|
66
|
+
|
|
67
|
+
console.log('-- Top Domain-Matched Models --');
|
|
68
|
+
for (const p of result.bestProfiles) {
|
|
69
|
+
const matchStar = p.domainMatch ? ' *' : ' ';
|
|
70
|
+
console.log(` ${matchStar} ${p.name.padEnd(36)} quality=${p.quality.toFixed(2)} cost=$${p.cost.toFixed(6)} [${p.strengths.slice(0, 3).join(', ')}]`);
|
|
71
|
+
}
|
|
72
|
+
console.log('');
|
|
73
|
+
|
|
74
|
+
console.log('-- A3M Route Decision --');
|
|
75
|
+
console.log(' Selected model: ', result.decision.primary_model);
|
|
76
|
+
console.log(' Confidence: ', (result.decision.confidence * 100).toFixed(1) + '%');
|
|
77
|
+
console.log(' Est. cost: ', '$' + result.decision.estimated_cost.toFixed(6));
|
|
78
|
+
console.log(' Reasoning: ', result.decision.reasoning);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function main() {
|
|
82
|
+
const result = classifyAndRoute(query);
|
|
83
|
+
printResult(result);
|
|
84
|
+
|
|
85
|
+
// Demo: show how routing differs per domain
|
|
86
|
+
console.log('');
|
|
87
|
+
console.log('-- Domain Routing Comparison --');
|
|
88
|
+
const testQueries = [
|
|
89
|
+
['code', 'Write a binary search tree in Python'],
|
|
90
|
+
['math', 'Solve for x: 3x^2 + 5x - 2 = 0'],
|
|
91
|
+
['creative', 'Write a haiku about the ocean'],
|
|
92
|
+
['reasoning', 'If all A are B and some B are C, can we conclude some A are C?'],
|
|
93
|
+
['general', 'What is the weather like today?'],
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
for (const [domain, q] of testQueries) {
|
|
97
|
+
const r = classifyAndRoute(q);
|
|
98
|
+
console.log(` ${domain.padEnd(12)} -> ${r.decision.primary_model.padEnd(36)} cost=$${r.decision.estimated_cost.toFixed(6)} conf=${(r.decision.confidence * 100).toFixed(0)}%`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
main();
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* cost-compare.js — Compare costs across providers for the same prompt.
|
|
4
|
+
*
|
|
5
|
+
* A3M Router provides MODEL_PROFILES with cost-per-token data for every model.
|
|
6
|
+
* Use CostTracker to estimate real costs, and findCheapestAvailableProvider /
|
|
7
|
+
* findFastestAvailableProvider to make data-driven decisions.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* node examples/cost-compare.js
|
|
11
|
+
* INPUT_TOKENS=500 OUTPUT_TOKENS=200 node examples/cost-compare.js
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
routeQuery,
|
|
16
|
+
CostTracker,
|
|
17
|
+
MODEL_PROFILES,
|
|
18
|
+
findCheapestAvailableProvider,
|
|
19
|
+
findFastestAvailableProvider,
|
|
20
|
+
MODEL_COSTS,
|
|
21
|
+
countTokens,
|
|
22
|
+
extractQueryFeatures,
|
|
23
|
+
} = require('../dist/index.js');
|
|
24
|
+
|
|
25
|
+
const INPUT_TOKENS = parseInt(process.env.INPUT_TOKENS || '150', 10);
|
|
26
|
+
const OUTPUT_TOKENS = parseInt(process.env.OUTPUT_TOKENS || '100', 10);
|
|
27
|
+
|
|
28
|
+
function main() {
|
|
29
|
+
console.log('A3M Router — Cost Comparison');
|
|
30
|
+
console.log('=' .repeat(50));
|
|
31
|
+
console.log('Input tokens: ', INPUT_TOKENS);
|
|
32
|
+
console.log('Output tokens:', OUTPUT_TOKENS);
|
|
33
|
+
console.log('');
|
|
34
|
+
|
|
35
|
+
// 1. Find cheapest and fastest available providers
|
|
36
|
+
const cheapest = findCheapestAvailableProvider();
|
|
37
|
+
const fastest = findFastestAvailableProvider();
|
|
38
|
+
|
|
39
|
+
console.log('-- Provider Recommendations --');
|
|
40
|
+
if (cheapest) {
|
|
41
|
+
const cost = new CostTracker().calculateCost(cheapest.models[0] || 'unknown', INPUT_TOKENS, OUTPUT_TOKENS);
|
|
42
|
+
console.log(` Cheapest: ${cheapest.id.padEnd(16)} ${cheapest.models[0] || 'N/A'.padEnd(30)} $${cost.total.toFixed(6)}/req (tier: ${cheapest.tier})`);
|
|
43
|
+
}
|
|
44
|
+
if (fastest) {
|
|
45
|
+
const cost = new CostTracker().calculateCost(fastest.models[0] || 'unknown', INPUT_TOKENS, OUTPUT_TOKENS);
|
|
46
|
+
console.log(` Fastest: ${fastest.id.padEnd(16)} ${fastest.models[0] || 'N/A'.padEnd(30)} $${cost.total.toFixed(6)}/req (tier: ${fastest.tier})`);
|
|
47
|
+
}
|
|
48
|
+
console.log('');
|
|
49
|
+
|
|
50
|
+
// 2. Compare costs across all major model profiles
|
|
51
|
+
console.log('-- All Model Profiles --');
|
|
52
|
+
console.log(' Model'.padEnd(38) + 'Provider'.padEnd(14) + 'Input/1K'.padEnd(12) + 'Output/1K'.padEnd(12) + 'Est. Cost'.padEnd(12) + 'Quality');
|
|
53
|
+
console.log(' ' + '-'.repeat(90));
|
|
54
|
+
|
|
55
|
+
const profiles = Object.entries(MODEL_PROFILES)
|
|
56
|
+
.map(([name, p]) => ({
|
|
57
|
+
name,
|
|
58
|
+
provider: p.provider,
|
|
59
|
+
cost_input: p.cost_per_1k_input,
|
|
60
|
+
cost_output: p.cost_per_1k_output,
|
|
61
|
+
estimated: (p.cost_per_1k_input * INPUT_TOKENS / 1000) + (p.cost_per_1k_output * OUTPUT_TOKENS / 1000),
|
|
62
|
+
quality: p.quality_score,
|
|
63
|
+
latency: p.latency_ms,
|
|
64
|
+
context: p.context_window,
|
|
65
|
+
}))
|
|
66
|
+
.sort((a, b) => a.estimated - b.estimated);
|
|
67
|
+
|
|
68
|
+
for (const p of profiles) {
|
|
69
|
+
console.log(` ${p.name.padEnd(36)} ${p.provider.padEnd(12)} $${p.cost_input.toFixed(6).padEnd(8)} $${p.cost_output.toFixed(6).padEnd(8)} $${p.estimated.toFixed(6).padEnd(8)} ${p.quality.toFixed(2)}`);
|
|
70
|
+
}
|
|
71
|
+
console.log('');
|
|
72
|
+
|
|
73
|
+
// 3. Compare A3M routing at different budget multipliers
|
|
74
|
+
console.log('-- A3M Routing Cost Comparison --');
|
|
75
|
+
const testQuery = process.env.QUERY || 'Write a short story about a robot learning to paint';
|
|
76
|
+
const features = extractQueryFeatures(testQuery);
|
|
77
|
+
console.log(' Query:', testQuery);
|
|
78
|
+
console.log(' Complexity:', features.complexity.toFixed(2));
|
|
79
|
+
console.log('');
|
|
80
|
+
|
|
81
|
+
const budgets = [
|
|
82
|
+
{ label: 'Cost-Focused', multiplier: 0.2 },
|
|
83
|
+
{ label: 'Budget', multiplier: 0.5 },
|
|
84
|
+
{ label: 'Balanced', multiplier: 1.0 },
|
|
85
|
+
{ label: 'Quality', multiplier: 1.5 },
|
|
86
|
+
{ label: 'Max Quality', multiplier: 2.0 },
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
console.log(' ' + 'Strategy'.padEnd(16) + 'Model'.padEnd(36) + 'Cost'.padEnd(14) + 'Latency'.padEnd(12) + 'Confidence');
|
|
90
|
+
console.log(' ' + '-'.repeat(80));
|
|
91
|
+
|
|
92
|
+
for (const b of budgets) {
|
|
93
|
+
const decision = routeQuery(testQuery, undefined, b.multiplier);
|
|
94
|
+
console.log(` ${b.label.padEnd(14)} ${decision.primary_model.padEnd(34)} $${decision.estimated_cost.toFixed(6).padEnd(10)} ${decision.estimated_latency_ms}ms ${(decision.confidence * 100).toFixed(0)}%`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 4. CostTracker usage example
|
|
98
|
+
console.log('');
|
|
99
|
+
console.log('-- CostTracker Session Example --');
|
|
100
|
+
const tracker = new CostTracker({ daily_limit: 5.0 });
|
|
101
|
+
|
|
102
|
+
// Simulate 3 requests
|
|
103
|
+
tracker.record('openai', 'gpt-4o-mini', 150, 100);
|
|
104
|
+
tracker.record('groq', 'llama-3.3-70b-versatile', 200, 150);
|
|
105
|
+
tracker.record('anthropic', 'claude-3-5-sonnet-latest', 180, 120);
|
|
106
|
+
|
|
107
|
+
const summary = tracker.getSummary();
|
|
108
|
+
console.log(' Requests tracked: ', summary.request_count);
|
|
109
|
+
console.log(' Total cost: $' + summary.total_cost.toFixed(6));
|
|
110
|
+
console.log(' Avg cost/request: $' + summary.average_cost_per_request.toFixed(6));
|
|
111
|
+
console.log(' Total tokens: ', summary.token_count.input + summary.token_count.output);
|
|
112
|
+
console.log(' Daily remaining: $' + (tracker.getRemainingBudget().daily !== null ? tracker.getRemainingBudget().daily.toFixed(6) : 'unlimited'));
|
|
113
|
+
console.log('');
|
|
114
|
+
console.log(' By provider:');
|
|
115
|
+
for (const [prov, cost] of Object.entries(summary.by_provider)) {
|
|
116
|
+
console.log(` ${prov}: $${cost.toFixed(6)}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
main();
|