Class Message.Builder

All Implemented Interfaces:
WithJson<Message.Builder>, ObjectBuilder<Message>
Enclosing class:
Message

public static class Message.Builder extends WithJsonObjectBuilderBase<Message.Builder> implements ObjectBuilder<Message>
Builder for Message.
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • content

      public final Message.Builder content(@Nullable MessageContent value)
      The content of the message.

      String example:

       {
          "content": "Some string"
       }
       
       

      Text example:

       {
         "content": [
             {
              "text": "Some text",
              "type": "text"
             }
          ]
       }
       
       

      Image example:

       {
         "content": [
             {
              "image_url": {
                "url": "data:image/jpeg;base64,..."
              },
              "type": "image_url"
             }
          ]
       }
       
       

      File example:

       {
         "content": [
             {
              "file": {
                "file_data": "data:application/pdf;base64,...",
                "filename": "somePDF"
              },
              "type": "file"
             }
          ]
       }
       
       

      API name: content

    • content

      The content of the message.

      String example:

       {
          "content": "Some string"
       }
       
       

      Text example:

       {
         "content": [
             {
              "text": "Some text",
              "type": "text"
             }
          ]
       }
       
       

      Image example:

       {
         "content": [
             {
              "image_url": {
                "url": "data:image/jpeg;base64,..."
              },
              "type": "image_url"
             }
          ]
       }
       
       

      File example:

       {
         "content": [
             {
              "file": {
                "file_data": "data:application/pdf;base64,...",
                "filename": "somePDF"
              },
              "type": "file"
             }
          ]
       }
       
       

      API name: content

    • role

      public final Message.Builder role(String value)
      Required - The role of the message author. Valid values are user, assistant, system, and tool.

      API name: role

    • toolCallId

      public final Message.Builder toolCallId(@Nullable String value)
      Only for tool role messages. The tool call that this message is responding to.

      API name: tool_call_id

    • toolCalls

      public final Message.Builder toolCalls(List<ToolCall> list)
      Only for assistant role messages. The tool calls generated by the model. If it's specified, the content field is optional. Example:
       {
         "tool_calls": [
             {
                 "id": "call_KcAjWtAww20AihPHphUh46Gd",
                 "type": "function",
                 "function": {
                     "name": "get_current_weather",
                     "arguments": "{\"location\":\"Boston, MA\"}"
                 }
             }
         ]
       }
       
       

      API name: tool_calls

      Adds all elements of list to toolCalls.

    • toolCalls

      public final Message.Builder toolCalls(ToolCall value, ToolCall... values)
      Only for assistant role messages. The tool calls generated by the model. If it's specified, the content field is optional. Example:
       {
         "tool_calls": [
             {
                 "id": "call_KcAjWtAww20AihPHphUh46Gd",
                 "type": "function",
                 "function": {
                     "name": "get_current_weather",
                     "arguments": "{\"location\":\"Boston, MA\"}"
                 }
             }
         ]
       }
       
       

      API name: tool_calls

      Adds one or more values to toolCalls.

    • toolCalls

      Only for assistant role messages. The tool calls generated by the model. If it's specified, the content field is optional. Example:
       {
         "tool_calls": [
             {
                 "id": "call_KcAjWtAww20AihPHphUh46Gd",
                 "type": "function",
                 "function": {
                     "name": "get_current_weather",
                     "arguments": "{\"location\":\"Boston, MA\"}"
                 }
             }
         ]
       }
       
       

      API name: tool_calls

      Adds a value to toolCalls using a builder lambda.

    • reasoning

      public final Message.Builder reasoning(@Nullable String value)
      Only for assistant role messages. The reasoning details generated by the model as plaintext. Currently supported only for elastic provider.

      API name: reasoning

    • reasoningDetails

      public final Message.Builder reasoningDetails(List<ReasoningDetail> list)
      Only for assistant role messages. The reasoning details generated by the model as structured data. Currently supported only for elastic provider.

      API name: reasoning_details

      Adds all elements of list to reasoningDetails.

    • reasoningDetails

      public final Message.Builder reasoningDetails(ReasoningDetail value, ReasoningDetail... values)
      Only for assistant role messages. The reasoning details generated by the model as structured data. Currently supported only for elastic provider.

      API name: reasoning_details

      Adds one or more values to reasoningDetails.

    • reasoningDetails

      Only for assistant role messages. The reasoning details generated by the model as structured data. Currently supported only for elastic provider.

      API name: reasoning_details

      Adds a value to reasoningDetails using a builder lambda.

    • self

      protected Message.Builder self()
      Specified by:
      self in class WithJsonObjectBuilderBase<Message.Builder>
    • build

      public Message build()
      Builds a Message.
      Specified by:
      build in interface ObjectBuilder<Message>
      Throws:
      NullPointerException - if some of the required fields are null.