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_URLFields inherited from interface sk.iway.iwcm.components.ai.providers.AiInterface
GENERATE_FILE_NAME_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintaddUsageAndReturnTotal(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.HttpRequestBasegetImageResponseRequest(String instructions, InputDataDTO inputData, AssistantDefinitionEntity assistant, javax.servlet.http.HttpServletRequest request, Prop prop) com.fasterxml.jackson.databind.node.ArrayNodegetImages(com.fasterxml.jackson.databind.JsonNode jsonNodeRes) org.apache.http.client.methods.HttpRequestBasegetModelsRequest(javax.servlet.http.HttpServletRequest request) org.apache.http.client.methods.HttpRequestBasegetResponseRequest(String instructions, InputDataDTO inputData, AssistantDefinitionEntity assistant, javax.servlet.http.HttpServletRequest request) org.apache.http.client.methods.HttpRequestBasegetStremResponseRequest(String instructions, InputDataDTO inputData, AssistantDefinitionEntity assistant, javax.servlet.http.HttpServletRequest request) handleBufferedReader(BufferedReader reader, BufferedWriter writer, Map<Integer, String> replacedIncludes) booleanisInit()Methods inherited from class sk.iway.iwcm.components.ai.providers.openai.OpenAiSupportService
addHeaders, addImageInput, addInput, getApiKey, getBaseMainObject, getBaseMainObjectWithImage, getImageQualitySelect, getImageSizeSelectMethods inherited from class sk.iway.iwcm.components.ai.providers.SupportLogic
getAiImageResponse, getAiResponse, getAiStreamResponse, getSupportedModels, handleErrorMessageMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface sk.iway.iwcm.components.ai.providers.AiInterface
getAiImageResponse, getAiResponse, getAiStreamResponse, getRequestBody, getSupportedModelsMethods inherited from interface sk.iway.iwcm.components.ai.providers.SupportLogicInterface
getStreamEncoding
-
Constructor Details
-
OpenAiService
public OpenAiService()
-
-
Method Details
-
getProviderId
- Specified by:
getProviderIdin interfaceAiInterface
-
getServiceName
- Specified by:
getServiceNamein interfaceSupportLogicInterface
-
getTitleKey
- Specified by:
getTitleKeyin interfaceAiInterface
-
isInit
public boolean isInit()- Specified by:
isInitin interfaceAiInterface
-
addUsageAndReturnTotal
public int addUsageAndReturnTotal(StringBuilder sb, int addTokens, com.fasterxml.jackson.databind.JsonNode root) - Specified by:
addUsageAndReturnTotalin interfaceSupportLogicInterface
-
getModelsRequest
public org.apache.http.client.methods.HttpRequestBase getModelsRequest(javax.servlet.http.HttpServletRequest request) - Specified by:
getModelsRequestin interfaceSupportLogicInterface
-
extractModels
- Specified by:
extractModelsin interfaceSupportLogicInterface
-
getResponseRequest
public org.apache.http.client.methods.HttpRequestBase getResponseRequest(String instructions, InputDataDTO inputData, AssistantDefinitionEntity assistant, javax.servlet.http.HttpServletRequest request) throws IOException - Specified by:
getResponseRequestin interfaceSupportLogicInterface- Throws:
IOException
-
extractResponseText
- Specified by:
extractResponseTextin interfaceSupportLogicInterface
-
getStremResponseRequest
public org.apache.http.client.methods.HttpRequestBase getStremResponseRequest(String instructions, InputDataDTO inputData, AssistantDefinitionEntity assistant, javax.servlet.http.HttpServletRequest request) throws IOException - Specified by:
getStremResponseRequestin interfaceSupportLogicInterface- Throws:
IOException
-
handleBufferedReader
public Pair<String,com.fasterxml.jackson.databind.JsonNode> handleBufferedReader(BufferedReader reader, BufferedWriter writer, Map<Integer, String> replacedIncludes) throws IOException- Specified by:
handleBufferedReaderin 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:
getImageResponseRequestin interfaceSupportLogicInterface- Throws:
IOException
-
getFinishError
- Specified by:
getFinishErrorin interfaceSupportLogicInterface
-
getImages
public com.fasterxml.jackson.databind.node.ArrayNode getImages(com.fasterxml.jackson.databind.JsonNode jsonNodeRes) - Specified by:
getImagesin interfaceSupportLogicInterface
-
getImageFormat
public String getImageFormat(com.fasterxml.jackson.databind.JsonNode jsonNodeRes, com.fasterxml.jackson.databind.JsonNode jsonImage) - Specified by:
getImageFormatin interfaceSupportLogicInterface
-
getImageBase64
public String getImageBase64(com.fasterxml.jackson.databind.JsonNode jsonNodeRes, com.fasterxml.jackson.databind.JsonNode jsonImage) - Specified by:
getImageBase64in interfaceSupportLogicInterface
-
getModelForImageNameGeneration
- Specified by:
getModelForImageNameGenerationin interfaceSupportLogicInterface
-
getBonusHtml
- Specified by:
getBonusHtmlin interfaceAiInterface
-