Class AiDataLoadServiceImpl

java.lang.Object
io.jmix.aitools.dataload.impl.AiDataLoadServiceImpl
All Implemented Interfaces:
AiDataLoadService, org.springframework.beans.factory.InitializingBean

@Component("aitls_AiDataLoadServiceImpl") public class AiDataLoadServiceImpl extends Object implements AiDataLoadService, org.springframework.beans.factory.InitializingBean
The default implementation of AiDataLoadService.

It uses DataLoadAiTool tools (entity discovery, JPQL execution, etc.) to get a valid JPQL query from LLM. This JPQL is validated and can be repaired if it is required.

See Also:
  • Field Details

  • Constructor Details

    • AiDataLoadServiceImpl

      public AiDataLoadServiceImpl()
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • send

      public @Nullable String send(String message)
      Description copied from interface: AiDataLoadService
      Sends a stateless message to the data-load chat and blocks until the full reply is produced. Chat history is not persisted.
      Specified by:
      send in interface AiDataLoadService
      Parameters:
      message - user message in natural language
      Returns:
      natural-language reply from the LLM
    • stream

      public reactor.core.publisher.Flux<String> stream(String message)
      Description copied from interface: AiDataLoadService
      Streams a stateless reply to the data-load chat as a flux of text chunks. Chat history is not persisted.
      Specified by:
      stream in interface AiDataLoadService
      Parameters:
      message - user message in natural language
      Returns:
      flux emitting reply chunks in order
    • loadData

      public EntityDataLoadResult loadData(String userText)
      Description copied from interface: AiDataLoadService
      Generates a JPQL query for the given natural-language request, executes it and returns the query that ran (or failed validation), its validation result and the fetched rows. Runs statelessly without persisting chat history.

      The query runs as the current user, so the rows hold only the records that user may see. A related record hidden from the user reads as an absent one: an empty reference does not prove that the data is missing.

      Specified by:
      loadData in interface AiDataLoadService
      Parameters:
      userText - user request in natural language
      Returns:
      result containing the executed query or the one that failed validation, its validation result and the fetched rows
    • resolveProcessedQuery

      protected EntityDataLoadQuery resolveProcessedQuery(EntityDataLoadQuery generatedQuery, JpqlExecutionResult executionResult)
      Returns the query that the result's rows and validation result belong to.
      Parameters:
      generatedQuery - query generated for the request
      executionResult - outcome of executing the generated query
      Returns:
      the generated query if no repair was attempted; otherwise the repaired query with the generated column names, which key the rows
    • buildChatClientPrompt

      protected org.springframework.ai.chat.client.ChatClient.ChatClientRequestSpec buildChatClientPrompt(String message)
    • buildChatClient

      protected void buildChatClient()
    • resolveResponseLanguage

      protected String resolveResponseLanguage()
    • checkChatClient

      protected void checkChatClient()
    • toExecutionParameters

      protected List<JpqlExecutionParameter> toExecutionParameters(List<GeneratedJpqlParameter> generatedParameters)