Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
sourceType: 'module'
},
rules: {
'no-console': ['error', { allow: ['log', 'error'] }],
'no-console': ['error', { allow: ['log', 'error', 'warn'] }],
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-explicit-any': 'off'
},
Expand Down
4 changes: 2 additions & 2 deletions src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import { finalizeAnswer } from "./tools/finalizer";
import { buildImageReferences, buildReferences } from "./tools/build-ref";
import { logInfo, logError, logDebug, logWarning } from './logging';
import { researchPlan } from './tools/research-planner';
import { reduceAnswers } from './tools/reducer';
import { AxiosError } from 'axios';
import { dedupImagesWithEmbeddings, filterImages } from './utils/image-tools';
import { serpCluster } from './tools/serp-cluster';
Expand Down Expand Up @@ -304,10 +303,11 @@ async function executeSearchQueries(
logDebug('Search query:', { query });
switch (searchProvider || SEARCH_PROVIDER) {
case 'jina':
case 'arxiv':
case 'arxiv': {
const num = meta ? undefined : 30;
results = (await search(query, searchProvider, num, meta, context.tokenTracker)).response.results || [];
break;
}
case 'duck':
results = (await duckSearch(query.q, { safeSearch: SafeSearchType.STRICT })).results;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ActionTracker } from "./utils/action-tracker";
import { ObjectGeneratorSafe } from "./utils/safe-generator";
import { jsonSchema } from "ai"; // or another converter library
import { normalizeHostName } from "./utils/url-tools";
import { logInfo, logError, logDebug, logWarning } from './logging';
import { logInfo, logError, logDebug } from './logging';
import { body, validationResult } from 'express-validator';

const app = express();
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Command } from 'commander';
import { getResponse } from './agent';
import { version } from '../package.json';
import { logInfo, logError, logDebug, logWarning } from './logging';
import { logInfo, logError } from './logging';

const program = new Command();

Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ProxyAgent, setGlobalDispatcher } from 'undici';
import { createGoogleGenerativeAI } from '@ai-sdk/google';
import { createOpenAI, OpenAIProviderSettings } from '@ai-sdk/openai';
import configJson from '../config.json';
import { logInfo, logError, logDebug, logWarning } from './logging';
import { logInfo, logError } from './logging';
// Load environment variables
dotenv.config();

Expand Down
2 changes: 1 addition & 1 deletion src/evals/batch-evals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GEMINI_API_KEY } from '../config';
import { z } from 'zod';
import { AnswerAction, TrackerContext } from "../types";
import { createGoogleGenerativeAI } from "@ai-sdk/google";
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logInfo, logError } from '../logging';

const execAsync = promisify(exec);

Expand Down
2 changes: 1 addition & 1 deletion src/tools/brave-search.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BRAVE_API_KEY } from "../config";
import axiosClient from "../utils/axios-client";
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logInfo } from '../logging';

import { BraveSearchResponse } from '../types';

Expand Down
2 changes: 1 addition & 1 deletion src/tools/broken-ch-fixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { generateText } from "ai";
import { getModel } from "../config";
import { TrackerContext } from "../types";
import { detectBrokenUnicodeViaFileIO } from "../utils/text-tools";
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logError, logDebug, logWarning } from '../logging';


/**
Expand Down
2 changes: 1 addition & 1 deletion src/tools/code-sandbox.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ObjectGeneratorSafe } from "../utils/safe-generator";
import { CodeGenResponse, PromptPair, TrackerContext } from "../types";
import { Schemas } from "../utils/schemas";
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logInfo, logDebug, logWarning } from '../logging';


interface SandboxResult {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/cosine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logWarning } from '../logging';

export function cosineSimilarity(vecA: number[], vecB: number[]): number {
if (vecA.length !== vecB.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async function getBatchEmbeddingsWithRetry(
}

const receivedIndices = new Set(response.data.data.map(item => item.index));
const dimensionSize = response.data.data[0]?.embedding?.length || options.dimensions || 1024;
// const dimensionSize = response.data.data[0]?.embedding?.length || options.dimensions || 1024;

// Process successful embeddings
const successfulEmbeddings: number[][] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/tools/error-analyzer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ErrorAnalysisResponse, PromptPair, TrackerContext } from '../types';
import { ObjectGeneratorSafe } from "../utils/safe-generator";
import { Schemas } from "../utils/schemas";
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logInfo, logError } from '../logging';


function getPrompt(diaryContext: string[]): PromptPair {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AnswerAction, EvaluationResponse, EvaluationType, KnowledgeItem, Prompt
import { ObjectGeneratorSafe } from "../utils/safe-generator";
import { Schemas } from "../utils/schemas";
import { getKnowledgeStr } from "../utils/text-tools";
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logInfo, logError } from '../logging';

const TOOL_NAME = 'evaluator';

Expand Down
2 changes: 1 addition & 1 deletion src/tools/jina-dedup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logDebug, logError, logInfo } from "../logging";
import { logError, logInfo } from "../logging";
import { TokenTracker } from "../utils/token-tracker";
import { cosineSimilarity } from "./cosine";
import { getEmbeddings } from "./embeddings";
Expand Down
2 changes: 1 addition & 1 deletion src/tools/jina-rerank.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TokenTracker } from "../utils/token-tracker";
import { JINA_API_KEY } from "../config";
import axiosClient from '../utils/axios-client';
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logError, logDebug } from '../logging';

const JINA_API_URL = 'https://api.jina.ai/v1/rerank';

Expand Down
2 changes: 1 addition & 1 deletion src/tools/query-rewriter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PromptPair, SearchAction, SERPQuery, TrackerContext } from '../types';
import { ObjectGeneratorSafe } from "../utils/safe-generator";
import { Schemas } from "../utils/schemas";
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logInfo, logError } from '../logging';


function getPrompt(query: string, think: string, context: string): PromptPair {
Expand Down
1 change: 1 addition & 0 deletions src/tools/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export async function readUrl(

return { response: data };
} catch (error: any) {
logDebug(`Read error: ${error.message}`);
throw error;
}
}
6 changes: 4 additions & 2 deletions src/tools/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ export function chunkText(text: string, options: ChunkOptions = {}): {
chunks = text.split(/(?<=[.!?。!?])/).filter(chunk => chunk.trim().length > 0);
break;

case 'characters':
case 'characters': {
const chunkSize = Number(options.value) || 1000;
for (let i = 0; i < text.length; i += chunkSize) {
chunks.push(text.slice(i, i + chunkSize));
}
break;
}

case 'regex':
case 'regex': {
if (!options.value || typeof options.value !== 'string') {
throw new Error('Regex pattern is required for regex chunking');
}
chunks = text.split(new RegExp(options.value)).filter(chunk => chunk.trim().length > 0);
break;
}

default:
throw new Error('Invalid chunking type');
Expand Down
1 change: 0 additions & 1 deletion src/tools/serper-search.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SERPER_API_KEY } from "../config";
import axiosClient from "../utils/axios-client";
import { logInfo, logError, logDebug, logWarning } from '../logging';

import { SerperSearchResponse, SERPQuery } from '../types';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/axios-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios, { AxiosRequestConfig } from 'axios';
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logError } from '../logging';

// Default timeout in milliseconds
const DEFAULT_TIMEOUT = 30000;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/image-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getEmbeddings } from '../tools/embeddings';
import { TokenTracker } from './token-tracker';
import { ImageObject, ImageReference } from '../types';
import { cosineSimilarity } from '../tools/cosine';
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logInfo, logError, logWarning } from '../logging';
import sharp from 'sharp';

export const downloadFile = async (uri: string) => {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/text-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AnswerAction, KnowledgeItem, Reference } from "../types";
import i18nJSON from './i18n.json';
import { JSDOM } from 'jsdom';
import fs from "fs/promises";
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logError } from '../logging';


export function buildMdFromAnswer(answer: AnswerAction): string {
Expand Down Expand Up @@ -916,7 +916,7 @@ export function extractNgrams(

// Second pass: calculate PMI and filter
const results: NgramResult[] = Array.from(ngramFreq.entries())
.filter(([ngram, freq]) => freq >= minFreq)
.filter(([, freq]) => freq >= minFreq)
.map(([ngram, freq]) => {
const pmi = isCJKText(ngram) ? 0 : calculatePMI(ngram, freq, wordFreq, totalNgrams);
return { ngram, freq, pmi };
Expand Down
2 changes: 1 addition & 1 deletion src/utils/token-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EventEmitter } from 'events';

import { TokenUsage } from '../types';
import { LanguageModelUsage } from "ai";
import { logInfo, logError, logDebug, logWarning } from '../logging';
import { logInfo } from '../logging';

export class TokenTracker extends EventEmitter {
private usages: TokenUsage[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/utils/url-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export async function processURLs(
// Process images
if (withImages && data.images) {
const imageEntries = Object.entries(data.images || {});
imageEntries.forEach(async ([alt, url]) => {
imageEntries.forEach(async ([, url]) => {
const imageObject = await processImage(url, context.tokenTracker);
if (imageObject && !imageObjects.find(i => i.url === imageObject.url)) {
imageObjects.push(imageObject);
Expand Down
Loading