Package io.jmix.aitools.dataload.impl
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 Summary
FieldsModifier and TypeFieldDescriptionprotected AiToolRegistryprotected @Nullable org.springframework.ai.chat.client.ChatClientprotected ChatClientFactoryprotected EntityDataLoadGenerationServiceprotected JpqlExecutionServiceprotected ResponseLanguageProviderprotected DataLoadChatSystemPromptProvider -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidprotected org.springframework.ai.chat.client.ChatClient.ChatClientRequestSpecbuildChatClientPrompt(String message) protected voidGenerates 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.protected EntityDataLoadQueryresolveProcessedQuery(EntityDataLoadQuery generatedQuery, JpqlExecutionResult executionResult) Returns the query that the result's rows and validation result belong to.protected String@Nullable StringSends a stateless message to the data-load chat and blocks until the full reply is produced.reactor.core.publisher.Flux<String> Streams a stateless reply to the data-load chat as a flux of text chunks.protected List<JpqlExecutionParameter> toExecutionParameters(List<GeneratedJpqlParameter> generatedParameters)
-
Field Details
-
chatClientFactory
-
systemPromptProvider
-
aiToolRegistry
-
responseLanguageProvider
-
entityDataLoadGenerationService
-
jpqlExecutionService
-
chatClient
protected @Nullable org.springframework.ai.chat.client.ChatClient chatClient
-
-
Constructor Details
-
AiDataLoadServiceImpl
public AiDataLoadServiceImpl()
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
send
Description copied from interface:AiDataLoadServiceSends a stateless message to the data-load chat and blocks until the full reply is produced. Chat history is not persisted.- Specified by:
sendin interfaceAiDataLoadService- Parameters:
message- user message in natural language- Returns:
- natural-language reply from the LLM
-
stream
Description copied from interface:AiDataLoadServiceStreams a stateless reply to the data-load chat as a flux of text chunks. Chat history is not persisted.- Specified by:
streamin interfaceAiDataLoadService- Parameters:
message- user message in natural language- Returns:
- flux emitting reply chunks in order
-
loadData
Description copied from interface:AiDataLoadServiceGenerates 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:
loadDatain interfaceAiDataLoadService- 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 requestexecutionResult- 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
-
checkChatClient
protected void checkChatClient() -
toExecutionParameters
protected List<JpqlExecutionParameter> toExecutionParameters(List<GeneratedJpqlParameter> generatedParameters)
-