Class ChatModelFactory

java.lang.Object
com.axelor.ai.chat.ChatModelFactory

public class ChatModelFactory extends Object
Creates non-streaming ChatModel instances for background tasks and resolves which model to use based on agent configuration.
  • Method Details

    • resolveUtilityModel

      public AiModel resolveUtilityModel(ChatRequest request)
      Resolves the utility model for background tasks. Falls back through: agent's utility model → agent's primary model → global default chat model. A task sends the chat's history, so when that model may not receive what the chat holds, the turn's own model does the task instead — held to the same question, since a consulted agent may have read data during the turn that its caller's model may not receive: none when neither may, and the task is skipped.
    • resolveUtilityModel

      public AiModel resolveUtilityModel(AiChat chat)
      The utility model of a chat outside any request — a recap posted from it — falling back, like resolveUtilityModel(ChatRequest), to the chat's own model when it may not receive what the chat holds. No turn's gate stands before this call, so each fallback is held to the same question: none when no candidate may receive the chat.
    • resolveUtilityModel

      public AiModel resolveUtilityModel(AiAgent agent)
      The same fallback for a caller that holds the agent rather than a request. A null agent lands on the global default, which is the right answer for a chat that never named one.
    • resolveReplyTokens

      public Integer resolveReplyTokens(ChatRequest request, AiModel model)
      The most tokens a reply to this request on model may take; null where the provider's own default applies.
    • resolvePrimaryModel

      public AiModel resolvePrimaryModel(ChatRequest request)
    • create

      public static dev.langchain4j.model.chat.ChatModel create(AiModel model, int maxOutputTokens, boolean background, ChatModelFactory.Usage usage)
      A utility call's model, every call of which is logged with what it went to and carried.
      See Also:
    • create

      public static dev.langchain4j.model.chat.ChatModel create(AiModel model, int maxOutputTokens)
      Creates a non-streaming ChatModel with the given max output tokens. Request/response logging is controlled via ai.logging.requests and ai.logging.responses in axelor-config.properties.
    • create

      public static dev.langchain4j.model.chat.ChatModel create(AiModel model, int maxOutputTokens, boolean background)
      Parameters:
      background - whether nobody is waiting on the reply, so the model's backgroundServiceTier applies. A task that holds a stream open until it answers — a title, a compaction summary — is not background.