Class RoutingChatModel.Builder
java.lang.Object
dev.langchain4j.model.chat.router.RoutingChatModel.Builder
- Enclosing class:
RoutingChatModel
- Since:
- 1.21.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()defaultRoute(String defaultRoute) Sets the route used when the router selects the default route (ChatModelRoutingResult.defaultRoute()), for example when a router that calls a model is unsure or fails.Adds a route without a description, for routers that do not decide based on descriptions.Adds a route.Adds a route with several descriptions, for a route meant for requests about different topics, for exampleroute("complex", List.of("Writing or debugging code", "Legal contract analysis"), largeModel).router(ChatModelRouter router) Sets the router that selects the route of each request.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
route
Adds a route without a description, for routers that do not decide based on descriptions.- Parameters:
name- the unique name of the route.model- the chat model that handles the requests sent to this route.
-
route
Adds a route. At least one route is required.- Parameters:
name- the unique name of the route. It is stored with the responses (seeRoutingChatModel.ROUTE_ATTRIBUTE), so keep it stable.description- what kind of requests this route is meant for, used by routers that decide based on the content of the request, such asDecisionModelChatModelRouter. Optional: without a description, the route is described by its name.model- the chat model that handles the requests sent to this route.
-
route
Adds a route with several descriptions, for a route meant for requests about different topics, for exampleroute("complex", List.of("Writing or debugging code", "Legal contract analysis"), largeModel). Routers that decide based on the descriptions, such asDecisionModelChatModelRouter, consider each description separately, which can make them more confident than one description that mixes all topics. When the decision model is unsure, a route with more descriptions gets more of the probability, so keep the number of descriptions of the routes balanced.- Parameters:
name- the unique name of the route, seeroute(String, String, ChatModel).descriptions- the kinds of requests this route is meant for, for example one per topic.model- the chat model that handles the requests sent to this route.
-
router
Sets the router that selects the route of each request. Required. -
defaultRoute
Sets the route used when the router selects the default route (ChatModelRoutingResult.defaultRoute()), for example when a router that calls a model is unsure or fails. Required. -
build
-