Class OpenAiService
java.lang.Object
sk.iway.iwcm.components.ai.providers.SupportLogic
sk.iway.iwcm.components.ai.providers.openai.OpenAiSupportService
sk.iway.iwcm.components.ai.providers.openai.OpenAiService
- All Implemented Interfaces:
AiInterface
,SupportLogicInterface
Service for OpenAI assistants - handles calls to OpenAI API
We do not use any official SDK, but rather direct REST calls, so its easy to maintain and we can see what is going on.
docs: https://platform.openai.com/docs/api-reference
-
Nested Class Summary
Nested classes/interfaces inherited from class sk.iway.iwcm.components.ai.providers.openai.OpenAiSupportService
OpenAiSupportService.ASSISTANT_FIELDS
-
Field Summary
Fields inherited from class sk.iway.iwcm.components.ai.providers.openai.OpenAiSupportService
IMAGES_EDITS_URL, IMAGES_GENERATION_URL, MODELS_URL, OUTPUT, RESPONSES_URL
Fields inherited from class sk.iway.iwcm.components.ai.providers.SupportLogic
AUDIT_AI_RESPONSE_KEY
Fields inherited from interface sk.iway.iwcm.components.ai.providers.AiInterface
GENERATE_FILE_NAME_KEY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
addUsageAndReturnTotal
(StringBuilder sb, int addTokens, com.fasterxml.jackson.databind.JsonNode root) extractModels
(com.fasterxml.jackson.databind.JsonNode root) extractResponseText
(com.fasterxml.jackson.databind.JsonNode jsonNodeRes) getBonusHtml
(AssistantDefinitionEntity assistant, Prop prop) getFinishError
(com.fasterxml.jackson.databind.JsonNode jsonNodeRes) getImageBase64
(com.fasterxml.jackson.databind.JsonNode jsonNodeRes, com.fasterxml.jackson.databind.JsonNode jsonImage) getImageFormat
(com.fasterxml.jackson.databind.JsonNode jsonNodeRes, com.fasterxml.jackson.databind.JsonNode jsonImage) org.apache.http.client.methods.HttpRequestBase
getImageResponseRequest
(String instructions, InputDataDTO inputData, AssistantDefinitionEntity assistant, javax.servlet.http.HttpServletRequest request, Prop prop) com.fasterxml.jackson.databind.node.ArrayNode
getImages
(com.fasterxml.jackson.databind.JsonNode jsonNodeRes) org.apache.http.client.methods.HttpRequestBase
getModelsRequest
(javax.servlet.http.HttpServletRequest request) org.apache.http.client.methods.HttpRequestBase
getResponseRequest
(String instructions, InputDataDTO inputData, AssistantDefinitionEntity assistant, javax.servlet.http.HttpServletRequest request) org.apache.http.client.methods.HttpRequestBase
getStremResponseRequest
(String instructions, InputDataDTO inputData, AssistantDefinitionEntity assistant, javax.servlet.http.HttpServletRequest request) com.fasterxml.jackson.databind.JsonNode
handleBufferedReader
(BufferedReader reader, BufferedWriter writer, Map<Integer, String> replacedIncludes) boolean
isInit()
Methods inherited from class sk.iway.iwcm.components.ai.providers.openai.OpenAiSupportService
addHeaders, addInput, getApiKey, getBaseMainObject, getImageQualitySelect, getImageSizeSelect
Methods inherited from class sk.iway.iwcm.components.ai.providers.SupportLogic
getAiImageResponse, getAiResponse, getAiStreamResponse, getSupportedModels, handleErrorMessage, handleErrorMessage
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface sk.iway.iwcm.components.ai.providers.AiInterface
getAiImageResponse, getAiResponse, getAiStreamResponse, getRequestBody, getSupportedModels
Methods inherited from interface sk.iway.iwcm.components.ai.providers.SupportLogicInterface
getStreamEncoding
-
Constructor Details
-
OpenAiService
public OpenAiService()
-
-
Method Details
-
getProviderId
- Specified by:
getProviderId
in interfaceAiInterface
-
getServiceName
- Specified by:
getServiceName
in interfaceSupportLogicInterface
-
getTitleKey
- Specified by:
getTitleKey
in interfaceAiInterface
-
isInit
public boolean isInit()- Specified by:
isInit
in interfaceAiInterface
-
addUsageAndReturnTotal
public int addUsageAndReturnTotal(StringBuilder sb, int addTokens, com.fasterxml.jackson.databind.JsonNode root) - Specified by:
addUsageAndReturnTotal
in interfaceSupportLogicInterface
-
getModelsRequest
public org.apache.http.client.methods.HttpRequestBase getModelsRequest(javax.servlet.http.HttpServletRequest request) - Specified by:
getModelsRequest
in interfaceSupportLogicInterface
-
extractModels
- Specified by:
extractModels
in interfaceSupportLogicInterface
-
getResponseRequest
public org.apache.http.client.methods.HttpRequestBase getResponseRequest(String instructions, InputDataDTO inputData, AssistantDefinitionEntity assistant, javax.servlet.http.HttpServletRequest request) - Specified by:
getResponseRequest
in interfaceSupportLogicInterface
-
extractResponseText
- Specified by:
extractResponseText
in interfaceSupportLogicInterface
-
getStremResponseRequest
public org.apache.http.client.methods.HttpRequestBase getStremResponseRequest(String instructions, InputDataDTO inputData, AssistantDefinitionEntity assistant, javax.servlet.http.HttpServletRequest request) - Specified by:
getStremResponseRequest
in interfaceSupportLogicInterface
-
handleBufferedReader
public com.fasterxml.jackson.databind.JsonNode handleBufferedReader(BufferedReader reader, BufferedWriter writer, Map<Integer, String> replacedIncludes) throws IOException- Specified by:
handleBufferedReader
in interfaceSupportLogicInterface
- Throws:
IOException
-
getImageResponseRequest
public org.apache.http.client.methods.HttpRequestBase getImageResponseRequest(String instructions, InputDataDTO inputData, AssistantDefinitionEntity assistant, javax.servlet.http.HttpServletRequest request, Prop prop) throws IOException - Specified by:
getImageResponseRequest
in interfaceSupportLogicInterface
- Throws:
IOException
-
getFinishError
- Specified by:
getFinishError
in interfaceSupportLogicInterface
-
getImages
public com.fasterxml.jackson.databind.node.ArrayNode getImages(com.fasterxml.jackson.databind.JsonNode jsonNodeRes) - Specified by:
getImages
in interfaceSupportLogicInterface
-
getImageFormat
public String getImageFormat(com.fasterxml.jackson.databind.JsonNode jsonNodeRes, com.fasterxml.jackson.databind.JsonNode jsonImage) - Specified by:
getImageFormat
in interfaceSupportLogicInterface
-
getImageBase64
public String getImageBase64(com.fasterxml.jackson.databind.JsonNode jsonNodeRes, com.fasterxml.jackson.databind.JsonNode jsonImage) - Specified by:
getImageBase64
in interfaceSupportLogicInterface
-
getModelForImageNameGeneration
- Specified by:
getModelForImageNameGeneration
in interfaceSupportLogicInterface
-
getBonusHtml
- Specified by:
getBonusHtml
in interfaceAiInterface
-