mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2025-12-26 06:28:56 +08:00
fix: logger
This commit is contained in:
parent
76dc568e52
commit
a179807c5a
@ -267,7 +267,7 @@ async function updateReferences(thisStep: AnswerAction, allURLs: Record<string,
|
|||||||
ref.dateTime = await getLastModified(ref.url) || '';
|
ref.dateTime = await getLastModified(ref.url) || '';
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console.log('Updated references:', thisStep.references);
|
logDebug('Updated references:', { references: thisStep.references });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function executeSearchQueries(
|
async function executeSearchQueries(
|
||||||
|
|||||||
@ -313,7 +313,7 @@ if (secret) {
|
|||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
const authHeader = req.headers.authorization;
|
const authHeader = req.headers.authorization;
|
||||||
if (!authHeader || !authHeader.startsWith('Bearer ') || authHeader.split(' ')[1] !== secret) {
|
if (!authHeader || !authHeader.startsWith('Bearer ') || authHeader.split(' ')[1] !== secret) {
|
||||||
console.log('[chat/completions] Unauthorized request');
|
logError('[chat/completions] Unauthorized request');
|
||||||
res.status(401).json({ error: 'Unauthorized' });
|
res.status(401).json({ error: 'Unauthorized' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -380,7 +380,7 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
|
|||||||
if (secret) {
|
if (secret) {
|
||||||
const authHeader = req.headers.authorization;
|
const authHeader = req.headers.authorization;
|
||||||
if (!authHeader || !authHeader.startsWith('Bearer ') || authHeader.split(' ')[1] !== secret) {
|
if (!authHeader || !authHeader.startsWith('Bearer ') || authHeader.split(' ')[1] !== secret) {
|
||||||
console.log('[chat/completions] Unauthorized request');
|
logError('[chat/completions] Unauthorized request');
|
||||||
res.status(401).json({ error: 'Unauthorized' });
|
res.status(401).json({ error: 'Unauthorized' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -392,7 +392,7 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
|
|||||||
req.socket.remoteAddress ||
|
req.socket.remoteAddress ||
|
||||||
'unknown';
|
'unknown';
|
||||||
// Log request details (excluding sensitive data)
|
// Log request details (excluding sensitive data)
|
||||||
console.log('[chat/completions] Request:', {
|
logInfo('[chat/completions] Request:', {
|
||||||
model: req.body.model,
|
model: req.body.model,
|
||||||
stream: req.body.stream,
|
stream: req.body.stream,
|
||||||
messageCount: req.body.messages?.length,
|
messageCount: req.body.messages?.length,
|
||||||
@ -410,7 +410,7 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
|
|||||||
return res.status(400).json({ error: 'Last message must be from user' });
|
return res.status(400).json({ error: 'Last message must be from user' });
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('messages', JSON.stringify(body.messages));
|
logDebug('Input messages', { messages: body.messages });
|
||||||
|
|
||||||
// clean <think> from all assistant messages
|
// clean <think> from all assistant messages
|
||||||
body.messages = body.messages?.filter(message => {
|
body.messages = body.messages?.filter(message => {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import {TokenTracker} from "../utils/token-tracker";
|
import { logDebug, logError, logInfo } from "../logging";
|
||||||
import {cosineSimilarity} from "./cosine";
|
import { TokenTracker } from "../utils/token-tracker";
|
||||||
import {getEmbeddings} from "./embeddings";
|
import { cosineSimilarity } from "./cosine";
|
||||||
|
import { getEmbeddings } from "./embeddings";
|
||||||
|
|
||||||
const SIMILARITY_THRESHOLD = 0.86; // Adjustable threshold for cosine similarity
|
const SIMILARITY_THRESHOLD = 0.86; // Adjustable threshold for cosine similarity
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ export async function dedupQueries(
|
|||||||
|
|
||||||
// Get embeddings for all queries in one batch
|
// Get embeddings for all queries in one batch
|
||||||
const allQueries = [...newQueries, ...existingQueries];
|
const allQueries = [...newQueries, ...existingQueries];
|
||||||
const {embeddings: allEmbeddings} = await getEmbeddings(allQueries, tracker);
|
const { embeddings: allEmbeddings } = await getEmbeddings(allQueries, tracker);
|
||||||
|
|
||||||
// If embeddings is empty (due to 402 error), return all new queries
|
// If embeddings is empty (due to 402 error), return all new queries
|
||||||
if (!allEmbeddings.length) {
|
if (!allEmbeddings.length) {
|
||||||
@ -66,12 +67,12 @@ export async function dedupQueries(
|
|||||||
usedIndices.add(i);
|
usedIndices.add(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('Dedup:', uniqueQueries);
|
logInfo('Dedup:', { uniqueQueries });
|
||||||
return {
|
return {
|
||||||
unique_queries: uniqueQueries,
|
unique_queries: uniqueQueries,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in deduplication analysis:', error);
|
logError('Error in deduplication analysis:', { error });
|
||||||
|
|
||||||
// return all new queries if there is an error
|
// return all new queries if there is an error
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user