@proteinjs/conversation 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/.eslintrc.js +1 -1
  2. package/.prettierignore +4 -0
  3. package/CHANGELOG.md +11 -0
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +28 -40
  6. package/dist/src/CodegenConversation.d.ts +11 -11
  7. package/dist/src/CodegenConversation.js +180 -294
  8. package/dist/src/Conversation.d.ts +49 -52
  9. package/dist/src/Conversation.js +288 -478
  10. package/dist/src/ConversationModule.d.ts +6 -6
  11. package/dist/src/ConversationModule.js +3 -3
  12. package/dist/src/Function.d.ts +4 -4
  13. package/dist/src/Function.js +3 -3
  14. package/dist/src/OpenAi.d.ts +10 -42
  15. package/dist/src/OpenAi.js +305 -495
  16. package/dist/src/Paragraph.d.ts +4 -4
  17. package/dist/src/Paragraph.js +17 -17
  18. package/dist/src/Sentence.d.ts +4 -4
  19. package/dist/src/Sentence.js +21 -21
  20. package/dist/src/code_template/Code.d.ts +15 -15
  21. package/dist/src/code_template/Code.js +73 -167
  22. package/dist/src/code_template/CodeTemplate.d.ts +11 -11
  23. package/dist/src/code_template/CodeTemplate.js +80 -169
  24. package/dist/src/code_template/CodeTemplateModule.d.ts +6 -6
  25. package/dist/src/code_template/CodeTemplateModule.js +26 -28
  26. package/dist/src/code_template/Repo.d.ts +38 -34
  27. package/dist/src/code_template/Repo.js +195 -291
  28. package/dist/src/fs/conversation_fs/ConversationFsModerator.d.ts +12 -12
  29. package/dist/src/fs/conversation_fs/ConversationFsModerator.js +108 -110
  30. package/dist/src/fs/conversation_fs/ConversationFsModule.d.ts +11 -11
  31. package/dist/src/fs/conversation_fs/ConversationFsModule.js +97 -204
  32. package/dist/src/fs/conversation_fs/FsFunctions.d.ts +62 -58
  33. package/dist/src/fs/conversation_fs/FsFunctions.js +252 -414
  34. package/dist/src/fs/git/GitModule.d.ts +8 -8
  35. package/dist/src/fs/git/GitModule.js +74 -163
  36. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.d.ts +18 -16
  37. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.js +58 -158
  38. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.d.ts +26 -27
  39. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js +131 -234
  40. package/dist/src/fs/package/PackageFunctions.d.ts +60 -54
  41. package/dist/src/fs/package/PackageFunctions.js +213 -366
  42. package/dist/src/fs/package/PackageModule.d.ts +24 -24
  43. package/dist/src/fs/package/PackageModule.js +170 -292
  44. package/dist/src/history/MessageHistory.d.ts +12 -12
  45. package/dist/src/history/MessageHistory.js +46 -52
  46. package/dist/src/history/MessageModerator.d.ts +2 -2
  47. package/dist/src/history/MessageModerator.js +3 -3
  48. package/dist/src/template/ConversationTemplate.d.ts +8 -8
  49. package/dist/src/template/ConversationTemplate.js +3 -3
  50. package/dist/src/template/ConversationTemplateFunctions.d.ts +35 -33
  51. package/dist/src/template/ConversationTemplateFunctions.js +75 -176
  52. package/dist/src/template/ConversationTemplateModule.d.ts +48 -51
  53. package/dist/src/template/ConversationTemplateModule.js +116 -211
  54. package/dist/src/template/createApp/CreateAppTemplate.d.ts +1 -1
  55. package/dist/src/template/createApp/CreateAppTemplate.js +59 -151
  56. package/dist/src/template/createCode/CreateCodeConversationTemplate.d.ts +1 -1
  57. package/dist/src/template/createCode/CreateCodeConversationTemplate.js +67 -183
  58. package/dist/src/template/createPackage/CreatePackageConversationTemplate.d.ts +1 -1
  59. package/dist/src/template/createPackage/CreatePackageConversationTemplate.js +77 -174
  60. package/dist/src/template/createPackage/tsconfig.json +11 -11
  61. package/dist/test/createKeywordFilesIndex.test.d.ts +1 -1
  62. package/dist/test/createKeywordFilesIndex.test.js +41 -132
  63. package/dist/test/openai/openai.generateList.test.d.ts +1 -1
  64. package/dist/test/openai/openai.generateList.test.js +47 -136
  65. package/dist/test/openai/openai.parseCodeFromMarkdown.test.d.ts +1 -1
  66. package/dist/test/openai/openai.parseCodeFromMarkdown.test.js +12 -13
  67. package/dist/test/repo/repo.test.d.ts +1 -1
  68. package/dist/test/repo/repo.test.js +38 -127
  69. package/package.json +5 -6
  70. package/LICENSE +0 -21
@@ -1,305 +1,191 @@
1
- 'use strict';
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = {
10
- enumerable: true,
11
- get: function () {
12
- return m[k];
13
- },
14
- };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }
18
- : function (o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- });
22
- var __setModuleDefault =
23
- (this && this.__setModuleDefault) ||
24
- (Object.create
25
- ? function (o, v) {
26
- Object.defineProperty(o, 'default', { enumerable: true, value: v });
27
- }
28
- : function (o, v) {
29
- o['default'] = v;
30
- });
31
- var __importStar =
32
- (this && this.__importStar) ||
33
- function (mod) {
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
34
19
  if (mod && mod.__esModule) return mod;
35
20
  var result = {};
36
- if (mod != null)
37
- for (var k in mod)
38
- if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
39
22
  __setModuleDefault(result, mod);
40
23
  return result;
41
- };
42
- var __awaiter =
43
- (this && this.__awaiter) ||
44
- function (thisArg, _arguments, P, generator) {
45
- function adopt(value) {
46
- return value instanceof P
47
- ? value
48
- : new P(function (resolve) {
49
- resolve(value);
50
- });
51
- }
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
52
27
  return new (P || (P = Promise))(function (resolve, reject) {
53
- function fulfilled(value) {
54
- try {
55
- step(generator.next(value));
56
- } catch (e) {
57
- reject(e);
58
- }
59
- }
60
- function rejected(value) {
61
- try {
62
- step(generator['throw'](value));
63
- } catch (e) {
64
- reject(e);
65
- }
66
- }
67
- function step(result) {
68
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
69
- }
70
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
71
32
  });
72
- };
73
- var __generator =
74
- (this && this.__generator) ||
75
- function (thisArg, body) {
76
- var _ = {
77
- label: 0,
78
- sent: function () {
79
- if (t[0] & 1) throw t[1];
80
- return t[1];
81
- },
82
- trys: [],
83
- ops: [],
84
- },
85
- f,
86
- y,
87
- t,
88
- g;
89
- return (
90
- (g = { next: verb(0), throw: verb(1), return: verb(2) }),
91
- typeof Symbol === 'function' &&
92
- (g[Symbol.iterator] = function () {
93
- return this;
94
- }),
95
- g
96
- );
97
- function verb(n) {
98
- return function (v) {
99
- return step([n, v]);
100
- };
101
- }
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
102
38
  function step(op) {
103
- if (f) throw new TypeError('Generator is already executing.');
104
- while ((g && ((g = 0), op[0] && (_ = 0)), _))
105
- try {
106
- if (
107
- ((f = 1),
108
- y &&
109
- (t = op[0] & 2 ? y['return'] : op[0] ? y['throw'] || ((t = y['return']) && t.call(y), 0) : y.next) &&
110
- !(t = t.call(y, op[1])).done)
111
- )
112
- return t;
113
- if (((y = 0), t)) op = [op[0] & 2, t.value];
114
- switch (op[0]) {
115
- case 0:
116
- case 1:
117
- t = op;
118
- break;
119
- case 4:
120
- _.label++;
121
- return { value: op[1], done: false };
122
- case 5:
123
- _.label++;
124
- y = op[1];
125
- op = [0];
126
- continue;
127
- case 7:
128
- op = _.ops.pop();
129
- _.trys.pop();
130
- continue;
131
- default:
132
- if (!((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && (op[0] === 6 || op[0] === 2)) {
133
- _ = 0;
134
- continue;
135
- }
136
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
137
- _.label = op[1];
138
- break;
139
- }
140
- if (op[0] === 6 && _.label < t[1]) {
141
- _.label = t[1];
142
- t = op;
143
- break;
144
- }
145
- if (t && _.label < t[2]) {
146
- _.label = t[2];
147
- _.ops.push(op);
148
- break;
149
- }
150
- if (t[2]) _.ops.pop();
151
- _.trys.pop();
152
- continue;
153
- }
154
- op = body.call(thisArg, _);
155
- } catch (e) {
156
- op = [6, e];
157
- y = 0;
158
- } finally {
159
- f = t = 0;
160
- }
161
- if (op[0] & 5) throw op[1];
162
- return { value: op[0] ? op[1] : void 0, done: true };
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
163
59
  }
164
- };
165
- Object.defineProperty(exports, '__esModule', { value: true });
60
+ };
61
+ Object.defineProperty(exports, "__esModule", { value: true });
166
62
  exports.CodegenConversation = void 0;
167
- var readline = __importStar(require('readline-sync'));
168
- var Conversation_1 = require('./Conversation');
169
- var KeywordToFilesIndexModule_1 = require('./fs/keyword_to_files_index/KeywordToFilesIndexModule');
170
- var ConversationTemplateModule_1 = require('./template/ConversationTemplateModule');
171
- var ConversationFsModule_1 = require('./fs/conversation_fs/ConversationFsModule');
172
- var PackageModule_1 = require('./fs/package/PackageModule');
173
- var util_1 = require('@proteinjs/util');
174
- var GitModule_1 = require('./fs/git/GitModule');
63
+ var readline = __importStar(require("readline-sync"));
64
+ var Conversation_1 = require("./Conversation");
65
+ var KeywordToFilesIndexModule_1 = require("./fs/keyword_to_files_index/KeywordToFilesIndexModule");
66
+ var ConversationTemplateModule_1 = require("./template/ConversationTemplateModule");
67
+ var ConversationFsModule_1 = require("./fs/conversation_fs/ConversationFsModule");
68
+ var PackageModule_1 = require("./fs/package/PackageModule");
69
+ var util_1 = require("@proteinjs/util");
70
+ var GitModule_1 = require("./fs/git/GitModule");
175
71
  var CodegenConversation = /** @class */ (function () {
176
- function CodegenConversation(repoPath) {
177
- this.repoPath = repoPath;
178
- }
179
- CodegenConversation.prototype.start = function () {
180
- return __awaiter(this, void 0, void 0, function () {
181
- var conversation, initialUserInput, response, userInput;
182
- return __generator(this, function (_a) {
183
- switch (_a.label) {
184
- case 0:
185
- return [4 /*yield*/, this.createConversation()];
186
- case 1:
187
- conversation = _a.sent();
188
- conversation.addAssistantMessagesToHistory([CodegenConversation.INITIAL_QUESTION]);
189
- initialUserInput = this.respondToUser(CodegenConversation.INITIAL_QUESTION);
190
- return [4 /*yield*/, conversation.generateResponse([initialUserInput], CodegenConversation.MODEL)];
191
- case 2:
192
- response = _a.sent();
193
- _a.label = 3;
194
- case 3:
195
- if (!true) return [3 /*break*/, 5];
196
- userInput = this.respondToUser(response);
197
- return [4 /*yield*/, conversation.generateResponse([userInput], CodegenConversation.MODEL)];
198
- case 4:
199
- response = _a.sent();
200
- return [3 /*break*/, 3];
201
- case 5:
202
- return [2 /*return*/];
203
- }
204
- });
205
- });
206
- };
207
- CodegenConversation.prototype.createConversation = function () {
208
- return __awaiter(this, void 0, void 0, function () {
209
- var conversation, _a;
210
- var _b;
211
- return __generator(this, function (_c) {
212
- switch (_c.label) {
213
- case 0:
214
- _a = Conversation_1.Conversation.bind;
215
- _b = {
216
- name: this.constructor.name,
217
- };
218
- return [4 /*yield*/, this.getModules()];
219
- case 1:
220
- conversation = new (_a.apply(Conversation_1.Conversation, [
221
- void 0,
222
- ((_b.modules = _c.sent()), (_b.logLevel = 'info'), _b),
223
- ]))();
224
- conversation.addSystemMessagesToHistory(this.getSystemMessages());
225
- return [2 /*return*/, conversation];
226
- }
227
- });
228
- });
229
- };
230
- CodegenConversation.prototype.getModules = function () {
231
- return __awaiter(this, void 0, void 0, function () {
232
- var moduleFactories, modules, _i, moduleFactories_1, moduleFactory, _a, _b;
233
- return __generator(this, function (_c) {
234
- switch (_c.label) {
235
- case 0:
236
- moduleFactories = [
237
- new ConversationFsModule_1.ConversationFsModuleFactory(),
238
- new KeywordToFilesIndexModule_1.KeywordToFilesIndexModuleFactory(),
239
- new PackageModule_1.PackageModuleFactory(),
240
- new ConversationTemplateModule_1.ConversationTemplateModuleFactory(),
241
- new GitModule_1.GitModuleFactory(),
242
- ];
243
- modules = [];
244
- (_i = 0), (moduleFactories_1 = moduleFactories);
245
- _c.label = 1;
246
- case 1:
247
- if (!(_i < moduleFactories_1.length)) return [3 /*break*/, 4];
248
- moduleFactory = moduleFactories_1[_i];
249
- _b = (_a = modules).push;
250
- return [4 /*yield*/, moduleFactory.createModule(this.repoPath)];
251
- case 2:
252
- _b.apply(_a, [_c.sent()]);
253
- _c.label = 3;
254
- case 3:
255
- _i++;
256
- return [3 /*break*/, 1];
257
- case 4:
258
- return [2 /*return*/, modules];
259
- }
260
- });
261
- });
262
- };
263
- CodegenConversation.prototype.getSystemMessages = function () {
264
- return [
265
- 'We are going to have a conversation with the user to generate code',
266
- 'Await all function calls that return a promise',
267
- 'Try to repspond to the user with as few words as possible while still having a conversational tone',
268
- "When generating code, export the objects you create inline; do not use 'export default' syntax",
269
- // `After finding a file to work with, assume the user's following question pertains to that file and use ${readFilesFunctionName} to read the file if needed`,
270
- // `If a conversation summary exists, if you aren't already working with a file, use the most relevant keyword mentioned in the conversation summary to find a file to read (using the ${searchFilesFunctionName} function) and then respond to the user after reading the file`,
271
- // `Use the most relevant keyword mentioned in the conversation summary to find a file to read (using the ${searchFilesFunctionName} function) and then respond to the user after reading the file`,
272
- // `If the conversation summary indicates the user was working with a file get the file path (use the ${searchFilesFunctionName} function if needed) and read the file with the ${readFilesFunctionName} function. Use that file as context to respond to the user.`,
273
- //
274
- // `Use the conversation summary to identify a file as context for the user interaction`,
275
- // `Use the ${searchFilesFunctionName} function to find the file if needed; read the file if needed`,
276
- // `If the user is referring to a function, object, class, or type and you don't have the relevant file content, first inspect the conversation summary in the chat history (if it exists) to find a file name, and call the ${searchFilesFunctionName} function and read the file before responding to the user`,
277
- // `Before calling ${searchFilesFunctionName}, ${searchLibrariesFunctionName} or ${searchPackagesFunctionName}, use the conversation summary in the chat history to identify a file or keyword to search for instead; after reading that file, respond to the user's request`,
278
- //
279
- // `Use the ${getRecentlyAccessedFilePathsFunctionName} function find a file that might pertain to the user's request before searching files, libraries or packages; read that file then respond to the user`,
280
- // `When trying to locate code, use the ${getRecentlyAccessedFilePathsFunctionName} function to search recently accessed files first, then proceed to calling other functions: ${searchLibrariesFunctionName}, ${searchPackagesFunctionName}, ${searchFilesFunctionName}`,
281
- // `The conversation summary indicates files recently worked in as well`,
282
- // `If that doesn't yield results, proceed to calling the ${searchLibrariesFunctionName} function, then fall back to functions: ${searchPackagesFunctionName}, ${searchFilesFunctionName}`,
283
- //
284
- // `To find code, a file, or a library, call ${getRecentlyAccessedFilePathsFunctionName} and read the most recent file, after trying that call ${searchLibrariesFunctionName} then ${searchFilesFunctionName} to find a relevant file`,
285
- // `The file mentioned in the conversation summary should be read if we're not already working in a file`,
286
- // `If there is a conversation summary assistant message, use that to pick a file to read before responding to the user if not already working with a specific file`,
287
- // `Check for a previous conversation summary assistant message in the chat history; if there is one and it mentions a file the user was working with, call ${searchLibrariesFunctionName} to find the file path then call ${readFilesFunctionName} to read the file. Do this to build context before responding to the user`,
288
- ];
289
- };
290
- CodegenConversation.prototype.respondToUser = function (message) {
291
- return readline.question(
292
- ''
293
- .concat(util_1.textColorMap.cyan, '[')
294
- .concat(CodegenConversation.BOT_NAME, '] ')
295
- .concat(message)
296
- .concat(util_1.Reset, '\n')
297
- );
298
- };
299
- CodegenConversation.INITIAL_QUESTION = 'What would you like to create?';
300
- CodegenConversation.BOT_NAME = 'Alina';
301
- CodegenConversation.MODEL = 'gpt-4'; //'gpt-3.5-turbo-16k';
302
- return CodegenConversation;
303
- })();
72
+ function CodegenConversation(repoPath) {
73
+ this.repoPath = repoPath;
74
+ }
75
+ CodegenConversation.prototype.start = function () {
76
+ return __awaiter(this, void 0, void 0, function () {
77
+ var conversation, initialUserInput, response, userInput;
78
+ return __generator(this, function (_a) {
79
+ switch (_a.label) {
80
+ case 0: return [4 /*yield*/, this.createConversation()];
81
+ case 1:
82
+ conversation = _a.sent();
83
+ conversation.addAssistantMessagesToHistory([CodegenConversation.INITIAL_QUESTION]);
84
+ initialUserInput = this.respondToUser(CodegenConversation.INITIAL_QUESTION);
85
+ return [4 /*yield*/, conversation.generateResponse([initialUserInput], CodegenConversation.MODEL)];
86
+ case 2:
87
+ response = _a.sent();
88
+ _a.label = 3;
89
+ case 3:
90
+ if (!true) return [3 /*break*/, 5];
91
+ userInput = this.respondToUser(response);
92
+ return [4 /*yield*/, conversation.generateResponse([userInput], CodegenConversation.MODEL)];
93
+ case 4:
94
+ response = _a.sent();
95
+ return [3 /*break*/, 3];
96
+ case 5: return [2 /*return*/];
97
+ }
98
+ });
99
+ });
100
+ };
101
+ CodegenConversation.prototype.createConversation = function () {
102
+ return __awaiter(this, void 0, void 0, function () {
103
+ var conversation, _a;
104
+ var _b;
105
+ return __generator(this, function (_c) {
106
+ switch (_c.label) {
107
+ case 0:
108
+ _a = Conversation_1.Conversation.bind;
109
+ _b = {
110
+ name: this.constructor.name
111
+ };
112
+ return [4 /*yield*/, this.getModules()];
113
+ case 1:
114
+ conversation = new (_a.apply(Conversation_1.Conversation, [void 0, (_b.modules = _c.sent(),
115
+ _b.logLevel = 'info',
116
+ _b)]))();
117
+ conversation.addSystemMessagesToHistory(this.getSystemMessages());
118
+ return [2 /*return*/, conversation];
119
+ }
120
+ });
121
+ });
122
+ };
123
+ CodegenConversation.prototype.getModules = function () {
124
+ return __awaiter(this, void 0, void 0, function () {
125
+ var moduleFactories, modules, _i, moduleFactories_1, moduleFactory, _a, _b;
126
+ return __generator(this, function (_c) {
127
+ switch (_c.label) {
128
+ case 0:
129
+ moduleFactories = [
130
+ new ConversationFsModule_1.ConversationFsModuleFactory(),
131
+ new KeywordToFilesIndexModule_1.KeywordToFilesIndexModuleFactory(),
132
+ new PackageModule_1.PackageModuleFactory(),
133
+ new ConversationTemplateModule_1.ConversationTemplateModuleFactory(),
134
+ new GitModule_1.GitModuleFactory(),
135
+ ];
136
+ modules = [];
137
+ _i = 0, moduleFactories_1 = moduleFactories;
138
+ _c.label = 1;
139
+ case 1:
140
+ if (!(_i < moduleFactories_1.length)) return [3 /*break*/, 4];
141
+ moduleFactory = moduleFactories_1[_i];
142
+ _b = (_a = modules).push;
143
+ return [4 /*yield*/, moduleFactory.createModule(this.repoPath)];
144
+ case 2:
145
+ _b.apply(_a, [_c.sent()]);
146
+ _c.label = 3;
147
+ case 3:
148
+ _i++;
149
+ return [3 /*break*/, 1];
150
+ case 4: return [2 /*return*/, modules];
151
+ }
152
+ });
153
+ });
154
+ };
155
+ CodegenConversation.prototype.getSystemMessages = function () {
156
+ return [
157
+ "We are going to have a conversation with the user to generate code",
158
+ "Await all function calls that return a promise",
159
+ "Try to repspond to the user with as few words as possible while still having a conversational tone",
160
+ "When generating code, export the objects you create inline; do not use 'export default' syntax",
161
+ // `After finding a file to work with, assume the user's following question pertains to that file and use ${readFilesFunctionName} to read the file if needed`,
162
+ // `If a conversation summary exists, if you aren't already working with a file, use the most relevant keyword mentioned in the conversation summary to find a file to read (using the ${searchFilesFunctionName} function) and then respond to the user after reading the file`,
163
+ // `Use the most relevant keyword mentioned in the conversation summary to find a file to read (using the ${searchFilesFunctionName} function) and then respond to the user after reading the file`,
164
+ // `If the conversation summary indicates the user was working with a file get the file path (use the ${searchFilesFunctionName} function if needed) and read the file with the ${readFilesFunctionName} function. Use that file as context to respond to the user.`,
165
+ //
166
+ // `Use the conversation summary to identify a file as context for the user interaction`,
167
+ // `Use the ${searchFilesFunctionName} function to find the file if needed; read the file if needed`,
168
+ // `If the user is referring to a function, object, class, or type and you don't have the relevant file content, first inspect the conversation summary in the chat history (if it exists) to find a file name, and call the ${searchFilesFunctionName} function and read the file before responding to the user`,
169
+ // `Before calling ${searchFilesFunctionName}, ${searchLibrariesFunctionName} or ${searchPackagesFunctionName}, use the conversation summary in the chat history to identify a file or keyword to search for instead; after reading that file, respond to the user's request`,
170
+ //
171
+ // `Use the ${getRecentlyAccessedFilePathsFunctionName} function find a file that might pertain to the user's request before searching files, libraries or packages; read that file then respond to the user`,
172
+ // `When trying to locate code, use the ${getRecentlyAccessedFilePathsFunctionName} function to search recently accessed files first, then proceed to calling other functions: ${searchLibrariesFunctionName}, ${searchPackagesFunctionName}, ${searchFilesFunctionName}`,
173
+ // `The conversation summary indicates files recently worked in as well`,
174
+ // `If that doesn't yield results, proceed to calling the ${searchLibrariesFunctionName} function, then fall back to functions: ${searchPackagesFunctionName}, ${searchFilesFunctionName}`,
175
+ //
176
+ // `To find code, a file, or a library, call ${getRecentlyAccessedFilePathsFunctionName} and read the most recent file, after trying that call ${searchLibrariesFunctionName} then ${searchFilesFunctionName} to find a relevant file`,
177
+ // `The file mentioned in the conversation summary should be read if we're not already working in a file`,
178
+ // `If there is a conversation summary assistant message, use that to pick a file to read before responding to the user if not already working with a specific file`,
179
+ // `Check for a previous conversation summary assistant message in the chat history; if there is one and it mentions a file the user was working with, call ${searchLibrariesFunctionName} to find the file path then call ${readFilesFunctionName} to read the file. Do this to build context before responding to the user`,
180
+ ];
181
+ };
182
+ CodegenConversation.prototype.respondToUser = function (message) {
183
+ return readline.question("".concat(util_1.textColorMap.cyan, "[").concat(CodegenConversation.BOT_NAME, "] ").concat(message).concat(util_1.Reset, "\n"));
184
+ };
185
+ CodegenConversation.INITIAL_QUESTION = 'What would you like to create?';
186
+ CodegenConversation.BOT_NAME = 'Alina';
187
+ CodegenConversation.MODEL = 'gpt-4'; //'gpt-3.5-turbo-16k';
188
+ return CodegenConversation;
189
+ }());
304
190
  exports.CodegenConversation = CodegenConversation;
305
- //# sourceMappingURL=CodegenConversation.js.map
191
+ //# sourceMappingURL=CodegenConversation.js.map
@@ -2,62 +2,59 @@ import { LogLevel } from '@proteinjs/util';
2
2
  import { ConversationModule } from './ConversationModule';
3
3
  import { TiktokenModel } from 'tiktoken';
4
4
  export type ConversationParams = {
5
- name: string;
6
- modules?: ConversationModule[];
7
- logLevel?: LogLevel;
8
- limits?: {
9
- enforceLimits?: boolean;
10
- maxMessagesInHistory?: number;
11
- tokenLimit?: number;
12
- };
5
+ name: string;
6
+ modules?: ConversationModule[];
7
+ logLevel?: LogLevel;
8
+ limits?: {
9
+ enforceLimits?: boolean;
10
+ maxMessagesInHistory?: number;
11
+ tokenLimit?: number;
12
+ };
13
13
  };
14
14
  export declare class Conversation {
15
- private tokenLimit;
16
- private history;
17
- private systemMessages;
18
- private functions;
19
- private messageModerators;
20
- private generatedCode;
21
- private generatedList;
22
- private logger;
23
- private params;
24
- constructor(params: ConversationParams);
25
- private addModules;
26
- private addFunctions;
27
- private addMessageModerators;
28
- private enforceTokenLimit;
29
- summarizeConversationHistory(summary: string): void;
30
- private clearHistory;
31
- addSystemMessagesToHistory(messages: string[], unshift?: boolean): void;
32
- addAssistantMessagesToHistory(messages: string[], unshift?: boolean): void;
33
- addUserMessagesToHistory(messages: string[], unshift?: boolean): void;
34
- generateResponse(messages: string[], model?: TiktokenModel): Promise<string>;
35
- generateCode(description: string[], model?: TiktokenModel): Promise<string>;
36
- updateCodeFromFile(
37
- codeToUpdateFilePath: string,
38
- dependencyCodeFilePaths: string[],
39
- description: string,
40
- model?: TiktokenModel
41
- ): Promise<string>;
42
- updateCode(code: string, description: string, model?: TiktokenModel): Promise<string>;
43
- generateList(description: string[], model?: TiktokenModel): Promise<string[]>;
15
+ private tokenLimit;
16
+ private history;
17
+ private systemMessages;
18
+ private functions;
19
+ private messageModerators;
20
+ private generatedCode;
21
+ private generatedList;
22
+ private logger;
23
+ private params;
24
+ constructor(params: ConversationParams);
25
+ private addModules;
26
+ private addFunctions;
27
+ private addMessageModerators;
28
+ private enforceTokenLimit;
29
+ summarizeConversationHistory(summary: string): void;
30
+ private clearHistory;
31
+ addSystemMessagesToHistory(messages: string[], unshift?: boolean): void;
32
+ addAssistantMessagesToHistory(messages: string[], unshift?: boolean): void;
33
+ addUserMessagesToHistory(messages: string[], unshift?: boolean): void;
34
+ generateResponse(messages: string[], model?: TiktokenModel): Promise<string>;
35
+ generateCode(description: string[], model?: TiktokenModel): Promise<string>;
36
+ updateCodeFromFile(codeToUpdateFilePath: string, dependencyCodeFilePaths: string[], description: string, model?: TiktokenModel): Promise<string>;
37
+ updateCode(code: string, description: string, model?: TiktokenModel): Promise<string>;
38
+ generateList(description: string[], model?: TiktokenModel): Promise<string[]>;
44
39
  }
45
- export declare const summarizeConversationHistoryFunctionName = 'summarizeConversationHistory';
40
+ export declare const summarizeConversationHistoryFunctionName = "summarizeConversationHistory";
46
41
  export declare const summarizeConversationHistoryFunction: (conversation: Conversation) => {
47
- definition: {
48
- name: string;
49
- description: string;
50
- parameters: {
51
- type: string;
52
- properties: {
53
- summary: {
54
- type: string;
55
- description: string;
42
+ definition: {
43
+ name: string;
44
+ description: string;
45
+ parameters: {
46
+ type: string;
47
+ properties: {
48
+ summary: {
49
+ type: string;
50
+ description: string;
51
+ };
52
+ };
53
+ required: string[];
56
54
  };
57
- };
58
- required: string[];
59
55
  };
60
- };
61
- call: (params: { summary: string }) => Promise<void>;
56
+ call: (params: {
57
+ summary: string;
58
+ }) => Promise<void>;
62
59
  };
63
- //# sourceMappingURL=Conversation.d.ts.map
60
+ //# sourceMappingURL=Conversation.d.ts.map