-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
99 lines (84 loc) · 3.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import path from 'path';
import readline from 'readline';
import dotenv from 'dotenv';
import colors from 'colors';
const configPath = path.join(process.cwd(), 'interintel.config.js');
import config from './interintel.config.js';
import { readSpecificFiles } from './functions/file-functions.js';
import { askQuestion } from './functions/chat-functions.js';
import { handleWriteFile } from './functions/handleWriteFile.js';
import { chatCompletion } from './serviceInterface.js';
dotenv.config();
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
async function main() {
let initialContent = await readSpecificFiles(configPath);
let messages = [{ role: 'system', content: initialContent }];
let currentState = null;
let promptFileName = '';
while (true) {
const userMessage = await askQuestion(rl, 'You: '.blue.bold);
let response = '';
// Exit condition
if (userMessage.toLowerCase() === 'exit') {
console.log('Exiting chat...'.bgRed);
rl.close();
break;
}
if (userMessage.toLowerCase().startsWith('//writefile') && currentState === null) {
let result = await handleWriteFile(config, messages, currentState, '');
({ currentState, messages, promptFileName, response } = result); // Update messages array
console.log(response.yellow);
} else if (currentState === 'awaitingFileName') {
({ currentState, messages, promptFileName, response } = await handleWriteFile(
config,
messages,
currentState,
userMessage,
promptFileName
));
console.log(response.yellow);
} else if (currentState === 'awaitingAIprompt') {
({ currentState, messages, promptFileName, response } = await handleWriteFile(
config,
messages,
currentState,
userMessage,
promptFileName
));
console.log(response.yellow);
} else if (currentState === null && userMessage.toLowerCase() === '//readrefs') {
console.log('System message:'.bgYellow);
console.log('Processing //readRefs command...'.yellow);
let content = readSpecificFiles(configPath);
messages.push({
role: 'user',
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}`,
});
const completion = await chatCompletion(config.aiService, messages, config.aiVersion);
let botMessage = '';
if (config.aiService === 'openai' || config.aiService === 'mistral') {
botMessage = completion.choices[0].message.content;
} else if (config.aiService === 'ollama') {
// Adjust this line based on how Ollama's response is structured
botMessage = completion;
}
} else {
// Regular message processing and interaction with GPT model
messages.push({ role: 'user', content: userMessage });
const completion = await chatCompletion(config.aiService, messages, config.aiVersion);
let botMessage;
if (config.aiService === 'openai' || config.aiService === 'mistral') {
botMessage = completion.choices[0].message.content;
} else if (config.aiService === 'ollama') {
// Adjust based on Ollama's response format
botMessage = completion; // Example - replace with actual response structure for Ollama
}
console.log(`${config.aiVersion}`.bgGreen, botMessage.green);
console.log('----------------'.bgGreen);
}
}
}
export { main };