Skip to content

Commit

Permalink
fix o1 history
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaki-1052 committed Dec 2, 2024
1 parent 1f924bc commit 4e9f025
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CODESTRAL_API_KEY=your_codestral_ai_key_here
# DEFAULT_MODEL=your_preferred_model

### EXAMPLE:
#DEFAULT_MODEL=claude-3-5-sonnet-20240620
#DEFAULT_MODEL=claude-3-5-sonnet-latest

DEFAULT_MODEL='gpt-4o'

Expand Down
11 changes: 9 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,10 @@ app.post('/setSummariesOnly', (req, res) => {

let chatHistory;
let isClaudeChat = false;
if (containsAssistantMessage) {
if (o1History.length > 0) {
console.log("Using O1 conversation history because it's non-empty.");
chatHistory = o1History;
} else if (containsAssistantMessage && conversationHistory.length > 0) {
console.log("Using GPT conversation history because it's non-empty.");
chatHistory = conversationHistory;
} else {
Expand All @@ -667,7 +670,7 @@ app.post('/setSummariesOnly', (req, res) => {

chatType = 'chat';
const tokens = await tokenizeHistory(chatHistory, modelID, chatType);
console.log("Total Tokens: ", tokens);
// console.log("Total Tokens: ", tokens);
const cost = await calculateCost(tokens, modelID);
console.log("Total Cost: ", cost);

Expand Down Expand Up @@ -2226,6 +2229,10 @@ if (modelID.startsWith('llama-3.1')) {
claudeHistory.push({ role: "assistant", content: lastMessageContent[0].text });
console.log("Claude History");
res.json({ text: lastMessageContent[0].text });
} else if (modelID === 'o1-preview' || modelID === 'o1-mini') {
o1History.push({ role: "assistant", content: lastMessageContent });
console.log("O1 History");
res.json({ text: lastMessageContent });
} else {
// Add assistant's message to the conversation history
conversationHistory.push({ role: "assistant", content: lastMessageContent });
Expand Down

0 comments on commit 4e9f025

Please sign in to comment.