Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaki-1052 committed Jun 29, 2024
1 parent 50fc7a9 commit b263acc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Empty file removed public/uploads/chats/.gitkeep
Empty file.
19 changes: 12 additions & 7 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ async function initializeConversationHistory() {
const fileInstructions = await readInstructionsFile();
systemMessage = `You are a helpful and intelligent AI assistant, knowledgeable about a wide range of topics and highly capable of a great many tasks.\n Specifically:\n ${fileInstructions}`;
if (continueConv) {
console.log("continue conversation", continueConv);
if (summariesOnly) {
console.log("summaries only", summariesOnly);
const contextAndSummary = await continueConversation(chosenChat);
Expand All @@ -358,12 +359,10 @@ async function initializeConversationHistory() {
}

}
conversationHistory.push({ role: "system", content: systemMessage });
return systemMessage;
}

// Call this function when the server starts
initializeConversationHistory();

async function initializeSystem() {
const systemMessage = await initializeConversationHistory();
Expand Down Expand Up @@ -405,7 +404,6 @@ async function initializeGeminiConversationHistory() {
}

// Call this function when the server starts
initializeGeminiConversationHistory();



Expand All @@ -415,7 +413,6 @@ async function continueConversation(chosenChat) {
// Read the chosen chat file
const conversationFile = await fs.promises.readFile(path.join(__dirname, 'public/uploads/chats', `${chosenChat}.txt`), 'utf8');
if (summariesOnly) {
console.log("summaries only regex", summariesOnly);
// Regex to extract everything starting from CONTEXT
const regex = /\n\n-----\n\n(.+)/s;
const match = conversationFile.match(regex);
Expand Down Expand Up @@ -539,7 +536,7 @@ app.post('/setSummariesOnly', (req, res) => {
return '';
}).join('\n');

console.log(savedHistory);
// console.log(savedHistory);

chatType = 'chat';
const tokens = await tokenizeHistory(chatHistory, modelID, chatType);
Expand Down Expand Up @@ -882,7 +879,7 @@ async function exportGeminiChatToHTML() {

chatType = 'gemini';
const tokens = await tokenizeHistory(geminiHistory, modelID, chatType);
console.log(tokens);
console.log(tokens.totalTokens);
// process chat history in a similar way
const { title, summary } = await nameChat(geminiHistory, tokens);
console.log(`Title: ${title}`);
Expand Down Expand Up @@ -968,7 +965,6 @@ async function initializeClaudeInstructions() {
}

// Call this function when the server starts
initializeClaudeInstructions();


let prompt;
Expand Down Expand Up @@ -1450,6 +1446,7 @@ const defaultConfig = {

app.post('/gemini', async (req, res) => {
try {
initializeGeminiConversationHistory();
const { model, prompt, imageParts, history } = req.body;
console.log('Prompt: ', prompt)
isAssistants = false;
Expand Down Expand Up @@ -1638,6 +1635,14 @@ if (user_message === "Bye!") {
// Assuming modelID is declared globally and available here
// Determine the structure of user_input.content based on modelID
if (modelID.startsWith('gpt') || modelID.startsWith('claude')) {

if (modelID.startsWith('gpt')) {
systemMessage = await initializeConversationHistory();
} else if (modelID.startsWith('claude')) {
systemMessage = await initializeClaudeInstructions();
}

conversationHistory.push({ role: "system", content: systemMessage });

// Add text content if present
if (user_message) {
Expand Down

0 comments on commit b263acc

Please sign in to comment.