
dev.langchain4j.model.chat.request.ChatRequest Maven / Gradle / Ivy
package dev.langchain4j.model.chat.request;
import dev.langchain4j.Experimental;
import dev.langchain4j.agent.tool.ToolSpecification;
import dev.langchain4j.data.message.ChatMessage;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import static dev.langchain4j.internal.Utils.copyIfNotNull;
import static dev.langchain4j.internal.ValidationUtils.ensureNotEmpty;
import static java.util.Arrays.asList;
@Experimental
public class ChatRequest {
private final List messages;
private final List toolSpecifications; // TODO add section with tools?
private final ResponseFormat responseFormat;
private ChatRequest(Builder builder) {
this.messages = new ArrayList<>(ensureNotEmpty(builder.messages, "messages"));
this.toolSpecifications = copyIfNotNull(builder.toolSpecifications);
this.responseFormat = builder.responseFormat;
}
public List messages() {
return messages;
}
public List toolSpecifications() {
return toolSpecifications;
}
public ResponseFormat responseFormat() {
return responseFormat;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ChatRequest that = (ChatRequest) o;
return Objects.equals(this.messages, that.messages)
&& Objects.equals(this.toolSpecifications, that.toolSpecifications)
&& Objects.equals(this.responseFormat, that.responseFormat);
}
@Override
public int hashCode() {
return Objects.hash(messages, toolSpecifications, responseFormat);
}
@Override
public String toString() {
return "ChatRequest {" +
" messages = " + messages +
", toolSpecifications = " + toolSpecifications +
", responseFormat = " + responseFormat +
" }";
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private List messages;
private List toolSpecifications;
private ResponseFormat responseFormat;
public Builder messages(List messages) {
this.messages = messages;
return this;
}
public Builder messages(ChatMessage... messages) {
return messages(asList(messages));
}
public Builder toolSpecifications(List toolSpecifications) {
this.toolSpecifications = toolSpecifications;
return this;
}
public Builder toolSpecifications(ToolSpecification... toolSpecifications) {
return toolSpecifications(asList(toolSpecifications));
}
public Builder responseFormat(ResponseFormat responseFormat) {
this.responseFormat = responseFormat;
return this;
}
// TODO consider adding responseFormat(JsonSchema) or jsonSchema(JsonSchema)
public ChatRequest build() {
return new ChatRequest(this);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy