All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.launchableinc.openai.completion.chat.ChatFunction Maven / Gradle / Ivy

There is a newer version: 0.4.0
Show newest version
package com.launchableinc.openai.completion.chat;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;

import java.util.function.Function;

@Data
@NoArgsConstructor
public class ChatFunction {

	/**
	 * The name of the function being called.
	 */
	@NonNull
	private String name;

	/**
	 * A description of what the function does, used by the model to choose when and how to call the
	 * function.
	 */
	private String description;

	/**
	 * The parameters the functions accepts.
	 */
	@JsonProperty("parameters")
	private Class parametersClass;

	@JsonIgnore
	private Function executor;

	public static Builder builder() {
		return new Builder();
	}

	public static class Builder {

		private String name;
		private String description;
		private Class parameters;
		private Function executor;

		public Builder name(String name) {
			this.name = name;
			return this;
		}

		public Builder description(String description) {
			this.description = description;
			return this;
		}

		public  Builder executor(Class requestClass, Function executor) {
			this.parameters = requestClass;
			this.executor = (Function) executor;
			return this;
		}

		public ChatFunction build() {
			ChatFunction chatFunction = new ChatFunction();
			chatFunction.setName(name);
			chatFunction.setDescription(description);
			chatFunction.setParametersClass(parameters);
			chatFunction.setExecutor(executor);
			return chatFunction;
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy