Class GPTConfiguration
- java.lang.Object
-
- com.composum.ai.backend.base.service.chat.GPTConfiguration
-
public class GPTConfiguration extends Object
A configuration to use for accessing the external LLM service. That currently contains the API key for ChatGPT, but could later include information about which LLM to use, template language, rate limiting, etc. This can be a separate parameter to a request, or implicitly contained in a passed GPTChatRequest.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GPTConfiguration.AnswerType
static class
GPTConfiguration.GPTContextInfo
Gives the conversation a history - additional assistant - user message pair.static class
GPTConfiguration.Mode
-
Field Summary
Fields Modifier and Type Field Description static GPTConfiguration
CHAT
static GPTConfiguration
DEBUG
If set, the AI services will not call the AI but return the JSON request as response, for debugging purposes.static GPTConfiguration
GENERATE
static GPTConfiguration
HIGH_INTELLIGENCE
Requests slower and more expensive "high intelligence" model - use sparingly.static GPTConfiguration
HTML
static GPTConfiguration
JSON
static GPTConfiguration
MARKDOWN
static GPTConfiguration
NULLCFG
static GPTConfiguration
STANDARD_INTELLIGENCE
Requests faster and less expensive "normal intelligence" model.
-
Constructor Summary
Constructors Constructor Description GPTConfiguration(String apiKey, String organizationId, GPTConfiguration.AnswerType answerType)
GPTConfiguration(String apiKey, String organizationId, GPTConfiguration.AnswerType answerType, String additionalInstructions)
GPTConfiguration(String apiKey, String organizationId, GPTConfiguration.AnswerType answerType, String additionalInstructions, GPTConfiguration.Mode mode)
GPTConfiguration(String apiKey, String organizationId, GPTConfiguration.AnswerType answerType, String additionalInstructions, GPTConfiguration.Mode mode, Boolean highIntelligenceNeeded)
GPTConfiguration(String apiKey, String organizationId, GPTConfiguration.AnswerType answerType, String additionalInstructions, GPTConfiguration.Mode mode, Boolean highIntelligenceNeeded, Boolean debug)
GPTConfiguration(String apiKey, String organizationId, GPTConfiguration.AnswerType answerType, String additionalInstructions, GPTConfiguration.Mode mode, Boolean highIntelligenceNeeded, Boolean debug, Double temperature)
GPTConfiguration(String apiKey, String organizationId, GPTConfiguration.AnswerType answerType, String additionalInstructions, GPTConfiguration.Mode mode, Boolean highIntelligenceNeeded, Boolean debug, Double temperature, Integer seed)
GPTConfiguration(String apiKey, String organizationId, GPTConfiguration.AnswerType answerType, String additionalInstructions, GPTConfiguration.Mode mode, Boolean highIntelligenceNeeded, Boolean debug, Double temperature, Integer seed, List<GPTConfiguration.GPTContextInfo> contexts)
GPTConfiguration(String apiKey, String organizationId, GPTConfiguration.AnswerType answerType, String additionalInstructions, GPTConfiguration.Mode mode, Boolean highIntelligenceNeeded, Boolean debug, Double temperature, Integer seed, List<GPTConfiguration.GPTContextInfo> contexts, List<GPTTool> tools)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
String
getAdditionalInstructions()
Optionally, additional instructions to add to the system prompt.GPTConfiguration.AnswerType
getAnswerType()
The type of answer we want from the LLM.String
getApiKey()
The API key to use with ChatGPT or another service.List<GPTConfiguration.GPTContextInfo>
getContexts()
Additional context information to provide to the AI.Boolean
getDebug()
If this is set, then the services will not call the AI and return the JSON request instead of the AI response.GPTConfiguration.Mode
getMode()
String
getOrganizationId()
The organization id to use with ChatGPT.Integer
getSeed()
If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result.Double
getTemperature()
The sampling temperature, between 0 and 1.List<GPTTool>
getTools()
A list of tools the Model could use.int
hashCode()
boolean
highIntelligenceNeededIsSet()
If true, this requires to uses the slower and more expensive high intelligence model - use sparingly for more challenging tasks.boolean
highIntelligenceNeededIsUnset()
If true, there is no information whether a "high intelligence model" is used - uses the default.boolean
isHtml()
GPTConfiguration
merge(GPTConfiguration other)
Creates a configuration that joins the values.GPTConfiguration
merge(GPTConfiguration other, boolean override)
Creates a configuration that joins the values.static GPTConfiguration
merge(GPTConfiguration first, GPTConfiguration second)
merge(GPTConfiguration)
several configurations.static GPTConfiguration
ofAdditionalInstructions(String additionalInstructions)
static GPTConfiguration
ofContext(String usermsg, String assistantmsg)
static GPTConfiguration
ofContexts(List<GPTConfiguration.GPTContextInfo> contexts)
static GPTConfiguration
ofRichText(boolean richText)
static GPTConfiguration
ofTemperature(Double temperature)
static GPTConfiguration
ofTools(List<GPTTool> tools)
GPTConfiguration
replaceContexts(List<GPTConfiguration.GPTContextInfo> newContexts)
Returns a copy with the contexts replaced.String
toString()
-
-
-
Field Detail
-
MARKDOWN
public static final GPTConfiguration MARKDOWN
-
HTML
public static final GPTConfiguration HTML
-
JSON
public static final GPTConfiguration JSON
-
CHAT
public static final GPTConfiguration CHAT
-
GENERATE
public static final GPTConfiguration GENERATE
-
NULLCFG
public static final GPTConfiguration NULLCFG
-
HIGH_INTELLIGENCE
public static final GPTConfiguration HIGH_INTELLIGENCE
Requests slower and more expensive "high intelligence" model - use sparingly.
-
STANDARD_INTELLIGENCE
public static final GPTConfiguration STANDARD_INTELLIGENCE
Requests faster and less expensive "normal intelligence" model.
-
DEBUG
public static final GPTConfiguration DEBUG
If set, the AI services will not call the AI but return the JSON request as response, for debugging purposes.
-
-
Constructor Detail
-
GPTConfiguration
public GPTConfiguration(@Nullable String apiKey, @Nullable String organizationId, @Nullable GPTConfiguration.AnswerType answerType)
-
GPTConfiguration
public GPTConfiguration(@Nullable String apiKey, @Nullable String organizationId, @Nullable GPTConfiguration.AnswerType answerType, @Nullable String additionalInstructions)
-
GPTConfiguration
public GPTConfiguration(@Nullable String apiKey, @Nullable String organizationId, @Nullable GPTConfiguration.AnswerType answerType, @Nullable String additionalInstructions, @Nullable GPTConfiguration.Mode mode)
-
GPTConfiguration
public GPTConfiguration(@Nullable String apiKey, @Nullable String organizationId, @Nullable GPTConfiguration.AnswerType answerType, @Nullable String additionalInstructions, @Nullable GPTConfiguration.Mode mode, @Nullable Boolean highIntelligenceNeeded)
-
GPTConfiguration
public GPTConfiguration(@Nullable String apiKey, @Nullable String organizationId, @Nullable GPTConfiguration.AnswerType answerType, @Nullable String additionalInstructions, @Nullable GPTConfiguration.Mode mode, @Nullable Boolean highIntelligenceNeeded, @Nullable Boolean debug)
-
GPTConfiguration
public GPTConfiguration(@Nullable String apiKey, @Nullable String organizationId, @Nullable GPTConfiguration.AnswerType answerType, @Nullable String additionalInstructions, @Nullable GPTConfiguration.Mode mode, @Nullable Boolean highIntelligenceNeeded, @Nullable Boolean debug, @Nullable Double temperature)
-
GPTConfiguration
public GPTConfiguration(@Nullable String apiKey, @Nullable String organizationId, @Nullable GPTConfiguration.AnswerType answerType, @Nullable String additionalInstructions, @Nullable GPTConfiguration.Mode mode, @Nullable Boolean highIntelligenceNeeded, @Nullable Boolean debug, @Nullable Double temperature, @Nullable Integer seed)
-
GPTConfiguration
public GPTConfiguration(@Nullable String apiKey, @Nullable String organizationId, @Nullable GPTConfiguration.AnswerType answerType, @Nullable String additionalInstructions, @Nullable GPTConfiguration.Mode mode, @Nullable Boolean highIntelligenceNeeded, @Nullable Boolean debug, @Nullable Double temperature, @Nullable Integer seed, @Nullable List<GPTConfiguration.GPTContextInfo> contexts)
-
GPTConfiguration
public GPTConfiguration(@Nullable String apiKey, @Nullable String organizationId, @Nullable GPTConfiguration.AnswerType answerType, @Nullable String additionalInstructions, @Nullable GPTConfiguration.Mode mode, @Nullable Boolean highIntelligenceNeeded, @Nullable Boolean debug, @Nullable Double temperature, @Nullable Integer seed, @Nullable List<GPTConfiguration.GPTContextInfo> contexts, List<GPTTool> tools)
-
-
Method Detail
-
getApiKey
public String getApiKey()
The API key to use with ChatGPT or another service. If this isnot set, we will try to fall back to global configurations.
-
getOrganizationId
public String getOrganizationId()
The organization id to use with ChatGPT. If this is not set, we will try to fall back to global configurations.
-
getAnswerType
public GPTConfiguration.AnswerType getAnswerType()
The type of answer we want from the LLM.
-
getAdditionalInstructions
public String getAdditionalInstructions()
Optionally, additional instructions to add to the system prompt.
-
isHtml
public boolean isHtml()
-
getMode
public GPTConfiguration.Mode getMode()
-
highIntelligenceNeededIsSet
public boolean highIntelligenceNeededIsSet()
If true, this requires to uses the slower and more expensive high intelligence model - use sparingly for more challenging tasks.
-
highIntelligenceNeededIsUnset
public boolean highIntelligenceNeededIsUnset()
If true, there is no information whether a "high intelligence model" is used - uses the default.
-
getDebug
public Boolean getDebug()
If this is set, then the services will not call the AI and return the JSON request instead of the AI response.
-
getTemperature
public Double getTemperature()
The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
-
getSeed
public Integer getSeed()
If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend. Beta feature of OpenAI.
-
merge
public GPTConfiguration merge(@Nullable GPTConfiguration other) throws IllegalArgumentException
Creates a configuration that joins the values.- Throws:
IllegalArgumentException
- if values conflict - that's checked for apiKey and organizationId and answerType.
-
merge
public GPTConfiguration merge(@Nullable GPTConfiguration other, boolean override) throws IllegalArgumentException
Creates a configuration that joins the values.- Parameters:
override
- if true, values set in this configuration will override values set in the other configuration. Otherwise, a conflict will throw an exception.other
- the other configuration to merge with (optional)- Returns:
- a new configuration
- Throws:
IllegalArgumentException
- if values conflict
-
getContexts
public List<GPTConfiguration.GPTContextInfo> getContexts()
Additional context information to provide to the AI. Not actual instructions, just background information.
-
replaceContexts
public GPTConfiguration replaceContexts(List<GPTConfiguration.GPTContextInfo> newContexts)
Returns a copy with the contexts replaced.
-
merge
@Nullable public static GPTConfiguration merge(@Nullable GPTConfiguration first, @Nullable GPTConfiguration second)
merge(GPTConfiguration)
several configurations.
-
ofRichText
@Nonnull public static GPTConfiguration ofRichText(boolean richText)
-
ofAdditionalInstructions
@Nonnull public static GPTConfiguration ofAdditionalInstructions(@Nullable String additionalInstructions)
-
ofContexts
@Nonnull public static GPTConfiguration ofContexts(@Nullable List<GPTConfiguration.GPTContextInfo> contexts)
-
ofContext
@Nonnull public static GPTConfiguration ofContext(@Nonnull String usermsg, @Nonnull String assistantmsg)
-
ofTools
@Nonnull public static GPTConfiguration ofTools(@Nullable List<GPTTool> tools)
-
ofTemperature
public static GPTConfiguration ofTemperature(Double temperature)
-
-