@@ -19,9 +19,16 @@ export interface Db2ContextItems {
19
19
specific ?: "copilot" | "continue" ;
20
20
}
21
21
22
- export async function buildPrompt ( input : string , options : PromptOptions = { } ) : Promise < Db2ContextItems [ ] > {
22
+ export interface BuildResult {
23
+ context : Db2ContextItems [ ] ;
24
+ followUps : string [ ] ;
25
+ }
26
+
27
+ export async function buildPrompt ( input : string , options : PromptOptions = { } ) : Promise < BuildResult > {
23
28
const currentJob : JobInfo = JobManager . getSelection ( ) ;
29
+
24
30
let contextItems : Db2ContextItems [ ] = [ ] ;
31
+ let followUps = [ ] ;
25
32
26
33
const progress = ( message : string ) => {
27
34
if ( options . progress ) {
@@ -65,14 +72,32 @@ export async function buildPrompt(input: string, options: PromptOptions = {}): P
65
72
} ) ;
66
73
}
67
74
75
+ if ( context . refs . filter ( r => r . sqlType === `TABLE` ) . length >= 2 ) {
76
+ const randomIndexA = Math . floor ( Math . random ( ) * context . refs . length ) ;
77
+ const randomIndexB = Math . floor ( Math . random ( ) * context . refs . length ) ;
78
+ const tableA = context . refs [ randomIndexA ] . name ;
79
+ const tableB = context . refs [ randomIndexB ] . name ;
80
+
81
+ if ( tableA !== tableB ) {
82
+ followUps . push ( `How can I join ${ tableA } and ${ tableB } ?` ) ;
83
+ }
84
+ }
85
+
68
86
// If the user only requests one reference, then let's find related objects
69
87
if ( context . refs . length === 1 ) {
70
88
const ref = context . refs [ 0 ] ;
71
- progress ( `Finding objects related to ${ Statement . prettyName ( ref . name ) } ...` ) ;
89
+ const prettyNameRef = Statement . prettyName ( ref . name ) ;
90
+ progress ( `Finding objects related to ${ prettyNameRef } ...` ) ;
72
91
73
92
const relatedObjects = await Schemas . getRelatedObjects ( ref ) ;
74
93
const contentItems = await getContentItemsForRefs ( relatedObjects ) ;
75
94
95
+ if ( relatedObjects . length === 1 ) {
96
+ followUps . push ( `How is ${ prettyNameRef } related to ${ Statement . prettyName ( relatedObjects [ 0 ] . name ) } ?` ) ;
97
+ } else if ( ref . sqlType === `TABLE` ) {
98
+ followUps . push ( `What are some objects related to that table?` ) ;
99
+ }
100
+
76
101
for ( const sqlObj of contentItems ) {
77
102
contextItems . push ( {
78
103
name : `${ sqlObj . type . toLowerCase ( ) } definition for ${ sqlObj . id } ` ,
@@ -81,6 +106,12 @@ export async function buildPrompt(input: string, options: PromptOptions = {}): P
81
106
type : `assistant`
82
107
} ) ;
83
108
}
109
+
110
+ } else if ( context . refs . length > 1 ) {
111
+ const randomRef = context . refs [ Math . floor ( Math . random ( ) * context . refs . length ) ] ;
112
+ const prettyNameRef = Statement . prettyName ( randomRef . name ) ;
113
+
114
+ followUps . push ( `What are some objects related to ${ prettyNameRef } ?` ) ;
84
115
}
85
116
86
117
if ( ! options . history ) {
@@ -100,5 +131,8 @@ export async function buildPrompt(input: string, options: PromptOptions = {}): P
100
131
} ) ;
101
132
}
102
133
103
- return contextItems ;
134
+ return {
135
+ context : contextItems ,
136
+ followUps
137
+ } ;
104
138
}
0 commit comments