Class RoutingStreamingChatModel.Builder

java.lang.Object
dev.langchain4j.model.chat.router.RoutingStreamingChatModel.Builder
Enclosing class:
RoutingStreamingChatModel

public static class RoutingStreamingChatModel.Builder extends Object
Since:
1.21.0
  • 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 streaming chat model that handles the requests sent to this route.
    • route

      public RoutingStreamingChatModel.Builder route(String name, String description, StreamingChatModel model)
      Adds a route. At least one route is required.
      Parameters:
      name - the unique name of the route. It is stored with the responses (see RoutingChatModel.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 as DecisionModelChatModelRouter. Optional: without a description, the route is described by its name.
      model - the streaming chat model that handles the requests sent to this route.
    • route

      public RoutingStreamingChatModel.Builder route(String name, List<String> descriptions, StreamingChatModel model)
      Adds a route with several descriptions, for a route meant for requests about different topics, for example route("complex", List.of("Writing or debugging code", "Legal contract analysis"), largeModel). Routers that decide based on the descriptions, such as DecisionModelChatModelRouter, 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, see route(String, String, StreamingChatModel).
      descriptions - the kinds of requests this route is meant for, for example one per topic.
      model - the streaming chat model that handles the requests sent to this route.
    • router

      Sets the router that selects the route of each request. Required.
    • defaultRoute

      public RoutingStreamingChatModel.Builder 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. Required.
    • build

      public RoutingStreamingChatModel build()