@proteinjs/conversation 1.0.5 → 1.0.7

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 (152) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.prettierrc +8 -0
  3. package/CHANGELOG.md +7 -4
  4. package/LICENSE +21 -0
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +40 -28
  7. package/dist/src/CodegenConversation.d.ts +11 -11
  8. package/dist/src/CodegenConversation.d.ts.map +1 -1
  9. package/dist/src/CodegenConversation.js +294 -180
  10. package/dist/src/CodegenConversation.js.map +1 -1
  11. package/dist/src/Conversation.d.ts +52 -49
  12. package/dist/src/Conversation.d.ts.map +1 -1
  13. package/dist/src/Conversation.js +480 -274
  14. package/dist/src/Conversation.js.map +1 -1
  15. package/dist/src/ConversationModule.d.ts +6 -6
  16. package/dist/src/ConversationModule.js +3 -3
  17. package/dist/src/Function.d.ts +4 -4
  18. package/dist/src/Function.d.ts.map +1 -1
  19. package/dist/src/Function.js +3 -3
  20. package/dist/src/OpenAi.d.ts +42 -10
  21. package/dist/src/OpenAi.d.ts.map +1 -1
  22. package/dist/src/OpenAi.js +496 -289
  23. package/dist/src/OpenAi.js.map +1 -1
  24. package/dist/src/Paragraph.d.ts +4 -4
  25. package/dist/src/Paragraph.d.ts.map +1 -1
  26. package/dist/src/Paragraph.js +17 -16
  27. package/dist/src/Paragraph.js.map +1 -1
  28. package/dist/src/Sentence.d.ts +4 -4
  29. package/dist/src/Sentence.d.ts.map +1 -1
  30. package/dist/src/Sentence.js +21 -19
  31. package/dist/src/Sentence.js.map +1 -1
  32. package/dist/src/code_template/Code.d.ts +15 -15
  33. package/dist/src/code_template/Code.d.ts.map +1 -1
  34. package/dist/src/code_template/Code.js +167 -69
  35. package/dist/src/code_template/Code.js.map +1 -1
  36. package/dist/src/code_template/CodeTemplate.d.ts +11 -11
  37. package/dist/src/code_template/CodeTemplate.d.ts.map +1 -1
  38. package/dist/src/code_template/CodeTemplate.js +169 -79
  39. package/dist/src/code_template/CodeTemplate.js.map +1 -1
  40. package/dist/src/code_template/CodeTemplateModule.d.ts +6 -6
  41. package/dist/src/code_template/CodeTemplateModule.js +28 -26
  42. package/dist/src/code_template/Repo.d.ts +34 -38
  43. package/dist/src/code_template/Repo.d.ts.map +1 -1
  44. package/dist/src/code_template/Repo.js +291 -191
  45. package/dist/src/code_template/Repo.js.map +1 -1
  46. package/dist/src/fs/conversation_fs/ConversationFsModerator.d.ts +12 -12
  47. package/dist/src/fs/conversation_fs/ConversationFsModerator.d.ts.map +1 -1
  48. package/dist/src/fs/conversation_fs/ConversationFsModerator.js +111 -98
  49. package/dist/src/fs/conversation_fs/ConversationFsModerator.js.map +1 -1
  50. package/dist/src/fs/conversation_fs/ConversationFsModule.d.ts +11 -11
  51. package/dist/src/fs/conversation_fs/ConversationFsModule.d.ts.map +1 -1
  52. package/dist/src/fs/conversation_fs/ConversationFsModule.js +204 -99
  53. package/dist/src/fs/conversation_fs/ConversationFsModule.js.map +1 -1
  54. package/dist/src/fs/conversation_fs/FsFunctions.d.ts +58 -62
  55. package/dist/src/fs/conversation_fs/FsFunctions.d.ts.map +1 -1
  56. package/dist/src/fs/conversation_fs/FsFunctions.js +414 -266
  57. package/dist/src/fs/conversation_fs/FsFunctions.js.map +1 -1
  58. package/dist/src/fs/git/GitModule.d.ts +8 -8
  59. package/dist/src/fs/git/GitModule.d.ts.map +1 -1
  60. package/dist/src/fs/git/GitModule.js +163 -74
  61. package/dist/src/fs/git/GitModule.js.map +1 -1
  62. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.d.ts +16 -18
  63. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.d.ts.map +1 -1
  64. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.js +158 -58
  65. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.js.map +1 -1
  66. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.d.ts +27 -26
  67. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.d.ts.map +1 -1
  68. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js +234 -133
  69. package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js.map +1 -1
  70. package/dist/src/fs/package/PackageFunctions.d.ts +54 -60
  71. package/dist/src/fs/package/PackageFunctions.d.ts.map +1 -1
  72. package/dist/src/fs/package/PackageFunctions.js +366 -223
  73. package/dist/src/fs/package/PackageFunctions.js.map +1 -1
  74. package/dist/src/fs/package/PackageModule.d.ts +24 -24
  75. package/dist/src/fs/package/PackageModule.d.ts.map +1 -1
  76. package/dist/src/fs/package/PackageModule.js +292 -163
  77. package/dist/src/fs/package/PackageModule.js.map +1 -1
  78. package/dist/src/history/MessageHistory.d.ts +12 -12
  79. package/dist/src/history/MessageHistory.d.ts.map +1 -1
  80. package/dist/src/history/MessageHistory.js +52 -43
  81. package/dist/src/history/MessageHistory.js.map +1 -1
  82. package/dist/src/history/MessageModerator.d.ts +2 -2
  83. package/dist/src/history/MessageModerator.js +3 -3
  84. package/dist/src/template/ConversationTemplate.d.ts +8 -8
  85. package/dist/src/template/ConversationTemplate.d.ts.map +1 -1
  86. package/dist/src/template/ConversationTemplate.js +3 -3
  87. package/dist/src/template/ConversationTemplateFunctions.d.ts +33 -35
  88. package/dist/src/template/ConversationTemplateFunctions.d.ts.map +1 -1
  89. package/dist/src/template/ConversationTemplateFunctions.js +176 -75
  90. package/dist/src/template/ConversationTemplateFunctions.js.map +1 -1
  91. package/dist/src/template/ConversationTemplateModule.d.ts +51 -48
  92. package/dist/src/template/ConversationTemplateModule.d.ts.map +1 -1
  93. package/dist/src/template/ConversationTemplateModule.js +211 -114
  94. package/dist/src/template/ConversationTemplateModule.js.map +1 -1
  95. package/dist/src/template/createApp/CreateAppTemplate.d.ts +1 -1
  96. package/dist/src/template/createApp/CreateAppTemplate.js +151 -59
  97. package/dist/src/template/createCode/CreateCodeConversationTemplate.d.ts +1 -1
  98. package/dist/src/template/createCode/CreateCodeConversationTemplate.d.ts.map +1 -1
  99. package/dist/src/template/createCode/CreateCodeConversationTemplate.js +183 -74
  100. package/dist/src/template/createCode/CreateCodeConversationTemplate.js.map +1 -1
  101. package/dist/src/template/createPackage/CreatePackageConversationTemplate.d.ts +1 -1
  102. package/dist/src/template/createPackage/CreatePackageConversationTemplate.d.ts.map +1 -1
  103. package/dist/src/template/createPackage/CreatePackageConversationTemplate.js +174 -84
  104. package/dist/src/template/createPackage/CreatePackageConversationTemplate.js.map +1 -1
  105. package/dist/src/template/createPackage/tsconfig.json +11 -11
  106. package/dist/test/createKeywordFilesIndex.test.d.ts +1 -1
  107. package/dist/test/createKeywordFilesIndex.test.js +132 -41
  108. package/dist/test/createKeywordFilesIndex.test.js.map +1 -1
  109. package/dist/test/openai/openai.generateList.test.d.ts +1 -1
  110. package/dist/test/openai/openai.generateList.test.js +136 -47
  111. package/dist/test/openai/openai.generateList.test.js.map +1 -1
  112. package/dist/test/openai/openai.parseCodeFromMarkdown.test.d.ts +1 -1
  113. package/dist/test/openai/openai.parseCodeFromMarkdown.test.js +15 -10
  114. package/dist/test/openai/openai.parseCodeFromMarkdown.test.js.map +1 -1
  115. package/dist/test/repo/repo.test.d.ts +1 -1
  116. package/dist/test/repo/repo.test.js +127 -38
  117. package/dist/test/repo/repo.test.js.map +1 -1
  118. package/jest.config.js +2 -2
  119. package/package.json +11 -5
  120. package/src/CodegenConversation.ts +6 -4
  121. package/src/Conversation.ts +102 -33
  122. package/src/ConversationModule.ts +2 -2
  123. package/src/Function.ts +0 -1
  124. package/src/OpenAi.ts +128 -63
  125. package/src/Paragraph.ts +3 -2
  126. package/src/Sentence.ts +5 -3
  127. package/src/code_template/Code.ts +25 -19
  128. package/src/code_template/CodeTemplate.ts +8 -7
  129. package/src/code_template/CodeTemplateModule.ts +2 -2
  130. package/src/code_template/Repo.ts +25 -19
  131. package/src/fs/conversation_fs/ConversationFsModerator.ts +34 -20
  132. package/src/fs/conversation_fs/ConversationFsModule.ts +13 -7
  133. package/src/fs/conversation_fs/FsFunctions.ts +33 -44
  134. package/src/fs/git/GitModule.ts +2 -4
  135. package/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.ts +31 -31
  136. package/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.ts +19 -18
  137. package/src/fs/package/PackageFunctions.ts +34 -41
  138. package/src/fs/package/PackageModule.ts +33 -21
  139. package/src/history/MessageHistory.ts +7 -4
  140. package/src/history/MessageModerator.ts +1 -1
  141. package/src/template/ConversationTemplate.ts +9 -9
  142. package/src/template/ConversationTemplateFunctions.ts +8 -7
  143. package/src/template/ConversationTemplateModule.ts +24 -15
  144. package/src/template/createApp/CreateAppTemplate.ts +1 -1
  145. package/src/template/createCode/CreateCodeConversationTemplate.ts +9 -11
  146. package/src/template/createPackage/CreatePackageConversationTemplate.ts +2 -9
  147. package/src/template/createPackage/jest.config.js +2 -2
  148. package/test/createKeywordFilesIndex.test.ts +3 -3
  149. package/test/openai/openai.generateList.test.ts +5 -3
  150. package/test/openai/openai.parseCodeFromMarkdown.test.ts +10 -5
  151. package/test/repo/repo.test.ts +3 -4
  152. package/tsconfig.json +16 -20
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@proteinjs/conversation",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
9
  "scripts": {
10
- "clean": "rm -rf dist/ node_modules/ package-lock.json",
10
+ "clean": "rm -rf dist/ node_modules/",
11
11
  "build": "tsc",
12
12
  "watch": "tsc -w -p .",
13
13
  "start": "node ./dist/index.js",
@@ -19,16 +19,22 @@
19
19
  "@types/jest": "^29.5.4",
20
20
  "@types/node": "20.5.9",
21
21
  "@types/readline-sync": "1.4.4",
22
+ "@typescript-eslint/eslint-plugin": "7.8.0",
23
+ "@typescript-eslint/parser": "7.8.0",
24
+ "eslint": "8.57.0",
25
+ "eslint-config-prettier": "9.1.0",
26
+ "eslint-plugin-prettier": "5.1.3",
22
27
  "jest": "^29.6.4",
23
28
  "ts-jest": "^29.1.1"
24
29
  },
25
30
  "dependencies": {
26
31
  "@proteinjs/util": "1.1.0",
27
- "@proteinjs/util-node": "1.1.0",
32
+ "@proteinjs/util-node": "1.2.0",
28
33
  "fs-extra": "11.1.1",
29
34
  "openai": "4.4.0",
30
35
  "readline-sync": "1.4.10",
31
36
  "tiktoken": "1.0.11",
32
37
  "typescript": "5.2.2"
33
- }
34
- }
38
+ },
39
+ "gitHead": "c80aa2d5ec21217b51a064ffdceada8e3d7644e8"
40
+ }
@@ -27,6 +27,7 @@ export class CodegenConversation {
27
27
  conversation.addAssistantMessagesToHistory([CodegenConversation.INITIAL_QUESTION]);
28
28
  const initialUserInput = this.respondToUser(CodegenConversation.INITIAL_QUESTION);
29
29
  let response = await conversation.generateResponse([initialUserInput], CodegenConversation.MODEL);
30
+ // eslint-disable-next-line no-constant-condition
30
31
  while (true) {
31
32
  const userInput = this.respondToUser(response);
32
33
  response = await conversation.generateResponse([userInput], CodegenConversation.MODEL);
@@ -52,8 +53,9 @@ export class CodegenConversation {
52
53
  new GitModuleFactory(),
53
54
  ];
54
55
  const modules: ConversationModule[] = [];
55
- for (let moduleFactory of moduleFactories)
56
+ for (const moduleFactory of moduleFactories) {
56
57
  modules.push(await moduleFactory.createModule(this.repoPath));
58
+ }
57
59
 
58
60
  return modules;
59
61
  }
@@ -73,12 +75,12 @@ export class CodegenConversation {
73
75
  // `Use the ${searchFilesFunctionName} function to find the file if needed; read the file if needed`,
74
76
  // `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`,
75
77
  // `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`,
76
- //
78
+ //
77
79
  // `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`,
78
80
  // `When trying to locate code, use the ${getRecentlyAccessedFilePathsFunctionName} function to search recently accessed files first, then proceed to calling other functions: ${searchLibrariesFunctionName}, ${searchPackagesFunctionName}, ${searchFilesFunctionName}`,
79
81
  // `The conversation summary indicates files recently worked in as well`,
80
82
  // `If that doesn't yield results, proceed to calling the ${searchLibrariesFunctionName} function, then fall back to functions: ${searchPackagesFunctionName}, ${searchFilesFunctionName}`,
81
- //
83
+ //
82
84
  // `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`,
83
85
  // `The file mentioned in the conversation summary should be read if we're not already working in a file`,
84
86
  // `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`,
@@ -89,4 +91,4 @@ export class CodegenConversation {
89
91
  private respondToUser(message: string) {
90
92
  return readline.question(`${textColorMap.cyan}[${CodegenConversation.BOT_NAME}] ${message}${Reset}\n`);
91
93
  }
92
- }
94
+ }
@@ -10,7 +10,7 @@ import { TiktokenModel, encoding_for_model } from 'tiktoken';
10
10
  import { searchLibrariesFunctionName } from './fs/package/PackageFunctions';
11
11
 
12
12
  export type ConversationParams = {
13
- name: string,
13
+ name: string;
14
14
  modules?: ConversationModule[];
15
15
  logLevel?: LogLevel;
16
16
  limits?: {
@@ -18,7 +18,7 @@ export type ConversationParams = {
18
18
  maxMessagesInHistory?: number;
19
19
  tokenLimit?: number;
20
20
  };
21
- }
21
+ };
22
22
 
23
23
  export class Conversation {
24
24
  private tokenLimit = 3000;
@@ -33,26 +33,30 @@ export class Conversation {
33
33
 
34
34
  constructor(params: ConversationParams) {
35
35
  this.params = params;
36
- this.history = new MessageHistory({ maxMessages: params.limits?.maxMessagesInHistory, enforceMessageLimit: params.limits?.enforceLimits });
36
+ this.history = new MessageHistory({
37
+ maxMessages: params.limits?.maxMessagesInHistory,
38
+ enforceMessageLimit: params.limits?.enforceLimits,
39
+ });
37
40
  this.logger = new Logger(params.name, params.logLevel);
38
41
 
39
- if (params.modules)
42
+ if (params.modules) {
40
43
  this.addModules(params.modules);
44
+ }
41
45
 
42
46
  if (typeof params.limits?.enforceLimits === 'undefined' || params.limits.enforceLimits) {
43
- this.addFunctions('Conversation', [
44
- summarizeConversationHistoryFunction(this),
45
- ]);
47
+ this.addFunctions('Conversation', [summarizeConversationHistoryFunction(this)]);
46
48
  }
47
49
 
48
- if (params.limits?.tokenLimit)
50
+ if (params.limits?.tokenLimit) {
49
51
  this.tokenLimit = params.limits.tokenLimit;
52
+ }
50
53
  }
51
54
 
52
55
  private addModules(modules: ConversationModule[]) {
53
- for (let module of modules) {
54
- if (module.getSystemMessages().length < 1)
56
+ for (const module of modules) {
57
+ if (module.getSystemMessages().length < 1) {
55
58
  continue;
59
+ }
56
60
 
57
61
  this.addSystemMessagesToHistory([
58
62
  `The following are instructions from the ${module.getName()} module: ${module.getSystemMessages().join('. ')}`,
@@ -66,10 +70,11 @@ export class Conversation {
66
70
  this.functions.push(...functions);
67
71
  let functionInstructions = `The following are instructions from functions in the ${moduleName} module:`;
68
72
  let functionInstructionsAdded = false;
69
- for (let f of functions) {
73
+ for (const f of functions) {
70
74
  if (f.instructions) {
71
- if (!f.instructions || f.instructions.length < 1)
75
+ if (!f.instructions || f.instructions.length < 1) {
72
76
  continue;
77
+ }
73
78
 
74
79
  functionInstructionsAdded = true;
75
80
  const instructionsParagraph = f.instructions.join('. ');
@@ -77,8 +82,9 @@ export class Conversation {
77
82
  }
78
83
  }
79
84
 
80
- if (!functionInstructionsAdded)
85
+ if (!functionInstructionsAdded) {
81
86
  return;
87
+ }
82
88
 
83
89
  this.addSystemMessagesToHistory([functionInstructions]);
84
90
  }
@@ -88,21 +94,37 @@ export class Conversation {
88
94
  }
89
95
 
90
96
  private async enforceTokenLimit(messages: string[], model?: TiktokenModel) {
91
- if (this.params.limits?.enforceLimits === false)
97
+ if (this.params.limits?.enforceLimits === false) {
92
98
  return;
93
-
99
+ }
100
+
94
101
  const resolvedModel = model ? model : DEFAULT_MODEL;
95
102
  const encoder = encoding_for_model(resolvedModel);
96
103
  const conversation = this.history.toString() + messages.join('. ');
97
104
  const encoded = encoder.encode(conversation);
98
105
  console.log(`current tokens: ${encoded.length}`);
99
- if (encoded.length < this.tokenLimit)
106
+ if (encoded.length < this.tokenLimit) {
100
107
  return;
108
+ }
101
109
 
102
110
  const summarizeConversationRequest = `First, call the ${summarizeConversationHistoryFunctionName} function`;
103
- await OpenAi.generateResponse([summarizeConversationRequest], model, this.history, this.functions, this.messageModerators, this.params.logLevel);
111
+ await OpenAi.generateResponse(
112
+ [summarizeConversationRequest],
113
+ model,
114
+ this.history,
115
+ this.functions,
116
+ this.messageModerators,
117
+ this.params.logLevel
118
+ );
104
119
  const referenceSummaryRequest = `If there's a file mentioned in the conversation summary, find and read the file to better respond to my next request. If that doesn't find anything, call the ${searchLibrariesFunctionName} function on other keywords in the conversation summary to find a file to read`;
105
- await OpenAi.generateResponse([referenceSummaryRequest], model, this.history, this.functions, this.messageModerators, this.params.logLevel);
120
+ await OpenAi.generateResponse(
121
+ [referenceSummaryRequest],
122
+ model,
123
+ this.history,
124
+ this.functions,
125
+ this.messageModerators,
126
+ this.params.logLevel
127
+ );
106
128
  }
107
129
 
108
130
  summarizeConversationHistory(summary: string) {
@@ -116,7 +138,9 @@ export class Conversation {
116
138
  }
117
139
 
118
140
  addSystemMessagesToHistory(messages: string[], unshift = false) {
119
- const chatCompletions: ChatCompletionMessageParam[] = messages.map(message => { return { role: 'system', content: message }});
141
+ const chatCompletions: ChatCompletionMessageParam[] = messages.map((message) => {
142
+ return { role: 'system', content: message };
143
+ });
120
144
  if (unshift) {
121
145
  this.history.getMessages().unshift(...chatCompletions);
122
146
  this.history.prune();
@@ -128,40 +152,66 @@ export class Conversation {
128
152
  }
129
153
 
130
154
  addAssistantMessagesToHistory(messages: string[], unshift = false) {
131
- const chatCompletions: ChatCompletionMessageParam[] = messages.map(message => { return { role: 'assistant', content: message }});
155
+ const chatCompletions: ChatCompletionMessageParam[] = messages.map((message) => {
156
+ return { role: 'assistant', content: message };
157
+ });
132
158
  if (unshift) {
133
159
  this.history.getMessages().unshift(...chatCompletions);
134
160
  this.history.prune();
135
- } else
161
+ } else {
136
162
  this.history.push(chatCompletions);
163
+ }
137
164
  }
138
165
 
139
166
  addUserMessagesToHistory(messages: string[], unshift = false) {
140
- const chatCompletions: ChatCompletionMessageParam[] = messages.map(message => { return { role: 'user', content: message }});
167
+ const chatCompletions: ChatCompletionMessageParam[] = messages.map((message) => {
168
+ return { role: 'user', content: message };
169
+ });
141
170
  if (unshift) {
142
171
  this.history.getMessages().unshift(...chatCompletions);
143
172
  this.history.prune();
144
- } else
173
+ } else {
145
174
  this.history.push(chatCompletions);
175
+ }
146
176
  }
147
177
 
148
178
  async generateResponse(messages: string[], model?: TiktokenModel) {
149
179
  await this.enforceTokenLimit(messages, model);
150
- return await OpenAi.generateResponse(messages, model, this.history, this.functions, this.messageModerators, this.params.logLevel);
180
+ return await OpenAi.generateResponse(
181
+ messages,
182
+ model,
183
+ this.history,
184
+ this.functions,
185
+ this.messageModerators,
186
+ this.params.logLevel
187
+ );
151
188
  }
152
189
 
153
190
  async generateCode(description: string[], model?: TiktokenModel) {
154
191
  this.logger.info(`Generating code for description:\n${description.join('\n')}`);
155
- const code = await OpenAi.generateCode(description, model, this.history, this.functions, this.messageModerators, !this.generatedCode, this.params.logLevel);
192
+ const code = await OpenAi.generateCode(
193
+ description,
194
+ model,
195
+ this.history,
196
+ this.functions,
197
+ this.messageModerators,
198
+ !this.generatedCode,
199
+ this.params.logLevel
200
+ );
156
201
  this.logger.info(`Generated code:\n${code.slice(0, 150)}${code.length > 150 ? '...' : ''}`);
157
202
  this.generatedCode = true;
158
203
  return code;
159
204
  }
160
205
 
161
- async updateCodeFromFile(codeToUpdateFilePath: string, dependencyCodeFilePaths: string[], description: string, model?: TiktokenModel) {
206
+ async updateCodeFromFile(
207
+ codeToUpdateFilePath: string,
208
+ dependencyCodeFilePaths: string[],
209
+ description: string,
210
+ model?: TiktokenModel
211
+ ) {
162
212
  const codeToUpdate = await Fs.readFile(codeToUpdateFilePath);
163
213
  let dependencyDescription = `Assume the following exists:\n`;
164
- for (let dependencyCodeFilePath of dependencyCodeFilePaths) {
214
+ for (const dependencyCodeFilePath of dependencyCodeFilePaths) {
165
215
  const dependencCode = await Fs.readFile(dependencyCodeFilePath);
166
216
  dependencyDescription += dependencCode + '\n\n';
167
217
  }
@@ -171,15 +221,34 @@ export class Conversation {
171
221
  }
172
222
 
173
223
  async updateCode(code: string, description: string, model?: TiktokenModel) {
174
- this.logger.info(`Updating code:\n${code.slice(0, 150)}${code.length > 150 ? '...' : ''}\nFrom description: ${description}`);
175
- const updatedCode = await OpenAi.updateCode(code, description, model, this.history, this.functions, this.messageModerators, !this.generatedCode, this.params.logLevel);
224
+ this.logger.info(
225
+ `Updating code:\n${code.slice(0, 150)}${code.length > 150 ? '...' : ''}\nFrom description: ${description}`
226
+ );
227
+ const updatedCode = await OpenAi.updateCode(
228
+ code,
229
+ description,
230
+ model,
231
+ this.history,
232
+ this.functions,
233
+ this.messageModerators,
234
+ !this.generatedCode,
235
+ this.params.logLevel
236
+ );
176
237
  this.logger.info(`Updated code:\n${updatedCode.slice(0, 150)}${updatedCode.length > 150 ? '...' : ''}`);
177
238
  this.generatedCode = true;
178
239
  return updatedCode;
179
240
  }
180
241
 
181
242
  async generateList(description: string[], model?: TiktokenModel) {
182
- const list = await OpenAi.generateList(description, model, this.history, this.functions, this.messageModerators, !this.generatedList, this.params.logLevel);
243
+ const list = await OpenAi.generateList(
244
+ description,
245
+ model,
246
+ this.history,
247
+ this.functions,
248
+ this.messageModerators,
249
+ !this.generatedList,
250
+ this.params.logLevel
251
+ );
183
252
  this.generatedList = true;
184
253
  return list;
185
254
  }
@@ -199,9 +268,9 @@ export const summarizeConversationHistoryFunction = (conversation: Conversation)
199
268
  description: 'A 1-3 sentence summary of the current chat history',
200
269
  },
201
270
  },
202
- required: ['summary']
271
+ required: ['summary'],
203
272
  },
204
273
  },
205
274
  call: async (params: { summary: string }) => conversation.summarizeConversationHistory(params.summary),
206
- }
207
- }
275
+ };
276
+ };
@@ -2,7 +2,7 @@ import { Function } from './Function';
2
2
  import { MessageModerator } from './history/MessageModerator';
3
3
 
4
4
  export interface ConversationModule {
5
- getName(): string,
5
+ getName(): string;
6
6
  getSystemMessages(): string[];
7
7
  getFunctions(): Function[];
8
8
  getMessageModerators(): MessageModerator[];
@@ -10,4 +10,4 @@ export interface ConversationModule {
10
10
 
11
11
  export interface ConversationModuleFactory {
12
12
  createModule(repoPath: string): Promise<ConversationModule>;
13
- }
13
+ }
package/src/Function.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { ChatCompletionCreateParams } from 'openai/resources/chat';
2
2
 
3
-
4
3
  export interface Function {
5
4
  definition: ChatCompletionCreateParams.Function;
6
5
  call(obj: any): Promise<any>;