Ollama4j
A Java library (wrapper/binding) for Ollama server.
Loading...
Searching...
No Matches
OllamaChatMessage.java
Go to the documentation of this file.
1/*
2 * Ollama4j - Java library for interacting with Ollama server.
3 * Copyright (c) 2025 Amith Koujalgi and contributors.
4 *
5 * Licensed under the MIT License (the "License");
6 * you may not use this file except in compliance with the License.
7 *
8*/
9package io.github.ollama4j.models.chat;
10
11import static io.github.ollama4j.utils.Utils.getObjectMapper;
12
13import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
14import com.fasterxml.jackson.annotation.JsonProperty;
15import com.fasterxml.jackson.core.JsonProcessingException;
16import com.fasterxml.jackson.databind.annotation.JsonSerialize;
17import io.github.ollama4j.utils.FileToBase64Serializer;
18import java.util.List;
19import lombok.*;
20
28@SuppressWarnings("NullableProblems")
29@Data
30@AllArgsConstructor
31@RequiredArgsConstructor
32@NoArgsConstructor
33@JsonIgnoreProperties(ignoreUnknown = true)
34public class OllamaChatMessage {
35
36 @NonNull private OllamaChatMessageRole role;
37
38 @JsonProperty("content")
39 @NonNull
40 private String response;
41
42 private String thinking;
43
44 private @JsonProperty("tool_calls") List<OllamaChatToolCalls> toolCalls;
45
46 @JsonSerialize(using = FileToBase64Serializer.class)
47 private List<byte[]> images;
48
49 @Override
50 public String toString() {
51 try {
52 return getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this);
53 } catch (JsonProcessingException e) {
54 throw new RuntimeException(e);
55 }
56 }
57}