Skip to content

Commit b444091

Browse files
authored
✨AI Column: [Part 1] New properties (aiIntegration, prompt, mode) (DevExpress#31219)
1 parent 86d282f commit b444091

File tree

11 files changed

+632
-18
lines changed

11 files changed

+632
-18
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { GenerateGridColumnCommandParams, GenerateGridColumnCommandResult } from '@js/common/ai-integration';
2+
import { BaseCommand } from '@ts/core/ai_integration/commands/base';
3+
import type { PromptData, PromptTemplateName } from '@ts/core/ai_integration/core/prompt_manager';
4+
5+
export class GenerateGridColumnCommand extends BaseCommand<
6+
GenerateGridColumnCommandParams,
7+
GenerateGridColumnCommandResult
8+
> {
9+
protected getTemplateName(): PromptTemplateName {
10+
return 'generateColumn';
11+
}
12+
13+
protected buildPromptData(params: GenerateGridColumnCommandParams): PromptData {
14+
const dataDescription = this.generateDataDescription(params.data);
15+
return {
16+
user: {
17+
text: params.text,
18+
data: dataDescription,
19+
},
20+
};
21+
}
22+
23+
protected parseResult(response: string): GenerateGridColumnCommandResult {
24+
const result: GenerateGridColumnCommandResult = JSON.parse(response);
25+
return result;
26+
}
27+
28+
private generateDataDescription(data: Record<PropertyKey, unknown>): string {
29+
const result = JSON.stringify(data);
30+
return result;
31+
}
32+
}

packages/devextreme/js/__internal/core/ai_integration/core/ai_integration.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type {
99
ExecuteCommandResult,
1010
ExpandCommandParams,
1111
ExpandCommandResult,
12+
GenerateGridColumnCommandParams,
13+
GenerateGridColumnCommandResult,
1214
ProofreadCommandParams,
1315
ProofreadCommandResult,
1416
RequestCallbacks,
@@ -36,6 +38,8 @@ import {
3638
import { PromptManager } from '@ts/core/ai_integration/core/prompt_manager';
3739
import { RequestManager } from '@ts/core/ai_integration/core/request_manager';
3840

41+
import { GenerateGridColumnCommand } from '../commands/generateGridColumn';
42+
3943
export const enum CommandNames {
4044
ChangeStyle = 'changeStyle',
4145
ChangeTone = 'changeTone',
@@ -46,6 +50,7 @@ export const enum CommandNames {
4650
Summarize = 'summarize',
4751
Translate = 'translate',
4852
SmartPaste = 'smartPaste',
53+
GenerateGridColumn = 'generateGridColumn',
4954
}
5055

5156
export const COMMANDS = {
@@ -58,6 +63,7 @@ export const COMMANDS = {
5863
[CommandNames.Summarize]: SummarizeCommand,
5964
[CommandNames.Translate]: TranslateCommand,
6065
[CommandNames.SmartPaste]: SmartPasteCommand,
66+
[CommandNames.GenerateGridColumn]: GenerateGridColumnCommand,
6167
} as const;
6268

6369
export interface CommandDefinition<TParams, TResult> {
@@ -76,6 +82,10 @@ export interface Commands {
7682
[CommandNames.Summarize]: CommandDefinition<SummarizeCommandParams, SummarizeCommandResult>;
7783
[CommandNames.Translate]: CommandDefinition<TranslateCommandParams, TranslateCommandResult>;
7884
[CommandNames.SmartPaste]: CommandDefinition<SmartPasteCommandParams, SmartPasteCommandResult>;
85+
[CommandNames.GenerateGridColumn]: CommandDefinition<
86+
GenerateGridColumnCommandParams,
87+
GenerateGridColumnCommandResult
88+
>;
7989
}
8090

8191
export class AIIntegration implements IAIIntegration {
@@ -210,4 +220,15 @@ export class AIIntegration implements IAIIntegration {
210220
callbacks,
211221
);
212222
}
223+
224+
public generateGridColumn(
225+
params: GenerateGridColumnCommandParams,
226+
callbacks: RequestCallbacks<GenerateGridColumnCommandResult>,
227+
): () => void {
228+
return this.executeCommand(
229+
CommandNames.GenerateGridColumn,
230+
params,
231+
callbacks,
232+
);
233+
}
213234
}

packages/devextreme/js/__internal/core/ai_integration/core/prompt_manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export type PromptTemplateName =
2020
| 'shorten'
2121
| 'summarize'
2222
| 'translate'
23-
| 'smartPaste';
23+
| 'smartPaste'
24+
| 'generateColumn';
2425

2526
export type PromptTemplates = Map<PromptTemplateName, PromptTemplate>;
2627

packages/devextreme/js/__internal/core/ai_integration/templates/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ export const templates: PromptTemplates = {
3131
system: 'You are a helpful assistant that helps to fill fields based on the text provided. You will get a text and a list of fields that should be filled using info from the text. It can include the name of field, suitable format, optionally some additional instruction about what it should include. You need to return data for all the fields in the following format without any preamble, introduction, or explanatory text: {fieldName}:::{fieldValue};;;{fieldName}:::{fieldValue} and so on, where {fieldName} - is a variable for a field name and {fieldValue} - is a variable for a string to fill. If there is no info to fill, field value should be empty (like Name:::;;;)- do not use placeholders like (empty), N/A, null, or similar. Only fill in date fields if a complete date is explicitly present. If the date is missing or incomplete, leave the field empty.',
3232
user: 'Text: {{text}}. Fields: {{fields}}.',
3333
},
34+
generateColumn: {
35+
system: 'You are a helpful assistant that generates column data based on the provided text and existing data context. Generate appropriate column values that match the request and are consistent with the existing data structure.',
36+
user: 'Text: {{text}}. Data: {{data}}.',
37+
},
3438
};

0 commit comments

Comments
 (0)