Package com.tnsai.reasoning
Class ReasoningRouter
java.lang.Object
com.tnsai.reasoning.ReasoningRouter
- All Implemented Interfaces:
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?");
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for ReasoningRouter. -
Method Summary
Modifier and TypeMethodDescriptionstatic ReasoningRouter.Builderbuilder()Creates a new builder for ReasoningRouter.doublecalculateReasoningScore(String query) Calculates a reasoning score for the given query.com.tnsai.llm.ChatResponsechat(String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) getModel()com.tnsai.llm.LLMClientGets the reasoning model.com.tnsai.llm.LLMClientGets the standard model.floatdoubleGets the routing threshold.com.tnsai.llm.LLMClientselectModel(String query) Determines which model to use for the query.streamChat(String message, Optional<String> systemPrompt, Optional<List<Map<String, Object>>> history, Optional<List<Map<String, Object>>> tools) Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tnsai.llm.LLMClient
chat, chat, chat, chat, chat, getCapabilities, getProviderName, getTopP, listModels, streamChat, streamChat, streamChatWithHandler, streamChatWithHandler, streamChatWithSpec, streamChatWithSpec
-
Method Details
-
builder
Creates a new builder for ReasoningRouter. -
calculateReasoningScore
Calculates a reasoning score for the given query.- Parameters:
query- The query to analyze- Returns:
- Score between 0.0 and 1.0
-
selectModel
Determines which model to use for the query.- Parameters:
query- The query to route- Returns:
- The selected LLM client
-
getModel
- Specified by:
getModelin interfacecom.tnsai.llm.LLMClient
-
getTemperature
public float getTemperature()- Specified by:
getTemperaturein interfacecom.tnsai.llm.LLMClient
-
getMaxTokens
- Specified by:
getMaxTokensin interfacecom.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:
chatin interfacecom.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:
streamChatin interfacecom.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.
-