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

fi.evolver.ai.spring.completion.CompletionResponse Maven / Gradle / Ivy

package fi.evolver.ai.spring.completion;

import fi.evolver.ai.spring.completion.prompt.CompletionPrompt;
import fi.evolver.ai.spring.ContentSubscriber;
import fi.evolver.ai.spring.util.RateLimitHeaders;

import java.util.Optional;

/**
 *
 */
public abstract class CompletionResponse {
  
	private final CompletionPrompt prompt;

	protected CompletionResponse(CompletionPrompt prompt) {
		this.prompt = prompt;
	}


	/**
	 * The prompt used as the input for the request.
	 *
	 * @return The prompt.
	 */
	public CompletionPrompt getPrompt() {
		return prompt;
	}

	/**
	 * Add a subscriber for streaming content updates.
	 *
	 * @param subscriber The subscriber to add.
	 */
	public abstract void addSubscriber(ContentSubscriber subscriber);

	/**
	 * Returns the response completion, if any. May block until the full response has been fully received.
	 *
	 * @return The result completion, if any.
	 */
	public abstract Optional getCompletionContent();

	/**
	 * The result state of the response. How to interpret the value is API specific.
	 *
	 * @return The result state of the response.
	 */
	public abstract String getResultState();

	/**
	 * Return whether the response completed without issued.
	 *
	 * @return Whether the response completed without issued.
	 */
	public abstract boolean isSuccess();

	/**
	 * Returns the rate limit headers for the response.
	 *
	 * @return The rate limit headers.
	 */
	public abstract RateLimitHeaders getRateLimitHeaders();

	/**
	 * The complete text from the prompt and the completion response, if any.
	 * Will block until the completion has been received or we know there is no completion
	 *
	 * @return The complete text
	 */
	public String getCompleteText() {
		return getPrompt().prompt() + getCompletionContent().orElse("");
	}



}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy