interintel 1.0.20 → 1.0.21
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/functions/handleWriteFile.js +18 -14
- package/functions/openai-functions.js +1 -0
- package/index.js +30 -27
- package/interintel.config.js +3 -3
- package/ollama.js +45 -26
- package/package.json +1 -1
- package/resources/interintel.config.template.js +5 -2
- package/interintel/session-samples/updatedReadSpecificFiles.js +0 -32
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
const { aiChatCompletion } = require('./openai-functions.js');
|
|
1
|
+
const chatCompletion = require('../ollama.js');
|
|
3
2
|
const { writeFileFromPrompt } = require('./file-functions.js');
|
|
4
|
-
const configPath = path.join(process.cwd(), 'interintel.config.js');
|
|
5
|
-
const config = require(configPath);
|
|
6
3
|
|
|
7
|
-
async function handleWriteFile(
|
|
4
|
+
async function handleWriteFile(config, messages, currentState, userInput, promptFileName) {
|
|
8
5
|
let contentToWrite = '';
|
|
9
6
|
|
|
10
7
|
if (currentState === null) {
|
|
@@ -17,28 +14,35 @@ async function handleWriteFile(openai, config, messages, currentState, userInput
|
|
|
17
14
|
};
|
|
18
15
|
} else if (currentState === 'awaitingFileName') {
|
|
19
16
|
promptFileName = userInput;
|
|
20
|
-
currentState = '
|
|
17
|
+
currentState = 'awaitingAIprompt';
|
|
21
18
|
return {
|
|
22
19
|
currentState,
|
|
23
20
|
messages,
|
|
24
21
|
promptFileName,
|
|
25
22
|
response: `Please provide a prompt for ${config.aiVersion}:`,
|
|
26
23
|
};
|
|
27
|
-
} else if (currentState === '
|
|
28
|
-
const
|
|
24
|
+
} else if (currentState === 'awaitingAIprompt') {
|
|
25
|
+
const promptForAI = userInput;
|
|
26
|
+
|
|
27
|
+
let updatedMessages = [...messages, { role: 'user', content: promptForAI }];
|
|
28
|
+
|
|
29
29
|
try {
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
let completionResponse = await chatCompletion(
|
|
31
|
+
config.aiService,
|
|
32
|
+
updatedMessages,
|
|
33
33
|
config.aiVersion
|
|
34
34
|
);
|
|
35
|
-
|
|
35
|
+
|
|
36
|
+
// Extract the response content
|
|
37
|
+
let contentToWrite = (config.aiService === 'openai') ?
|
|
38
|
+
completionResponse.choices[0].message.content : completionResponse;
|
|
39
|
+
|
|
36
40
|
await writeFileFromPrompt(promptFileName, contentToWrite, __dirname); // Assuming this function handles file writing
|
|
37
41
|
|
|
38
42
|
currentState = null; // Reset state after completing the operation
|
|
39
43
|
return {
|
|
40
44
|
currentState,
|
|
41
|
-
messages,
|
|
45
|
+
messages: updatedMessages,
|
|
42
46
|
promptFileName,
|
|
43
47
|
contentToWrite,
|
|
44
48
|
response: `Content written to ${promptFileName}`.yellow,
|
|
@@ -47,7 +51,7 @@ async function handleWriteFile(openai, config, messages, currentState, userInput
|
|
|
47
51
|
console.error('Error in handleWriteFile:', error);
|
|
48
52
|
return {
|
|
49
53
|
currentState,
|
|
50
|
-
messages,
|
|
54
|
+
messages: updatedMessages, // Return the updated messages array
|
|
51
55
|
promptFileName,
|
|
52
56
|
contentToWrite,
|
|
53
57
|
response: 'An error occurred while writing the file.',
|
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const OpenAI = require('openai');
|
|
1
|
+
const path = require('path');
|
|
3
2
|
const readline = require('readline');
|
|
4
3
|
const configPath = path.join(process.cwd(), 'interintel.config.js');
|
|
5
4
|
const config = require(configPath);
|
|
@@ -8,13 +7,8 @@ require('colors');
|
|
|
8
7
|
|
|
9
8
|
const { readSpecificFiles } = require('./functions/file-functions.js');
|
|
10
9
|
const { askQuestion } = require('./functions/chat-functions.js');
|
|
11
|
-
const { aiChatCompletion } = require('./functions/openai-functions.js');
|
|
12
10
|
const { handleWriteFile } = require('./functions/handleWriteFile.js');
|
|
13
|
-
|
|
14
|
-
const openai = new OpenAI({
|
|
15
|
-
apiKey: config.apiKey,
|
|
16
|
-
model: config.aiVersion,
|
|
17
|
-
});
|
|
11
|
+
const chatCompletion = require('./ollama.js');
|
|
18
12
|
|
|
19
13
|
const rl = readline.createInterface({
|
|
20
14
|
input: process.stdin,
|
|
@@ -30,7 +24,7 @@ async function main() {
|
|
|
30
24
|
|
|
31
25
|
while (true) {
|
|
32
26
|
const userMessage = await askQuestion(rl, 'You: '.blue.bold);
|
|
33
|
-
let response = '';
|
|
27
|
+
let response = '';
|
|
34
28
|
|
|
35
29
|
// Exit condition
|
|
36
30
|
if (userMessage.toLowerCase() === 'exit') {
|
|
@@ -40,17 +34,16 @@ async function main() {
|
|
|
40
34
|
}
|
|
41
35
|
|
|
42
36
|
if (userMessage.toLowerCase().startsWith('//writefile') && currentState === null) {
|
|
43
|
-
|
|
44
|
-
openai,
|
|
37
|
+
let result = await handleWriteFile(
|
|
45
38
|
config,
|
|
46
39
|
messages,
|
|
47
40
|
currentState,
|
|
48
41
|
''
|
|
49
|
-
)
|
|
42
|
+
);
|
|
43
|
+
({ currentState, messages, promptFileName, response } = result); // Update messages array
|
|
50
44
|
console.log(response.yellow);
|
|
51
45
|
} else if (currentState === 'awaitingFileName') {
|
|
52
46
|
({ currentState, messages, promptFileName, response } = await handleWriteFile(
|
|
53
|
-
openai,
|
|
54
47
|
config,
|
|
55
48
|
messages,
|
|
56
49
|
currentState,
|
|
@@ -58,9 +51,8 @@ async function main() {
|
|
|
58
51
|
promptFileName
|
|
59
52
|
));
|
|
60
53
|
console.log(response.yellow);
|
|
61
|
-
} else if (currentState === '
|
|
54
|
+
} else if (currentState === 'awaitingAIprompt') {
|
|
62
55
|
({ currentState, messages, promptFileName, response } = await handleWriteFile(
|
|
63
|
-
openai,
|
|
64
56
|
config,
|
|
65
57
|
messages,
|
|
66
58
|
currentState,
|
|
@@ -75,27 +67,38 @@ async function main() {
|
|
|
75
67
|
let content = readSpecificFiles(configPath);
|
|
76
68
|
messages.push({
|
|
77
69
|
role: 'user',
|
|
78
|
-
content: `please just acknowledge you have read the name and the content of the files I have provided ${content}`,
|
|
70
|
+
content: `please just acknowledge you have read the name and the content of the files I have provided. once you have done this a single time you do not need to do it again. ${content}`,
|
|
79
71
|
});
|
|
80
|
-
const completion = await
|
|
72
|
+
const completion = await chatCompletion(config.aiService, messages, config.aiVersion);
|
|
81
73
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
74
|
+
let botMessage;
|
|
75
|
+
|
|
76
|
+
if (config.aiService === 'openai') {
|
|
77
|
+
botMessage = completion.choices[0].message.content;
|
|
78
|
+
} else if (config.aiService === 'ollama') {
|
|
79
|
+
// Adjust this line based on how Ollama's response is structured
|
|
80
|
+
botMessage = completion;
|
|
81
|
+
}
|
|
85
82
|
} else {
|
|
86
83
|
// Regular message processing and interaction with GPT model
|
|
87
84
|
messages.push({ role: 'user', content: userMessage });
|
|
88
85
|
|
|
89
|
-
const completion = await
|
|
86
|
+
const completion = await chatCompletion(config.aiService, messages, config.aiVersion);
|
|
87
|
+
|
|
88
|
+
let botMessage;
|
|
89
|
+
if (config.aiService === 'openai') {
|
|
90
|
+
botMessage = completion.choices[0].message.content;
|
|
91
|
+
} else if (config.aiService === 'ollama') {
|
|
92
|
+
// Adjust based on Ollama's response format
|
|
93
|
+
botMessage = completion; // Example - replace with actual response structure for Ollama
|
|
94
|
+
}
|
|
90
95
|
|
|
91
|
-
|
|
92
|
-
console.log(`${config.aiVersion}`.bgGreen, botMessage);
|
|
96
|
+
console.log(`${config.aiVersion}`.bgGreen, botMessage.green);
|
|
93
97
|
console.log('----------------'.bgGreen);
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
|
|
98
|
-
exports.main = function() {
|
|
99
|
-
main()
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
+
exports.main = function () {
|
|
103
|
+
main();
|
|
104
|
+
};
|
package/interintel.config.js
CHANGED
|
@@ -2,9 +2,9 @@ require('dotenv').config();
|
|
|
2
2
|
|
|
3
3
|
const config = {
|
|
4
4
|
apiKey: `${process.env.OPENAI_API_KEY}`,
|
|
5
|
-
|
|
6
|
-
aiVersion: `
|
|
7
|
-
filePaths: ['./
|
|
5
|
+
aiService: 'ollama',
|
|
6
|
+
aiVersion: `mistral`,
|
|
7
|
+
filePaths: ['./functions/openai-functions.js', './README.md'],
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
module.exports = config;
|
package/ollama.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
const path = require('path');
|
|
1
2
|
const fetch = require('node-fetch');
|
|
3
|
+
const OpenAI = require('openai');
|
|
4
|
+
const configPath = path.join(process.cwd(), 'interintel.config.js');
|
|
5
|
+
const config = require(configPath);
|
|
6
|
+
|
|
7
|
+
const openai = new OpenAI({
|
|
8
|
+
apiKey: config.apiKey,
|
|
9
|
+
model: config.aiVersion,
|
|
10
|
+
});
|
|
2
11
|
|
|
3
12
|
let ai = 'ollama';
|
|
4
13
|
let messages = [
|
|
@@ -6,36 +15,46 @@ let messages = [
|
|
|
6
15
|
role: 'assistant',
|
|
7
16
|
content: 'please use a respectful tone',
|
|
8
17
|
},
|
|
9
|
-
{
|
|
10
|
-
role: 'assistant',
|
|
11
|
-
content: 'when asked for a code reference, please provide only the code with no commentary or explanation just the code. No commentary or explanation. NO COMMENTARY OR EXPLANATION',
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
role: 'user',
|
|
15
|
-
content: 'how can I most effectively persist chat history with you? Is every conversation then dependent on a finding a way to persist history by sending along the ongoing chat for you to continually reference context?',
|
|
16
|
-
},
|
|
17
18
|
];
|
|
18
19
|
let model = 'mistral';
|
|
19
20
|
|
|
20
|
-
async function
|
|
21
|
-
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
async function chatCompletion(aiService, messages, model) {
|
|
22
|
+
try {
|
|
23
|
+
let response;
|
|
24
|
+
|
|
25
|
+
if (aiService === 'openai') {
|
|
26
|
+
response = await openai.chat.completions.create({
|
|
27
|
+
messages: messages,
|
|
28
|
+
model: model,
|
|
29
|
+
stream: false,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return response;
|
|
33
|
+
} else if (aiService === 'ollama') {
|
|
34
|
+
// Ollama specific code
|
|
35
|
+
let data = {
|
|
36
|
+
messages,
|
|
37
|
+
model,
|
|
38
|
+
stream: false,
|
|
39
|
+
};
|
|
40
|
+
const fetchResponse = await fetch('http://localhost:11434/api/chat', {
|
|
41
|
+
method: 'POST',
|
|
42
|
+
headers: {
|
|
43
|
+
'Content-Type': 'application/json',
|
|
44
|
+
},
|
|
45
|
+
body: JSON.stringify(data),
|
|
46
|
+
});
|
|
27
47
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.catch((error) => console.error('Error:', error));
|
|
48
|
+
// Properly resolve the response
|
|
49
|
+
response = await fetchResponse.json();
|
|
50
|
+
return response.message.content;
|
|
51
|
+
} else {
|
|
52
|
+
throw new Error('Invalid AI service');
|
|
53
|
+
}
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('Error:', error);
|
|
56
|
+
return null;
|
|
38
57
|
}
|
|
39
58
|
}
|
|
40
59
|
|
|
41
|
-
|
|
60
|
+
module.exports = chatCompletion;
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
},
|
|
7
7
|
"name": "interintel",
|
|
8
8
|
"description": "The application `Interintel` is a command line interface (CLI) application implemented in Node.js. It essentially is an interactive communication tool between the user and an AI model, only openai models for now.",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.21",
|
|
10
10
|
"main": "index.js",
|
|
11
11
|
"directories": {
|
|
12
12
|
"doc": "docs"
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
require('dotenv').config();
|
|
2
2
|
|
|
3
3
|
const config = {
|
|
4
|
+
// this is service dependent
|
|
4
5
|
apiKey: `${process.env.OPENAI_API_KEY}`,
|
|
5
|
-
//
|
|
6
|
-
|
|
6
|
+
// openai || ollama
|
|
7
|
+
aiService: 'ONE_OF_THE_ABOVE',
|
|
8
|
+
// only open ai or ollama models for now
|
|
9
|
+
aiVersion: `ONLY_USE_OPENAI_OR_OLLAMA_MODELS`,
|
|
7
10
|
// These filepaths are relative to where your config is created
|
|
8
11
|
filePaths: ['interintel/interintelReadMe.md'],
|
|
9
12
|
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// role: 'system',
|
|
2
|
-
// content: `I am sharing information from my file system for reference in our chat.\n
|
|
3
|
-
// File Name: ${fileMsg.fileName}\nContent:\n${fileMsg.content}
|
|
4
|
-
// \n Content for File Name: ${fileMsg.fileName}`
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function readSpecificFiles(configFilePath) {
|
|
8
|
-
try {
|
|
9
|
-
const configContent = fs.readFileSync(configFilePath, 'utf8');
|
|
10
|
-
const config = eval(configContent);
|
|
11
|
-
const filePaths = config.filePaths;
|
|
12
|
-
const configDir = path.dirname(configFilePath);
|
|
13
|
-
|
|
14
|
-
let allContent = 'I am sharing information from my file system for reference in our chat.\n';
|
|
15
|
-
|
|
16
|
-
filePaths.forEach((filePath) => {
|
|
17
|
-
try {
|
|
18
|
-
const absolutePath = path.resolve(configDir, filePath);
|
|
19
|
-
const fileContent = fs.readFileSync(absolutePath, 'utf8');
|
|
20
|
-
|
|
21
|
-
allContent += `\nFile Name: ${filePath}\nContent:\n${fileContent}\n`;
|
|
22
|
-
} catch (error) {
|
|
23
|
-
console.error(`Error reading file ${filePath}: ${error.message}`.bgRed);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
return allContent;
|
|
28
|
-
} catch (error) {
|
|
29
|
-
console.error(`Error reading config file: ${error.message}`.bgRed);
|
|
30
|
-
return '';
|
|
31
|
-
}
|
|
32
|
-
}
|