Class MistralAiChatModel

java.lang.Object
dev.langchain4j.model.mistralai.MistralAiChatModel
All Implemented Interfaces:
dev.langchain4j.model.chat.ChatLanguageModel

public class MistralAiChatModel extends Object implements dev.langchain4j.model.chat.ChatLanguageModel
Represents a Mistral AI Chat Model with a chat completion interface, such as open-mistral-7b and open-mixtral-8x7b This model allows generating chat completion of a sync way based on a list of chat messages. You can find description of parameters here.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    MistralAiChatModel(String baseUrl, String apiKey, String modelName, Double temperature, Double topP, Integer maxTokens, Boolean safePrompt, Integer randomSeed, String responseFormat, Duration timeout, Boolean logRequests, Boolean logResponses, Integer maxRetries)
    Constructs a MistralAiChatModel with the specified parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
     
    dev.langchain4j.model.output.Response<dev.langchain4j.data.message.AiMessage>
    generate(List<dev.langchain4j.data.message.ChatMessage> messages)
    Generates chat response based on the given list of messages.
    dev.langchain4j.model.output.Response<dev.langchain4j.data.message.AiMessage>
    generate(List<dev.langchain4j.data.message.ChatMessage> messages, dev.langchain4j.agent.tool.ToolSpecification toolSpecification)
    Generates an AI message response based on the given list of chat messages and a tool specification.
    dev.langchain4j.model.output.Response<dev.langchain4j.data.message.AiMessage>
    generate(List<dev.langchain4j.data.message.ChatMessage> messages, List<dev.langchain4j.agent.tool.ToolSpecification> toolSpecifications)
    Generates an AI message response based on the given list of chat messages and tool specifications.
    Creates a MistralAiChatModel with the specified API key.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface dev.langchain4j.model.chat.ChatLanguageModel

    generate, generate
  • Constructor Details

    • MistralAiChatModel

      public MistralAiChatModel(String baseUrl, String apiKey, String modelName, Double temperature, Double topP, Integer maxTokens, Boolean safePrompt, Integer randomSeed, String responseFormat, Duration timeout, Boolean logRequests, Boolean logResponses, Integer maxRetries)
      Constructs a MistralAiChatModel with the specified parameters.
      Parameters:
      baseUrl - the base URL of the Mistral AI API. It uses the default value if not specified
      apiKey - the API key for authentication
      modelName - the name of the Mistral AI model to use
      temperature - the temperature parameter for generating chat responses
      topP - the top-p parameter for generating chat responses
      maxTokens - the maximum number of new tokens to generate in a chat response
      safePrompt - a flag indicating whether to use a safe prompt for generating chat responses
      randomSeed - the random seed for generating chat responses
      responseFormat - the response format for generating chat responses.

      Current values supported are "text" and "json_object".

      timeout - the timeout duration for API requests

      The default value is 60 seconds

      logRequests - a flag indicating whether to log API requests
      logResponses - a flag indicating whether to log API responses
      maxRetries - the maximum number of retries for API requests. It uses the default value 3 if not specified
  • Method Details

    • withApiKey

      public static MistralAiChatModel withApiKey(String apiKey)
      Creates a MistralAiChatModel with the specified API key.
      Parameters:
      apiKey - the API key for authentication
      Returns:
      a MistralAiChatModel instance
    • generate

      public dev.langchain4j.model.output.Response<dev.langchain4j.data.message.AiMessage> generate(List<dev.langchain4j.data.message.ChatMessage> messages)
      Generates chat response based on the given list of messages.
      Specified by:
      generate in interface dev.langchain4j.model.chat.ChatLanguageModel
      Parameters:
      messages - the list of chat messages
    • generate

      public dev.langchain4j.model.output.Response<dev.langchain4j.data.message.AiMessage> generate(List<dev.langchain4j.data.message.ChatMessage> messages, List<dev.langchain4j.agent.tool.ToolSpecification> toolSpecifications)
      Generates an AI message response based on the given list of chat messages and tool specifications.
      Specified by:
      generate in interface dev.langchain4j.model.chat.ChatLanguageModel
      Parameters:
      messages - the list of chat messages
      toolSpecifications - the list of tool specifications. tool_choice is set to AUTO.
      Returns:
      a Response containing the generated AI message
    • generate

      public dev.langchain4j.model.output.Response<dev.langchain4j.data.message.AiMessage> generate(List<dev.langchain4j.data.message.ChatMessage> messages, dev.langchain4j.agent.tool.ToolSpecification toolSpecification)
      Generates an AI message response based on the given list of chat messages and a tool specification.
      Specified by:
      generate in interface dev.langchain4j.model.chat.ChatLanguageModel
      Parameters:
      messages - the list of chat messages
      toolSpecification - the tool specification that must be executed. tool_choice is set to ANY.
      Returns:
      a Response containing the generated AI message
    • builder