Class ModelCall

java.lang.Object
dev.langchain4j.test.service.ModelCall
Direct Known Subclasses:
ChatModelCall, DecisionModelCall, EmbeddingModelCall, ModerationModelCall, ScoringModelCall

A call to a model made during an AI Service invocation: by the AI Service itself to its chat model (see ChatModelCall.isOwn()), or by the components it runs, for example a query transformer or a judge calling a chat model, an embedding model used for retrieval, or a scoring model that re-ranks the retrieved contents.

There is one subclass per type of model, with the request and the response of that type: ChatModelCall, EmbeddingModelCall, ScoringModelCall, ModerationModelCall and DecisionModelCall.

Only calls whose listeners LangChain4j notifies are captured: the calls that go through the default methods of the model interfaces (chat, embed, score, moderate, decide), which most models of LangChain4j do. The calls of a model that bypasses them are not captured, for example a chat model that overrides chat(...) instead of implementing doChat(...), or VertexAiScoringModel. See AiServiceInvocation.modelCalls().

  • Method Details

    • modelProvider

      public ModelProvider modelProvider()
      Returns the provider of the model, or null if the model does not report it.
    • request

      public abstract Object request()
      Returns the request sent to the model. Each subclass returns the request type of its model, for example ChatModelCall.request() returns a ChatRequest.
    • response

      public abstract Object response()
      Returns the response of the model, or null if the call failed or had not ended when the invocation finished. Each subclass returns the response type of its model, for example ChatModelCall.response() returns a ChatResponse.
    • error

      public Throwable error()
      Returns the error the call failed with, or null if it did not fail.
    • hasFailed

      public boolean hasFailed()
      Returns whether the call failed, that is whether error() is not null. A call that had not ended when the invocation finished has not failed: it has neither a response nor an error.
    • toString

      public String toString()
      Overrides:
      toString in class Object