@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.
- package/.eslintrc.js +20 -0
- package/.prettierrc +8 -0
- package/CHANGELOG.md +7 -4
- package/LICENSE +21 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +40 -28
- package/dist/src/CodegenConversation.d.ts +11 -11
- package/dist/src/CodegenConversation.d.ts.map +1 -1
- package/dist/src/CodegenConversation.js +294 -180
- package/dist/src/CodegenConversation.js.map +1 -1
- package/dist/src/Conversation.d.ts +52 -49
- package/dist/src/Conversation.d.ts.map +1 -1
- package/dist/src/Conversation.js +480 -274
- package/dist/src/Conversation.js.map +1 -1
- package/dist/src/ConversationModule.d.ts +6 -6
- package/dist/src/ConversationModule.js +3 -3
- package/dist/src/Function.d.ts +4 -4
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Function.js +3 -3
- package/dist/src/OpenAi.d.ts +42 -10
- package/dist/src/OpenAi.d.ts.map +1 -1
- package/dist/src/OpenAi.js +496 -289
- package/dist/src/OpenAi.js.map +1 -1
- package/dist/src/Paragraph.d.ts +4 -4
- package/dist/src/Paragraph.d.ts.map +1 -1
- package/dist/src/Paragraph.js +17 -16
- package/dist/src/Paragraph.js.map +1 -1
- package/dist/src/Sentence.d.ts +4 -4
- package/dist/src/Sentence.d.ts.map +1 -1
- package/dist/src/Sentence.js +21 -19
- package/dist/src/Sentence.js.map +1 -1
- package/dist/src/code_template/Code.d.ts +15 -15
- package/dist/src/code_template/Code.d.ts.map +1 -1
- package/dist/src/code_template/Code.js +167 -69
- package/dist/src/code_template/Code.js.map +1 -1
- package/dist/src/code_template/CodeTemplate.d.ts +11 -11
- package/dist/src/code_template/CodeTemplate.d.ts.map +1 -1
- package/dist/src/code_template/CodeTemplate.js +169 -79
- package/dist/src/code_template/CodeTemplate.js.map +1 -1
- package/dist/src/code_template/CodeTemplateModule.d.ts +6 -6
- package/dist/src/code_template/CodeTemplateModule.js +28 -26
- package/dist/src/code_template/Repo.d.ts +34 -38
- package/dist/src/code_template/Repo.d.ts.map +1 -1
- package/dist/src/code_template/Repo.js +291 -191
- package/dist/src/code_template/Repo.js.map +1 -1
- package/dist/src/fs/conversation_fs/ConversationFsModerator.d.ts +12 -12
- package/dist/src/fs/conversation_fs/ConversationFsModerator.d.ts.map +1 -1
- package/dist/src/fs/conversation_fs/ConversationFsModerator.js +111 -98
- package/dist/src/fs/conversation_fs/ConversationFsModerator.js.map +1 -1
- package/dist/src/fs/conversation_fs/ConversationFsModule.d.ts +11 -11
- package/dist/src/fs/conversation_fs/ConversationFsModule.d.ts.map +1 -1
- package/dist/src/fs/conversation_fs/ConversationFsModule.js +204 -99
- package/dist/src/fs/conversation_fs/ConversationFsModule.js.map +1 -1
- package/dist/src/fs/conversation_fs/FsFunctions.d.ts +58 -62
- package/dist/src/fs/conversation_fs/FsFunctions.d.ts.map +1 -1
- package/dist/src/fs/conversation_fs/FsFunctions.js +414 -266
- package/dist/src/fs/conversation_fs/FsFunctions.js.map +1 -1
- package/dist/src/fs/git/GitModule.d.ts +8 -8
- package/dist/src/fs/git/GitModule.d.ts.map +1 -1
- package/dist/src/fs/git/GitModule.js +163 -74
- package/dist/src/fs/git/GitModule.js.map +1 -1
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.d.ts +16 -18
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.d.ts.map +1 -1
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.js +158 -58
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.js.map +1 -1
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.d.ts +27 -26
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.d.ts.map +1 -1
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js +234 -133
- package/dist/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.js.map +1 -1
- package/dist/src/fs/package/PackageFunctions.d.ts +54 -60
- package/dist/src/fs/package/PackageFunctions.d.ts.map +1 -1
- package/dist/src/fs/package/PackageFunctions.js +366 -223
- package/dist/src/fs/package/PackageFunctions.js.map +1 -1
- package/dist/src/fs/package/PackageModule.d.ts +24 -24
- package/dist/src/fs/package/PackageModule.d.ts.map +1 -1
- package/dist/src/fs/package/PackageModule.js +292 -163
- package/dist/src/fs/package/PackageModule.js.map +1 -1
- package/dist/src/history/MessageHistory.d.ts +12 -12
- package/dist/src/history/MessageHistory.d.ts.map +1 -1
- package/dist/src/history/MessageHistory.js +52 -43
- package/dist/src/history/MessageHistory.js.map +1 -1
- package/dist/src/history/MessageModerator.d.ts +2 -2
- package/dist/src/history/MessageModerator.js +3 -3
- package/dist/src/template/ConversationTemplate.d.ts +8 -8
- package/dist/src/template/ConversationTemplate.d.ts.map +1 -1
- package/dist/src/template/ConversationTemplate.js +3 -3
- package/dist/src/template/ConversationTemplateFunctions.d.ts +33 -35
- package/dist/src/template/ConversationTemplateFunctions.d.ts.map +1 -1
- package/dist/src/template/ConversationTemplateFunctions.js +176 -75
- package/dist/src/template/ConversationTemplateFunctions.js.map +1 -1
- package/dist/src/template/ConversationTemplateModule.d.ts +51 -48
- package/dist/src/template/ConversationTemplateModule.d.ts.map +1 -1
- package/dist/src/template/ConversationTemplateModule.js +211 -114
- package/dist/src/template/ConversationTemplateModule.js.map +1 -1
- package/dist/src/template/createApp/CreateAppTemplate.d.ts +1 -1
- package/dist/src/template/createApp/CreateAppTemplate.js +151 -59
- package/dist/src/template/createCode/CreateCodeConversationTemplate.d.ts +1 -1
- package/dist/src/template/createCode/CreateCodeConversationTemplate.d.ts.map +1 -1
- package/dist/src/template/createCode/CreateCodeConversationTemplate.js +183 -74
- package/dist/src/template/createCode/CreateCodeConversationTemplate.js.map +1 -1
- package/dist/src/template/createPackage/CreatePackageConversationTemplate.d.ts +1 -1
- package/dist/src/template/createPackage/CreatePackageConversationTemplate.d.ts.map +1 -1
- package/dist/src/template/createPackage/CreatePackageConversationTemplate.js +174 -84
- package/dist/src/template/createPackage/CreatePackageConversationTemplate.js.map +1 -1
- package/dist/src/template/createPackage/tsconfig.json +11 -11
- package/dist/test/createKeywordFilesIndex.test.d.ts +1 -1
- package/dist/test/createKeywordFilesIndex.test.js +132 -41
- package/dist/test/createKeywordFilesIndex.test.js.map +1 -1
- package/dist/test/openai/openai.generateList.test.d.ts +1 -1
- package/dist/test/openai/openai.generateList.test.js +136 -47
- package/dist/test/openai/openai.generateList.test.js.map +1 -1
- package/dist/test/openai/openai.parseCodeFromMarkdown.test.d.ts +1 -1
- package/dist/test/openai/openai.parseCodeFromMarkdown.test.js +15 -10
- package/dist/test/openai/openai.parseCodeFromMarkdown.test.js.map +1 -1
- package/dist/test/repo/repo.test.d.ts +1 -1
- package/dist/test/repo/repo.test.js +127 -38
- package/dist/test/repo/repo.test.js.map +1 -1
- package/jest.config.js +2 -2
- package/package.json +11 -5
- package/src/CodegenConversation.ts +6 -4
- package/src/Conversation.ts +102 -33
- package/src/ConversationModule.ts +2 -2
- package/src/Function.ts +0 -1
- package/src/OpenAi.ts +128 -63
- package/src/Paragraph.ts +3 -2
- package/src/Sentence.ts +5 -3
- package/src/code_template/Code.ts +25 -19
- package/src/code_template/CodeTemplate.ts +8 -7
- package/src/code_template/CodeTemplateModule.ts +2 -2
- package/src/code_template/Repo.ts +25 -19
- package/src/fs/conversation_fs/ConversationFsModerator.ts +34 -20
- package/src/fs/conversation_fs/ConversationFsModule.ts +13 -7
- package/src/fs/conversation_fs/FsFunctions.ts +33 -44
- package/src/fs/git/GitModule.ts +2 -4
- package/src/fs/keyword_to_files_index/KeywordToFilesIndexFunctions.ts +31 -31
- package/src/fs/keyword_to_files_index/KeywordToFilesIndexModule.ts +19 -18
- package/src/fs/package/PackageFunctions.ts +34 -41
- package/src/fs/package/PackageModule.ts +33 -21
- package/src/history/MessageHistory.ts +7 -4
- package/src/history/MessageModerator.ts +1 -1
- package/src/template/ConversationTemplate.ts +9 -9
- package/src/template/ConversationTemplateFunctions.ts +8 -7
- package/src/template/ConversationTemplateModule.ts +24 -15
- package/src/template/createApp/CreateAppTemplate.ts +1 -1
- package/src/template/createCode/CreateCodeConversationTemplate.ts +9 -11
- package/src/template/createPackage/CreatePackageConversationTemplate.ts +2 -9
- package/src/template/createPackage/jest.config.js +2 -2
- package/test/createKeywordFilesIndex.test.ts +3 -3
- package/test/openai/openai.generateList.test.ts +5 -3
- package/test/openai/openai.parseCodeFromMarkdown.test.ts +10 -5
- package/test/repo/repo.test.ts +3 -4
- package/tsconfig.json +16 -20
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/conversation",
|
|
3
|
-
"version": "1.0.
|
|
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/
|
|
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.
|
|
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 (
|
|
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
|
+
}
|
package/src/Conversation.ts
CHANGED
|
@@ -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({
|
|
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 (
|
|
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 (
|
|
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(
|
|
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(
|
|
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 => {
|
|
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 => {
|
|
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 => {
|
|
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(
|
|
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(
|
|
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(
|
|
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 (
|
|
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(
|
|
175
|
-
|
|
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(
|
|
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
|
+
}
|