Remove deprecated UserMessage constructors · spring-projects/spring-ai@06edee4 (original) (raw)

`@@ -470,8 +470,10 @@ void multiModalityEmbeddedImage(String modelName) throws IOException {

`

470

470

``

471

471

`var imageData = new ClassPathResource("/test.png");

`

472

472

``

473

``

`-

var userMessage = new UserMessage("Explain what do you see on this picture?",

`

474

``

`-

List.of(new Media(MimeTypeUtils.IMAGE_PNG, imageData)));

`

``

473

`+

var userMessage = UserMessage.builder()

`

``

474

`+

.text("Explain what do you see on this picture?")

`

``

475

`+

.media(List.of(new Media(MimeTypeUtils.IMAGE_PNG, imageData)))

`

``

476

`+

.build();

`

475

477

``

476

478

`var response = this.chatModel

`

477

479

` .call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().model(modelName).build()));

`

`@@ -485,11 +487,13 @@ void multiModalityEmbeddedImage(String modelName) throws IOException {

`

485

487

`@ValueSource(strings = { "gpt-4o" })

`

486

488

`void multiModalityImageUrl(String modelName) throws IOException {

`

487

489

``

488

``

`-

var userMessage = new UserMessage("Explain what do you see on this picture?",

`

489

``

`-

List.of(Media.builder()

`

490

``

`-

.mimeType(MimeTypeUtils.IMAGE_PNG)

`

491

``

`-

.data(new URL("https://docs.spring.io/spring-ai/reference/_images/multimodal.test.png"))

`

492

``

`-

.build()));

`

``

490

`+

var userMessage = UserMessage.builder()

`

``

491

`+

.text("Explain what do you see on this picture?")

`

``

492

`+

.media(List.of(Media.builder()

`

``

493

`+

.mimeType(MimeTypeUtils.IMAGE_PNG)

`

``

494

`+

.data(new URL("https://docs.spring.io/spring-ai/reference/_images/multimodal.test.png"))

`

``

495

`+

.build()))

`

``

496

`+

.build();

`

493

497

``

494

498

`ChatResponse response = this.chatModel

`

495

499

` .call(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().model(modelName).build()));

`

`@@ -502,11 +506,13 @@ void multiModalityImageUrl(String modelName) throws IOException {

`

502

506

`@Test

`

503

507

`void streamingMultiModalityImageUrl() throws IOException {

`

504

508

``

505

``

`-

var userMessage = new UserMessage("Explain what do you see on this picture?",

`

506

``

`-

List.of(Media.builder()

`

507

``

`-

.mimeType(MimeTypeUtils.IMAGE_PNG)

`

508

``

`-

.data(new URL("https://docs.spring.io/spring-ai/reference/_images/multimodal.test.png"))

`

509

``

`-

.build()));

`

``

509

`+

var userMessage = UserMessage.builder()

`

``

510

`+

.text("Explain what do you see on this picture?")

`

``

511

`+

.media(List.of(Media.builder()

`

``

512

`+

.mimeType(MimeTypeUtils.IMAGE_PNG)

`

``

513

`+

.data(new URL("https://docs.spring.io/spring-ai/reference/_images/multimodal.test.png"))

`

``

514

`+

.build()))

`

``

515

`+

.build();

`

510

516

``

511

517

`Flux response = this.streamingChatModel.stream(new Prompt(List.of(userMessage),

`

512

518

`OpenAiChatOptions.builder().model(OpenAiApi.ChatModel.GPT_4_O.getValue()).build()));

`

`@@ -565,8 +571,10 @@ void streamingMultiModalityOutputAudio(String modelName) throws IOException {

`

565

571

`@ValueSource(strings = { "gpt-4o-audio-preview" })

`

566

572

`void multiModalityInputAudio(String modelName) {

`

567

573

`var audioResource = new ClassPathResource("speech1.mp3");

`

568

``

`-

var userMessage = new UserMessage("What is this recording about?",

`

569

``

`-

List.of(new Media(MimeTypeUtils.parseMimeType("audio/mp3"), audioResource)));

`

``

574

`+

var userMessage = UserMessage.builder()

`

``

575

`+

.text("What is this recording about?")

`

``

576

`+

.media(List.of(new Media(MimeTypeUtils.parseMimeType("audio/mp3"), audioResource)))

`

``

577

`+

.build();

`

570

578

``

571

579

`ChatResponse response = this.chatModel

`

572

580

` .call(new Prompt(List.of(userMessage), ChatOptions.builder().model(modelName).build()));

`

`@@ -580,8 +588,10 @@ void multiModalityInputAudio(String modelName) {

`

580

588

`@ValueSource(strings = { "gpt-4o-audio-preview" })

`

581

589

`void streamingMultiModalityInputAudio(String modelName) {

`

582

590

`var audioResource = new ClassPathResource("speech1.mp3");

`

583

``

`-

var userMessage = new UserMessage("What is this recording about?",

`

584

``

`-

List.of(new Media(MimeTypeUtils.parseMimeType("audio/mp3"), audioResource)));

`

``

591

`+

var userMessage = UserMessage.builder()

`

``

592

`+

.text("What is this recording about?")

`

``

593

`+

.media(List.of(new Media(MimeTypeUtils.parseMimeType("audio/mp3"), audioResource)))

`

``

594

`+

.build();

`

585

595

``

586

596

`Flux response = this.chatModel

`

587

597

` .stream(new Prompt(List.of(userMessage), OpenAiChatOptions.builder().model(modelName).build()));

`