Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add automatically the filename : line_nu in log messages, and do some cleaning #2416

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions api/app/clients/AnthropicClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class AnthropicClient extends BaseClient {
parentMessageId,
});

logger.debug('[AnthropicClient] orderedMessages', { orderedMessages, parentMessageId });
logger.debug('orderedMessages', { orderedMessages, parentMessageId });

if (this.options.attachments) {
const attachments = await this.options.attachments;
Expand Down Expand Up @@ -295,7 +295,7 @@ class AnthropicClient extends BaseClient {
return map;
}, {});

logger.debug('[AnthropicClient]', {
logger.debug({
messagesInWindow: messagesInWindow.length,
remainingContextTokens,
});
Expand Down Expand Up @@ -587,7 +587,7 @@ class AnthropicClient extends BaseClient {
requestOptions.system = this.systemMessage;
}

logger.debug('[AnthropicClient]', { ...requestOptions });
logger.debug({ ...requestOptions });

const handleChunk = (currentChunk) => {
if (currentChunk) {
Expand All @@ -606,7 +606,7 @@ class AnthropicClient extends BaseClient {
response = await this.createResponse(client, requestOptions);

signal.addEventListener('abort', () => {
logger.debug('[AnthropicClient] message aborted!');
logger.debug('message aborted!');
if (response.controller?.abort) {
response.controller.abort();
}
Expand Down Expand Up @@ -636,7 +636,7 @@ class AnthropicClient extends BaseClient {
}
} finally {
signal.removeEventListener('abort', () => {
logger.debug('[AnthropicClient] message aborted!');
logger.debug('message aborted!');
if (response.controller?.abort) {
response.controller.abort();
}
Expand Down Expand Up @@ -749,7 +749,7 @@ class AnthropicClient extends BaseClient {
};

await titleChatCompletion();
logger.debug('[AnthropicClient] Convo Title: ' + title);
logger.debug('Convo Title: ' + title);
return title;
}
}
Expand Down
18 changes: 9 additions & 9 deletions api/app/clients/BaseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,14 @@ class BaseClient {
if (instructions) {
({ tokenCount, ..._instructions } = instructions);
}
_instructions && logger.debug('[BaseClient] instructions tokenCount: ' + tokenCount);
_instructions && logger.debug('instructions tokenCount: ' + tokenCount);
let payload = this.addInstructions(formattedMessages, _instructions);
let orderedWithInstructions = this.addInstructions(orderedMessages, instructions);

let { context, remainingContextTokens, messagesToRefine, summaryIndex } =
await this.getMessagesWithinTokenLimit(orderedWithInstructions);

logger.debug('[BaseClient] Context Count (1/2)', {
logger.debug('Context Count (1/2)', {
remainingContextTokens,
maxContextTokens: this.maxContextTokens,
});
Expand Down Expand Up @@ -337,7 +337,7 @@ class BaseClient {
// Make sure to only continue summarization logic if the summary message was generated
shouldSummarize = summaryMessage && shouldSummarize;

logger.debug('[BaseClient] Context Count (2/2)', {
logger.debug('Context Count (2/2)', {
remainingContextTokens,
maxContextTokens: this.maxContextTokens,
});
Expand All @@ -358,8 +358,8 @@ class BaseClient {

const promptTokens = this.maxContextTokens - remainingContextTokens;

logger.debug('[BaseClient] tokenCountMap:', tokenCountMap);
logger.debug('[BaseClient]', {
logger.debug('tokenCountMap:', tokenCountMap);
logger.debug({
promptTokens,
remainingContextTokens,
payloadSize: payload.length,
Expand Down Expand Up @@ -412,10 +412,10 @@ class BaseClient {
);

if (tokenCountMap) {
logger.debug('[BaseClient] tokenCountMap', tokenCountMap);
logger.debug('tokenCountMap', tokenCountMap);
if (tokenCountMap[userMessage.messageId]) {
userMessage.tokenCount = tokenCountMap[userMessage.messageId];
logger.debug('[BaseClient] userMessage', userMessage);
logger.debug('userMessage', userMessage);
}

this.handleTokenCountMap(tokenCountMap);
Expand Down Expand Up @@ -479,7 +479,7 @@ class BaseClient {
}

async loadHistory(conversationId, parentMessageId = null) {
logger.debug('[BaseClient] Loading history:', { conversationId, parentMessageId });
logger.debug('Loading history:', { conversationId, parentMessageId });

const messages = (await getMessages({ conversationId })) ?? [];

Expand Down Expand Up @@ -514,7 +514,7 @@ class BaseClient {

if (this.previous_summary) {
const { messageId, summary, tokenCount, summaryTokenCount } = this.previous_summary;
logger.debug('[BaseClient] Previous summary:', {
logger.debug('Previous summary:', {
messageId,
summary,
tokenCount,
Expand Down
4 changes: 2 additions & 2 deletions api/app/clients/ChatGPTClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class ChatGPTClient extends BaseClient {
...modelOptions,
...this.options.addParams,
};
logger.debug('[ChatGPTClient] chatCompletion: added params', {
logger.debug('chatCompletion: added params', {
addParams: this.options.addParams,
modelOptions,
});
Expand All @@ -303,7 +303,7 @@ class ChatGPTClient extends BaseClient {
this.options.dropParams.forEach((param) => {
delete modelOptions[param];
});
logger.debug('[ChatGPTClient] chatCompletion: dropped params', {
logger.debug('chatCompletion: dropped params', {
dropParams: this.options.dropParams,
modelOptions,
});
Expand Down
4 changes: 2 additions & 2 deletions api/app/clients/GoogleClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class GoogleClient extends BaseClient {
payload.instances[0].examples = this.options.examples;
}

logger.debug('[GoogleClient] buildMessages', payload);
logger.debug('buildMessages', payload);

return { prompt: payload };
}
Expand All @@ -351,7 +351,7 @@ class GoogleClient extends BaseClient {
parentMessageId,
});

logger.debug('[GoogleClient]', {
logger.debug({
orderedMessages,
parentMessageId,
});
Expand Down
28 changes: 14 additions & 14 deletions api/app/clients/OpenAIClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class OpenAIClient extends BaseClient {
}

if (this.options.debug) {
logger.debug('[OpenAIClient] maxContextTokens', this.maxContextTokens);
logger.debug('maxContextTokens', this.maxContextTokens);
}

this.maxResponseTokens = this.modelOptions.max_tokens || 1024;
Expand Down Expand Up @@ -339,7 +339,7 @@ class OpenAIClient extends BaseClient {
resetTokenizersIfNecessary() {
if (tokenizerCallsCount >= 25) {
if (this.options.debug) {
logger.debug('[OpenAIClient] freeAndResetAllEncoders: reached 25 encodings, resetting...');
logger.debug('freeAndResetAllEncoders: reached 25 encodings, resetting...');
}
this.constructor.freeAndResetAllEncoders();
}
Expand Down Expand Up @@ -613,7 +613,7 @@ class OpenAIClient extends BaseClient {
return result.trim();
}

logger.debug('[OpenAIClient] sendCompletion: result', result);
logger.debug('sendCompletion: result', result);

if (this.isChatCompletion) {
reply = result.choices[0].message.content;
Expand Down Expand Up @@ -814,7 +814,7 @@ ${convo}

if (this.options.titleMethod === 'completion') {
await titleChatCompletion();
logger.debug('[OpenAIClient] Convo Title: ' + title);
logger.debug('Convo Title: ' + title);
return title;
}

Expand All @@ -829,7 +829,7 @@ ${convo}
title = await runTitleChain({ llm, text, convo, signal: this.abortController.signal });
} catch (e) {
if (e?.message?.toLowerCase()?.includes('abort')) {
logger.debug('[OpenAIClient] Aborted title generation');
logger.debug('Aborted title generation');
return;
}
logger.error(
Expand All @@ -840,12 +840,12 @@ ${convo}
await titleChatCompletion();
}

logger.debug('[OpenAIClient] Convo Title: ' + title);
logger.debug('Convo Title: ' + title);
return title;
}

async summarizeMessages({ messagesToRefine, remainingContextTokens }) {
logger.debug('[OpenAIClient] Summarizing messages...');
logger.debug('Summarizing messages...');
let context = messagesToRefine;
let prompt;

Expand Down Expand Up @@ -905,7 +905,7 @@ ${convo}
// by recreating the summary prompt (single message) to avoid LangChain handling

const initialPromptTokens = this.maxContextTokens - remainingContextTokens;
logger.debug('[OpenAIClient] initialPromptTokens', initialPromptTokens);
logger.debug('initialPromptTokens', initialPromptTokens);

const llm = this.initializeLLM({
model,
Expand All @@ -931,7 +931,7 @@ ${convo}
const summaryTokenCount = this.getTokenCountForMessage(summaryMessage);

if (this.options.debug) {
logger.debug('[OpenAIClient] summaryTokenCount', summaryTokenCount);
logger.debug('summaryTokenCount', summaryTokenCount);
logger.debug(
`[OpenAIClient] Summarization complete: remainingContextTokens: ${remainingContextTokens}, after refining: ${
remainingContextTokens - summaryTokenCount
Expand All @@ -942,7 +942,7 @@ ${convo}
return { summaryMessage, summaryTokenCount };
} catch (e) {
if (e?.message?.toLowerCase()?.includes('abort')) {
logger.debug('[OpenAIClient] Aborted summarization');
logger.debug('Aborted summarization');
const { run, runId } = this.runManager.getRunByConversationId(this.conversationId);
if (run && run.error) {
const { error } = run;
Expand Down Expand Up @@ -996,7 +996,7 @@ ${convo}
}

const baseURL = extractBaseURL(this.completionsUrl);
logger.debug('[OpenAIClient] chatCompletion', { baseURL, modelOptions });
logger.debug('chatCompletion', { baseURL, modelOptions });
const opts = {
baseURL,
};
Expand Down Expand Up @@ -1104,7 +1104,7 @@ ${convo}
...modelOptions,
...this.options.addParams,
};
logger.debug('[OpenAIClient] chatCompletion: added params', {
logger.debug('chatCompletion: added params', {
addParams: this.options.addParams,
modelOptions,
});
Expand All @@ -1114,7 +1114,7 @@ ${convo}
this.options.dropParams.forEach((param) => {
delete modelOptions[param];
});
logger.debug('[OpenAIClient] chatCompletion: dropped params', {
logger.debug('chatCompletion: dropped params', {
dropParams: this.options.dropParams,
modelOptions,
});
Expand Down Expand Up @@ -1192,7 +1192,7 @@ ${convo}
this.metadata = { finish_reason };
}

logger.debug('[OpenAIClient] chatCompletion response', chatCompletion);
logger.debug('chatCompletion response', chatCompletion);

if (!message?.content?.trim() && intermediateReply.length) {
logger.debug(
Expand Down