Class ChatGPTChatCompletionService

java.lang.Object
com.theokanning.openai.service.OpenAiService
com.vaadin.flow.ai.formfiller.services.ChatGPTChatCompletionService
All Implemented Interfaces:
LLMService

public class ChatGPTChatCompletionService extends com.theokanning.openai.service.OpenAiService implements LLMService
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Generates a response based on the input prompt from the AI module.
    getPromptTemplate(String input, Map<String,Object> objectMap, Map<String,String> typesMap, Map<com.vaadin.flow.component.Component,String> componentInstructions, List<String> contextInstructions)
    Generates a prompt based on the input, the target components and any extra instruction.

    Methods inherited from class com.theokanning.openai.service.OpenAiService

    billingUsage, buildApi, cancelFineTune, cancelFineTuningJob, createChatCompletion, createCompletion, createEdit, createEmbeddings, createFineTune, createFineTuneCompletion, createFineTuningJob, createImage, createImageEdit, createImageEdit, createImageVariation, createImageVariation, createModeration, createTranscription, createTranscription, createTranslation, createTranslation, defaultClient, defaultObjectMapper, defaultRetrofit, deleteFile, deleteFineTune, execute, getModel, listFiles, listFineTuneEvents, listFineTunes, listFineTuningJobEvents, listFineTuningJobs, listModels, mapStreamToAccumulator, retrieveFile, retrieveFineTune, retrieveFineTuningJob, shutdownExecutor, stream, stream, stream, streamChatCompletion, streamCompletion, subscription, uploadFile

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ChatGPTChatCompletionService

      public ChatGPTChatCompletionService()
  • Method Details

    • getPromptTemplate

      public String getPromptTemplate(String input, Map<String,Object> objectMap, Map<String,String> typesMap, Map<com.vaadin.flow.component.Component,String> componentInstructions, List<String> contextInstructions)
      Description copied from interface: LLMService
      Generates a prompt based on the input, the target components and any extra instruction.
      Specified by:
      getPromptTemplate in interface LLMService
      Parameters:
      input - the input text (e.g. "My name is John")
      objectMap - the objectMap containing the target components in a hierarchical structure (keys = ids)
      typesMap - the map containing the desired type to fill with each one of the target components (keys = ids)
      componentInstructions - the components (fields) instructions containing additional information to understand the field meaning.
      contextInstructions - the context instructions containing additional information to understand the input or providing some information not present in the input
      Returns:
      the generated prompt to be sent to the AI module
    • getGeneratedResponse

      public String getGeneratedResponse(String prompt)
      Description copied from interface: LLMService
      Generates a response based on the input prompt from the AI module.
      Specified by:
      getGeneratedResponse in interface LLMService
      Parameters:
      prompt - the prompt to be used by the AI module
      Returns:
      the generated response from the AI module. This response has to be a valid JSON Object using target field IDs as keys and the value correctly formatted according to the target component. An example is the following format:
      
           {
           "field Id 1": "value 1", // TextField
           "field Id 2": 66, // NumberField or IntegerField
           "field Id 3": "2022-04-03", // DatePicker
           "field Id 4 ": [ // Grid
                {
               "inner item id1": "Value 1",
               "inner item id2": "Value 2",
               "inner item id3": "Value 3"
                },
                {
               "inner item id1": "Value 1",
               "inner item id2": "Value 2",
               "inner item id3": "Value 3"
                }
       ],
       "field Id 5 ": ["Value 1", "Value 2"], // MultiSelectComboBox
       "field Id 6": true, // Checkbox
       "field Id 7": 43.47 // BigDecimalField
       }