Skip to content

Commit c4eb9f3

Browse files
Tomobobo710Rishabh4275Pulkit Juneja
authored
Feature/implement conductor generation (#76)
* Initial toggleable implementation * Remove sequential generator, conductor toggle * Move simple chat, check memory in one place * Minor cleanups * Don't add user message twice * Be a lot smarter about tool detection * Remove bogus model settings * Try to fix build errors * Try again * PR comment fixes and cleanup * UTs * Add thinking state and improve prompts * Something more * Testing with some logs * Removed initial phase from conductor WIP * WIP testing 3 phase approach * Testing with Phase 1+2 combined * Test fixes and linting --------- Co-authored-by: Rishabh Chawla <rishabhchawla1995@gmail.com> Co-authored-by: Pulkit Juneja <pulkitjuneja2@gmail.com>
1 parent e7eec56 commit c4eb9f3

27 files changed

Lines changed: 4205 additions & 4049 deletions

package-lock.json

Lines changed: 853 additions & 660 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/app/package-lock.json

Lines changed: 307 additions & 2788 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cobolt-backend/chat.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import * as readline from 'readline';
22
import { queryEngineInstance } from './query_engine';
33
import { RequestContext } from './logger';
44
import { ChatHistory } from './chat_history';
5+
import log from 'electron-log/main';
56

67
async function main() {
78
const rl = readline.createInterface({
89
input: process.stdin,
910
output: process.stdout,
1011
});
1112

12-
console.log("Chat with AI (type 'exit' to quit)");
13-
console.log("Available modes: chat, contextaware");
14-
console.log("Usage: /mode <mode> to switch modes (e.g. /mode contextaware)");
13+
log.info("Chat with AI (type 'exit' to quit)");
14+
log.info("Available modes: chat, contextaware");
15+
log.info("Usage: /mode <mode> to switch modes (e.g. /mode contextaware)");
1516

1617
const askQuestion = (): Promise<string> => {
1718
return new Promise((resolve) => {
@@ -21,15 +22,15 @@ async function main() {
2122
});
2223
};
2324

24-
let currentMode: 'CHAT' | 'CONTEXT_AWARE' = 'CHAT';
25+
let currentMode: 'CHAT' | 'CONTEXT_AWARE' = 'CONTEXT_AWARE';
2526
const chatHistory = new ChatHistory();
2627

2728
try {
2829
for (;;) {
2930
const userInput = await askQuestion();
3031

3132
if (userInput.toLowerCase() === "exit") {
32-
console.log("Goodbye!");
33+
log.info("Goodbye!");
3334
rl.close();
3435
break;
3536
}
@@ -38,10 +39,10 @@ async function main() {
3839
const mode = userInput.slice(6).toUpperCase();
3940
if (['CHAT', 'CONTEXT_AWARE'].includes(mode)) {
4041
currentMode = mode as 'CHAT' | 'CONTEXT_AWARE';
41-
console.log(`Switched to ${currentMode} mode`);
42+
log.info(`Switched to ${currentMode} mode`);
4243
continue;
4344
} else {
44-
console.log("Invalid mode. Available modes: chat, contextaware");
45+
log.info("Invalid mode. Available modes: chat, contextaware");
4546
continue;
4647
}
4748
}
@@ -55,23 +56,22 @@ async function main() {
5556

5657
chatHistory.addUserMessage(userInput);
5758

58-
console.log("AI: ");
59+
log.info("AI: ");
5960
let response = "";
6061
const stream = await queryEngineInstance.query(requestContext, currentMode);
6162

6263
for await (const chunk of stream) {
6364
process.stdout.write(chunk);
6465
response += chunk;
6566
}
66-
console.log("\n");
67+
log.info("\n");
6768

6869
chatHistory.addAssistantMessage(response);
6970
}
7071
} catch (error) {
71-
console.error("An error occurred:", error);
72+
log.error("An error occurred:", error);
7273
rl.close();
7374
}
7475
}
7576

76-
main().catch(console.error);
77-
77+
main().catch(log.error);

src/cobolt-backend/chat_history.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,44 @@ class ChatHistory {
5656

5757
/**
5858
* Convert chat history to format used by Ollama LLM
59-
* @returns Array of Message objects in Ollama format
59+
* Removes execution event metadata from AI context
60+
* @returns Array of Message objects in Ollama format with clean content
6061
*/
6162
toOllamaMessages(): Message[] {
6263
return this.messages.map(message => ({
6364
role: message.role,
64-
content: message.content
65+
content: this.cleanContentForAI(message.content)
6566
}));
6667
}
6768

69+
/**
70+
* Clean content for AI context - removes ALL execution metadata
71+
* This prevents AI from learning how to fake execution patterns
72+
*/
73+
private cleanContentForAI(content: string): string {
74+
let cleaned = content;
75+
76+
// AGGRESSIVE CLEANING: Remove ALL XML-like tags that start with these patterns
77+
cleaned = cleaned.replace(/<execution_event\b[^>]*>.*?<\/execution_event>/gs, '');
78+
cleaned = cleaned.replace(/<tool_call_position\b[^>]*>/g, '');
79+
cleaned = cleaned.replace(/<tool_calls_update\b[^>]*>.*?<\/tool_calls_update>/gs, '');
80+
cleaned = cleaned.replace(/<tool_calls_complete\b[^>]*>.*?<\/tool_calls_complete>/gs, '');
81+
cleaned = cleaned.replace(/<tool_calls\b[^>]*>.*?<\/tool_calls>/gs, '');
82+
83+
// Remove standalone closing tags that might be left behind
84+
cleaned = cleaned.replace(/<\/(?:execution_event|tool_calls_update|tool_calls_complete|tool_calls|tool_call_position)>/g, '');
85+
86+
// Remove any remaining XML-like execution metadata
87+
cleaned = cleaned.replace(/<[^>]*(?:execution|tool_call|metadata|event)[^>]*>.*?<\/[^>]+>/gs, '');
88+
89+
// Clean up any excessive whitespace left behind
90+
cleaned = cleaned.replace(/\n\s*\n\s*\n/g, '\n\n');
91+
cleaned = cleaned.replace(/^\s+|\s+$/gm, ''); // Trim each line
92+
cleaned = cleaned.trim();
93+
94+
return cleaned;
95+
}
96+
6897
/**
6998
* Clear the chat history
7099
*/

0 commit comments

Comments
 (0)