@@ -10,8 +10,8 @@ import {
10
10
refsToMarkdown ,
11
11
} from "../context" ;
12
12
import { JobManager } from "../../config" ;
13
- import { DB2_SYSTEM_PROMPT } from "../continue/ prompts" ;
14
- import Configuration from "../../configuration " ;
13
+ import { DB2_SYSTEM_PROMPT } from "../prompts" ;
14
+ import { buildPrompt , Db2ContextItems } from "../prompt " ;
15
15
16
16
const CHAT_ID = `vscode-db2i.chat` ;
17
17
@@ -58,107 +58,85 @@ export function activateChat(context: vscode.ExtensionContext) {
58
58
token : vscode . CancellationToken
59
59
) : Promise < IDB2ChatResult > => {
60
60
const copilotFamily = request . model . family ;
61
- let messages : vscode . LanguageModelChatMessage [ ] = [ ] ;
62
61
63
62
if ( canTalkToDb ( ) ) {
64
- // 1. SCHEMA Definiton (semantic)
65
- let usingSchema = getCurrentSchema ( ) ;
66
-
67
- const useSchemaDef : boolean = Configuration . get < boolean > ( `ai.useSchemaDefinition` ) ;
68
- if ( useSchemaDef ) {
69
- const schemaSemantic = await buildSchemaDefinition ( usingSchema ) ;
70
- if ( schemaSemantic ) {
71
- messages . push (
72
- vscode . LanguageModelChatMessage . Assistant (
73
- JSON . stringify ( schemaSemantic )
74
- )
75
- ) ;
76
- }
77
- }
78
-
79
63
switch ( request . command ) {
80
- case `activity` :
81
- stream . progress ( `Grabbing Information about IBM i system` ) ;
82
- const data = await getSystemStatus ( ) ;
83
- console . log (
84
- `summarize the following data in a readable paragraph: ${ data } `
85
- ) ;
86
- messages = [
87
- vscode . LanguageModelChatMessage . User (
88
- `You are a an IBM i savant speciallizing in database features in Db2 for i. Please provide a summary of the current IBM i system state based on the developer requirement.`
89
- ) ,
90
- vscode . LanguageModelChatMessage . User (
91
- `Here is the current IBM i state: ${ data } `
92
- ) ,
93
- vscode . LanguageModelChatMessage . User ( request . prompt ) ,
94
- ] ;
95
-
96
- await copilotRequest ( copilotFamily , messages , { } , token , stream ) ;
97
-
98
- return { metadata : { command : "activity" } } ;
99
-
100
- case `set-schema` :
101
- stream . progress ( `Setting Current Schema for SQL Job` ) ;
102
- const newSchema = request . prompt . split ( " " ) [ 0 ] ;
103
- if ( newSchema ) {
104
- const curJob = JobManager . getSelection ( ) ;
105
- if ( curJob ) {
106
- const result = await curJob . job . setCurrentSchema ( newSchema ) ;
107
- if ( result ) {
108
- stream . progress ( `Set Current Schema: ${ newSchema } ✅` ) ;
109
- usingSchema = newSchema ;
110
- }
111
- }
112
- return ;
113
- }
64
+ // case `activity`: //TODO: remove
65
+ // stream.progress(`Grabbing Information about IBM i system`);
66
+ // const data = await getSystemStatus();
67
+ // console.log(
68
+ // `summarize the following data in a readable paragraph: ${data}`
69
+ // );
70
+ // messages = [
71
+ // vscode.LanguageModelChatMessage.User(
72
+ // `You are a an IBM i savant speciallizing in database features in Db2 for i. Please provide a summary of the current IBM i system state based on the developer requirement.`
73
+ // ),
74
+ // vscode.LanguageModelChatMessage.User(
75
+ // `Here is the current IBM i state: ${data}`
76
+ // ),
77
+ // vscode.LanguageModelChatMessage.User(request.prompt),
78
+ // ];
79
+
80
+ // await copilotRequest(copilotFamily, messages, {}, token, stream);
81
+
82
+ // return { metadata: { command: "activity" } };
83
+
84
+ // case `set-schema`:
85
+ // stream.progress(`Setting Current Schema for SQL Job`);
86
+ // const newSchema = request.prompt.split(" ")[0];
87
+ // if (newSchema) {
88
+ // const curJob = JobManager.getSelection();
89
+ // if (curJob) {
90
+ // const result = await curJob.job.setCurrentSchema(newSchema);
91
+ // if (result) {
92
+ // stream.progress(`Set Current Schema: ${newSchema}✅`);
93
+ // usingSchema = newSchema;
94
+ // }
95
+ // }
96
+ // return;
97
+ // }
114
98
115
99
default :
116
- stream . progress (
117
- `Getting information from ${ Statement . prettyName ( usingSchema ) } ...`
118
- ) ;
119
-
120
- // 2. TABLE References
121
- let refs = await generateTableDefinition (
122
- usingSchema ,
123
- request . prompt . split ( ` ` )
124
- ) ;
100
+ stream . progress ( `Building response...` ) ;
125
101
126
102
// get history
103
+ let history : Db2ContextItems [ ] | undefined ;
127
104
if ( context . history . length > 0 ) {
128
- const historyMessages = context . history . map ( ( h ) => {
105
+ history = context . history . map ( ( h ) => {
129
106
if ( "prompt" in h ) {
130
- return vscode . LanguageModelChatMessage . Assistant ( h . prompt ) ;
107
+ return {
108
+ name : `reply` ,
109
+ description : `reply from Copilot` ,
110
+ content : h . prompt ,
111
+ type : `assistant` ,
112
+ } ;
131
113
} else {
132
114
const responseContent = h . response
133
115
. filter ( ( r ) => r . value instanceof vscode . MarkdownString )
134
116
. map ( ( r ) => ( r . value as vscode . MarkdownString ) . value )
135
117
. join ( "\n\n" ) ;
136
- return vscode . LanguageModelChatMessage . Assistant (
137
- responseContent
138
- ) ;
118
+ return {
119
+ name : `message` ,
120
+ description : `message from user` ,
121
+ content : responseContent ,
122
+ type : `assistant` ,
123
+ } ;
139
124
}
140
125
} ) ;
141
- messages . push ( ...historyMessages ) ;
142
126
}
143
127
144
- // add table refs to messages
145
- if ( Object . keys ( refs ) . length > 0 ) {
146
- for ( const tableRef of refs ) {
147
- messages . push (
148
- vscode . LanguageModelChatMessage . Assistant ( tableRef . content )
149
- ) ;
150
- }
151
- }
128
+ const contextItems = await buildPrompt ( request . prompt , {
129
+ history,
130
+ progress : stream . progress
131
+ } ) ;
152
132
153
- // 3. DB2 Guidelines
154
- messages . push (
155
- vscode . LanguageModelChatMessage . Assistant ( DB2_SYSTEM_PROMPT )
156
- ) ;
157
-
158
- stream . progress ( `Building response...` ) ;
159
-
160
- // 4. user prompt
161
- messages . push ( vscode . LanguageModelChatMessage . User ( request . prompt ) ) ;
133
+ const messages = contextItems . map ( c => {
134
+ if ( c . type === `user` ) {
135
+ return vscode . LanguageModelChatMessage . User ( c . content ) ;
136
+ } else {
137
+ return vscode . LanguageModelChatMessage . Assistant ( c . content ) ;
138
+ }
139
+ } ) ;
162
140
163
141
await copilotRequest (
164
142
request . model . family ,
0 commit comments