Class ReasoningRouter

java.lang.Object
com.tnsai.reasoning.ReasoningRouter
All Implemented Interfaces:
com.tnsai.llm.LLMClient

public class ReasoningRouter extends Object implements com.tnsai.llm.LLMClient
Routes queries to reasoning-specialized models based on task complexity.

Detects reasoning tasks (math, logic, planning, coding) and routes them to specialized models like o1, DeepSeek-R1, or Qwen-Math while using standard models for simple queries.

Usage


 ReasoningRouter router = ReasoningRouter.builder()
     .reasoningModel(o1Client)      // For complex reasoning
     .standardModel(gpt4oClient)    // For simple queries
     .threshold(0.7)                // Routing threshold
     .build();

 // Automatically routes to o1 for complex math
 ChatResponse response = router.chat("Prove that sqrt(2) is irrational");

 // Uses gpt-4o for simple queries
 ChatResponse response2 = router.chat("What is the capital of France?");
 
  • Method Details

    • builder

      public static ReasoningRouter.Builder builder()
      Creates a new builder for ReasoningRouter.
    • calculateReasoningScore

      public double calculateReasoningScore(String query)
      Calculates a reasoning score for the given query.
      Parameters:
      query - The query to analyze
      Returns:
      Score between 0.0 and 1.0
    • selectModel

      public com.tnsai.llm.LLMClient selectModel(String query)
      Determines which model to use for the query.
      Parameters:
      query - The query to route
      Returns:
      The selected LLM client
    • getModel

      public String getModel()
      Specified by:
      getModel in interface com.tnsai.llm.LLMClient
    • getTemperature

      public float getTemperature()
      Specified by:
      getTemperature in interface com.tnsai.llm.LLMClient
    • getMaxTokens

      public Optional<Integer> getMaxTokens()
      Specified by:
      getMaxTokens in interface com.tnsai.llm.LLMClient
    • chat

      public com.tnsai.llm.ChatResponse chat(String message, Optional<String> systemPrompt, Optional<List<Map<String,Object>>> history, Optional<List<Map<String,Object>>> tools)
      Specified by:
      chat in interface com.tnsai.llm.LLMClient
    • streamChat

      public Stream<String> streamChat(String message, Optional<String> systemPrompt, Optional<List<Map<String,Object>>> history, Optional<List<Map<String,Object>>> tools)
      Specified by:
      streamChat in interface com.tnsai.llm.LLMClient
    • getReasoningModel

      public com.tnsai.llm.LLMClient getReasoningModel()
      Gets the reasoning model.
    • getStandardModel

      public com.tnsai.llm.LLMClient getStandardModel()
      Gets the standard model.
    • getThreshold

      public double getThreshold()
      Gets the routing threshold.