feat(providers): Add Anthropic extended thinking and adapt providers to new streaming/file APIs; bump dependencies and update docs, tests and configuration

This commit is contained in:
2026-01-18 16:26:16 +00:00
parent e8a2a3ff1b
commit b4ced080f2
27 changed files with 2262 additions and 3339 deletions

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartai',
version: '0.8.0',
version: '0.9.0',
description: 'SmartAi is a versatile TypeScript library designed to facilitate integration and interaction with various AI models, offering functionalities for chat, audio generation, document processing, and vision tasks.'
}

View File

@@ -317,7 +317,11 @@ export class AnthropicProvider extends MultiModalModel {
const maxTokens = optionsArg.searchDepth === 'deep' ? 20000 :
optionsArg.searchDepth === 'advanced' ? 20000 : 20000;
// Add thinking configuration if enabled
const thinkingConfig = this.getThinkingConfig();
// Create the research request
// Note: When thinking is enabled, temperature must be 1 (or omitted)
const requestParams: any = {
model: 'claude-sonnet-4-5-20250929',
system: systemMessage,
@@ -328,7 +332,8 @@ export class AnthropicProvider extends MultiModalModel {
}
],
max_tokens: maxTokens,
temperature: 0.7
// Only set temperature when thinking is NOT enabled
...(thinkingConfig ? {} : { temperature: 0.7 })
};
// Add tools if web search is enabled
@@ -337,7 +342,6 @@ export class AnthropicProvider extends MultiModalModel {
}
// Add thinking configuration if enabled
const thinkingConfig = this.getThinkingConfig();
if (thinkingConfig) {
requestParams.thinking = thinkingConfig;
}

View File

@@ -1,4 +1,5 @@
import * as plugins from './plugins.js';
import { Readable } from 'stream';
import { MultiModalModel } from './abstract.classes.multimodal.js';
import type {
@@ -83,7 +84,8 @@ export class ElevenLabsProvider extends MultiModalModel {
throw new Error(`ElevenLabs API error: ${response.status} ${response.statusText} - ${errorText}`);
}
const nodeStream = response.streamNode();
const webStream = response.stream();
const nodeStream = Readable.fromWeb(webStream as any);
return nodeStream;
}

View File

@@ -1,6 +1,7 @@
import * as plugins from './plugins.js';
import * as paths from './paths.js';
import { Readable } from 'stream';
import { toFile } from 'openai';
// Custom type definition for chat completion messages
export type TChatCompletionRequestMessage = {
@@ -405,16 +406,19 @@ export class OpenAiProvider extends MultiModalModel {
const model = optionsArg.model || this.options.imageModel || 'gpt-image-1';
try {
// Convert Buffer to uploadable file format for OpenAI API
const imageFile = await toFile(optionsArg.image, 'image.png', { type: 'image/png' });
const requestParams: any = {
model,
image: optionsArg.image,
image: imageFile,
prompt: optionsArg.prompt,
n: optionsArg.n || 1,
};
// Add mask if provided
// Add mask if provided (also convert to file format)
if (optionsArg.mask) {
requestParams.mask = optionsArg.mask;
requestParams.mask = await toFile(optionsArg.mask, 'mask.png', { type: 'image/png' });
}
// Add gpt-image-1 specific parameters