Package com.composum.sling.nodes.ai.impl
Class AIServiceImpl
- java.lang.Object
-
- com.composum.sling.nodes.ai.impl.AIServiceImpl
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AIServiceImpl.Configuration
-
Nested classes/interfaces inherited from interface com.composum.sling.nodes.ai.AIService
AIService.AIServiceException, AIService.AIServiceNotAvailableException, AIService.ResponseFormat
-
-
Field Summary
Fields Modifier and Type Field Description protected String
additionalHeader
protected String
additionalHeaderValue
protected String
apiKey
protected String
apiKeyHeader
protected static String
CHAT_COMPLETION_URL
protected String
chatURL
protected AIServiceImpl.Configuration
config
static String
DEFAULT_MODEL
The default model - probably a GPT-4 is needed for complicated stuff like JCR queries.protected com.google.gson.Gson
gson
protected org.apache.http.impl.client.CloseableHttpClient
httpClient
protected static org.slf4j.Logger
LOG
protected RateLimiter
rateLimiter
static String
SERVICE_NAME
-
Constructor Summary
Constructors Constructor Description AIServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
activate(AIServiceImpl.Configuration configuration)
protected void
deactivate()
protected @NotNull String
extractText(String responseJson)
protected boolean
isAnthropicClaude()
boolean
isAvailable()
Whether the service is configured.String
prompt(String systemmsg, String usermsg, AIService.ResponseFormat responseFormat)
Simplest AI related service: execute a prompt and return the response of the AI.protected String
retrieveMessage(String id, org.apache.http.client.methods.CloseableHttpResponse response)
-
-
-
Field Detail
-
SERVICE_NAME
public static final String SERVICE_NAME
- See Also:
- Constant Field Values
-
LOG
protected static final org.slf4j.Logger LOG
-
DEFAULT_MODEL
public static final String DEFAULT_MODEL
The default model - probably a GPT-4 is needed for complicated stuff like JCR queries.- See Also:
- Constant Field Values
-
CHAT_COMPLETION_URL
protected static final String CHAT_COMPLETION_URL
- See Also:
- Constant Field Values
-
config
protected AIServiceImpl.Configuration config
-
apiKey
protected String apiKey
-
rateLimiter
protected RateLimiter rateLimiter
-
gson
protected com.google.gson.Gson gson
-
httpClient
protected org.apache.http.impl.client.CloseableHttpClient httpClient
-
chatURL
protected String chatURL
-
apiKeyHeader
protected String apiKeyHeader
-
additionalHeader
protected String additionalHeader
-
additionalHeaderValue
protected String additionalHeaderValue
-
-
Method Detail
-
isAvailable
public boolean isAvailable()
Description copied from interface:AIService
Whether the service is configured.- Specified by:
isAvailable
in interfaceAIService
-
isAnthropicClaude
protected boolean isAnthropicClaude()
-
prompt
@Nonnull public String prompt(@Nullable String systemmsg, @Nonnull String usermsg, @Nullable AIService.ResponseFormat responseFormat) throws AIService.AIServiceException
Description copied from interface:AIService
Simplest AI related service: execute a prompt and return the response of the AI.- Specified by:
prompt
in interfaceAIService
- Parameters:
systemmsg
- a system prompt to be used in addition to the promptusermsg
- the prompt to be usedresponseFormat
- the format of the response, defaultAIService.ResponseFormat.TEXT
.- Returns:
- the response of the AI
- Throws:
AIService.AIServiceException
-
retrieveMessage
@Nonnull protected String retrieveMessage(String id, org.apache.http.client.methods.CloseableHttpResponse response) throws AIService.AIServiceException, IOException
-
extractText
@NotNull protected @NotNull String extractText(String responseJson) throws AIService.AIServiceException
- Throws:
AIService.AIServiceException
-
deactivate
protected void deactivate()
-
activate
protected void activate(AIServiceImpl.Configuration configuration)
-
-