Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 27cef60900 | |||
| 2b00e36b02 | |||
| 8eb3111e7e | |||
| d296a1b676 | |||
| f74d1cf2ba | |||
| b29d7f5df3 | |||
| 00b8312fa7 | |||
| 4be91d678a | |||
| 1156320546 | |||
| 7cb9bc24dc | |||
| 9ad039f77b |
25
changelog.md
25
changelog.md
@@ -1,5 +1,30 @@
|
||||
# Changelog
|
||||
|
||||
## 2026-01-20 - 0.13.3 - fix()
|
||||
no changes detected
|
||||
|
||||
- No files changed in the provided diff.
|
||||
- No version bump required.
|
||||
|
||||
## 2026-01-20 - 0.13.2 - fix(repo)
|
||||
no changes detected in diff; nothing to commit
|
||||
|
||||
- Git diff reported no changes — no files modified
|
||||
- No code or dependency updates detected, so no version bump required
|
||||
|
||||
## 2026-01-20 - 0.13.1 - fix()
|
||||
no changes detected; no release required
|
||||
|
||||
- No changes found in the provided git diff
|
||||
- Current package version is 0.13.0
|
||||
|
||||
## 2026-01-20 - 0.13.0 - feat(provider.ollama)
|
||||
add chain-of-thought reasoning support to chat messages and Ollama provider
|
||||
|
||||
- Added optional reasoning?: string to chat message and chat response interfaces to surface chain-of-thought data.
|
||||
- Propagates reasoning from message history into formatted requests sent to Ollama.
|
||||
- Maps Ollama response fields (thinking or reasoning) into ChatResponse.reasoning so downstream code can access model reasoning output.
|
||||
|
||||
## 2026-01-20 - 0.12.1 - fix(docs)
|
||||
update documentation: clarify provider capabilities, add provider capabilities summary, polish examples and formatting, and remove Serena project config
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@push.rocks/smartai",
|
||||
"version": "0.12.1",
|
||||
"version": "0.13.3",
|
||||
"private": false,
|
||||
"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.",
|
||||
"main": "dist_ts/index.js",
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartai',
|
||||
version: '0.12.1',
|
||||
version: '0.13.3',
|
||||
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.'
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ export interface ChatMessage {
|
||||
content: string;
|
||||
/** Base64-encoded images for vision-capable models */
|
||||
images?: string[];
|
||||
/** Chain-of-thought reasoning for GPT-OSS models (e.g., Ollama) */
|
||||
reasoning?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,6 +37,8 @@ export interface StreamingChatOptions extends ChatOptions {
|
||||
export interface ChatResponse {
|
||||
role: 'assistant';
|
||||
message: string;
|
||||
/** Chain-of-thought reasoning from reasoning models */
|
||||
reasoning?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as plugins from './plugins.js';
|
||||
import { AnthropicProvider } from './provider.anthropic.js';
|
||||
import { ElevenLabsProvider } from './provider.elevenlabs.js';
|
||||
import { MistralProvider } from './provider.mistral.js';
|
||||
import { OllamaProvider } from './provider.ollama.js';
|
||||
import { OllamaProvider, type IOllamaModelOptions } from './provider.ollama.js';
|
||||
import { OpenAiProvider } from './provider.openai.js';
|
||||
import { PerplexityProvider } from './provider.perplexity.js';
|
||||
import { ExoProvider } from './provider.exo.js';
|
||||
@@ -32,16 +32,7 @@ export interface ISmartAiOptions {
|
||||
baseUrl?: string;
|
||||
model?: string;
|
||||
visionModel?: string;
|
||||
defaultOptions?: {
|
||||
num_ctx?: number;
|
||||
temperature?: number;
|
||||
top_k?: number;
|
||||
top_p?: number;
|
||||
repeat_penalty?: number;
|
||||
num_predict?: number;
|
||||
stop?: string[];
|
||||
seed?: number;
|
||||
};
|
||||
defaultOptions?: IOllamaModelOptions;
|
||||
defaultTimeout?: number;
|
||||
};
|
||||
elevenlabs?: {
|
||||
|
||||
@@ -26,6 +26,39 @@ export interface IOllamaModelOptions {
|
||||
num_predict?: number; // Max tokens to predict
|
||||
stop?: string[]; // Stop sequences
|
||||
seed?: number; // Random seed for reproducibility
|
||||
think?: boolean; // Enable thinking/reasoning mode (for GPT-OSS, QwQ, etc.)
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON Schema tool definition for Ollama native tool calling
|
||||
* @see https://docs.ollama.com/capabilities/tool-calling
|
||||
*/
|
||||
export interface IOllamaTool {
|
||||
type: 'function';
|
||||
function: {
|
||||
name: string;
|
||||
description: string;
|
||||
parameters: {
|
||||
type: 'object';
|
||||
properties: Record<string, {
|
||||
type: string;
|
||||
description?: string;
|
||||
enum?: string[];
|
||||
}>;
|
||||
required?: string[];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Tool call returned by model in native tool calling mode
|
||||
*/
|
||||
export interface IOllamaToolCall {
|
||||
function: {
|
||||
name: string;
|
||||
arguments: Record<string, unknown>;
|
||||
index?: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface IOllamaProviderOptions {
|
||||
@@ -43,6 +76,7 @@ export interface IOllamaChatOptions extends ChatOptions {
|
||||
options?: IOllamaModelOptions; // Per-request model options
|
||||
timeout?: number; // Per-request timeout in ms
|
||||
model?: string; // Per-request model override
|
||||
tools?: IOllamaTool[]; // Available tools for native function calling
|
||||
// images is inherited from ChatOptions
|
||||
}
|
||||
|
||||
@@ -52,6 +86,7 @@ export interface IOllamaChatOptions extends ChatOptions {
|
||||
export interface IOllamaStreamChunk {
|
||||
content: string;
|
||||
thinking?: string; // For models with extended thinking
|
||||
toolCalls?: IOllamaToolCall[]; // Tool calls in streaming mode
|
||||
done: boolean;
|
||||
stats?: {
|
||||
totalDuration?: number;
|
||||
@@ -64,6 +99,7 @@ export interface IOllamaStreamChunk {
|
||||
*/
|
||||
export interface IOllamaChatResponse extends ChatResponse {
|
||||
thinking?: string;
|
||||
toolCalls?: IOllamaToolCall[]; // Tool calls from model (native tool calling)
|
||||
stats?: {
|
||||
totalDuration?: number;
|
||||
evalCount?: number;
|
||||
@@ -205,13 +241,16 @@ export class OllamaProvider extends MultiModalModel {
|
||||
public async chat(optionsArg: ChatOptions): Promise<ChatResponse> {
|
||||
// Format messages for Ollama
|
||||
const historyMessages = optionsArg.messageHistory.map((msg) => {
|
||||
const formatted: { role: string; content: string; images?: string[] } = {
|
||||
const formatted: { role: string; content: string; images?: string[]; reasoning?: string } = {
|
||||
role: msg.role,
|
||||
content: msg.content,
|
||||
};
|
||||
if (msg.images && msg.images.length > 0) {
|
||||
formatted.images = msg.images;
|
||||
}
|
||||
if (msg.reasoning) {
|
||||
formatted.reasoning = msg.reasoning;
|
||||
}
|
||||
return formatted;
|
||||
});
|
||||
|
||||
@@ -230,18 +269,26 @@ export class OllamaProvider extends MultiModalModel {
|
||||
userMessage,
|
||||
];
|
||||
|
||||
// Build request body - include think parameter if set
|
||||
const requestBody: Record<string, unknown> = {
|
||||
model: this.model,
|
||||
messages: messages,
|
||||
stream: false,
|
||||
options: this.defaultOptions,
|
||||
};
|
||||
|
||||
// Add think parameter for reasoning models (GPT-OSS, QwQ, etc.)
|
||||
if (this.defaultOptions.think !== undefined) {
|
||||
requestBody.think = this.defaultOptions.think;
|
||||
}
|
||||
|
||||
// Make API call to Ollama with defaultOptions and timeout
|
||||
const response = await fetch(`${this.baseUrl}/api/chat`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: this.model,
|
||||
messages: messages,
|
||||
stream: false,
|
||||
options: this.defaultOptions,
|
||||
}),
|
||||
body: JSON.stringify(requestBody),
|
||||
signal: AbortSignal.timeout(this.defaultTimeout),
|
||||
});
|
||||
|
||||
@@ -254,6 +301,7 @@ export class OllamaProvider extends MultiModalModel {
|
||||
return {
|
||||
role: 'assistant' as const,
|
||||
message: result.message.content,
|
||||
reasoning: result.message.thinking || result.message.reasoning,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -283,6 +331,7 @@ export class OllamaProvider extends MultiModalModel {
|
||||
return {
|
||||
role: 'assistant' as const,
|
||||
message: response.message,
|
||||
reasoning: response.thinking,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -296,15 +345,23 @@ export class OllamaProvider extends MultiModalModel {
|
||||
const timeout = optionsArg.timeout || this.defaultTimeout;
|
||||
const modelOptions = { ...this.defaultOptions, ...optionsArg.options };
|
||||
|
||||
// Format history messages with optional images
|
||||
// Format history messages with optional images, reasoning, and tool_calls
|
||||
const historyMessages = optionsArg.messageHistory.map((msg) => {
|
||||
const formatted: { role: string; content: string; images?: string[] } = {
|
||||
const formatted: { role: string; content: string; images?: string[]; reasoning?: string; tool_calls?: any[] } = {
|
||||
role: msg.role,
|
||||
content: msg.content,
|
||||
};
|
||||
if (msg.images && msg.images.length > 0) {
|
||||
formatted.images = msg.images;
|
||||
}
|
||||
if (msg.reasoning) {
|
||||
formatted.reasoning = msg.reasoning;
|
||||
}
|
||||
// CRITICAL: Include tool_calls in history for native tool calling
|
||||
// Without this, the model doesn't know it already called a tool and may call it again
|
||||
if ((msg as any).tool_calls && Array.isArray((msg as any).tool_calls)) {
|
||||
formatted.tool_calls = (msg as any).tool_calls;
|
||||
}
|
||||
return formatted;
|
||||
});
|
||||
|
||||
@@ -323,15 +380,28 @@ export class OllamaProvider extends MultiModalModel {
|
||||
userMessage,
|
||||
];
|
||||
|
||||
const response = await fetch(`${this.baseUrl}/api/chat`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
// Build request body with optional tools and think parameters
|
||||
const requestBody: Record<string, unknown> = {
|
||||
model,
|
||||
messages,
|
||||
stream: true,
|
||||
options: modelOptions,
|
||||
}),
|
||||
};
|
||||
|
||||
// Add think parameter for reasoning models (GPT-OSS, QwQ, etc.)
|
||||
if (modelOptions.think !== undefined) {
|
||||
requestBody.think = modelOptions.think;
|
||||
}
|
||||
|
||||
// Add tools for native function calling
|
||||
if (optionsArg.tools && optionsArg.tools.length > 0) {
|
||||
requestBody.tools = optionsArg.tools;
|
||||
}
|
||||
|
||||
const response = await fetch(`${this.baseUrl}/api/chat`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(requestBody),
|
||||
signal: AbortSignal.timeout(timeout),
|
||||
});
|
||||
|
||||
@@ -356,9 +426,25 @@ export class OllamaProvider extends MultiModalModel {
|
||||
if (!line.trim()) continue;
|
||||
try {
|
||||
const json = JSON.parse(line);
|
||||
|
||||
// Parse tool_calls from response
|
||||
let toolCalls: IOllamaToolCall[] | undefined;
|
||||
if (json.message?.tool_calls && Array.isArray(json.message.tool_calls)) {
|
||||
toolCalls = json.message.tool_calls.map((tc: any) => ({
|
||||
function: {
|
||||
name: tc.function?.name || '',
|
||||
arguments: typeof tc.function?.arguments === 'string'
|
||||
? JSON.parse(tc.function.arguments)
|
||||
: tc.function?.arguments || {},
|
||||
index: tc.index,
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
yield {
|
||||
content: json.message?.content || '',
|
||||
thinking: json.message?.thinking,
|
||||
toolCalls,
|
||||
done: json.done || false,
|
||||
stats: json.done ? {
|
||||
totalDuration: json.total_duration,
|
||||
@@ -385,11 +471,13 @@ export class OllamaProvider extends MultiModalModel {
|
||||
const stream = await this.chatStreamResponse(optionsArg);
|
||||
let content = '';
|
||||
let thinking = '';
|
||||
let toolCalls: IOllamaToolCall[] = [];
|
||||
let stats: IOllamaChatResponse['stats'];
|
||||
|
||||
for await (const chunk of stream) {
|
||||
if (chunk.content) content += chunk.content;
|
||||
if (chunk.thinking) thinking += chunk.thinking;
|
||||
if (chunk.toolCalls) toolCalls = toolCalls.concat(chunk.toolCalls);
|
||||
if (chunk.stats) stats = chunk.stats;
|
||||
if (onChunk) onChunk(chunk);
|
||||
}
|
||||
@@ -398,6 +486,7 @@ export class OllamaProvider extends MultiModalModel {
|
||||
role: 'assistant' as const,
|
||||
message: content,
|
||||
thinking: thinking || undefined,
|
||||
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
||||
stats,
|
||||
};
|
||||
}
|
||||
@@ -410,15 +499,32 @@ export class OllamaProvider extends MultiModalModel {
|
||||
const timeout = optionsArg.timeout || this.defaultTimeout;
|
||||
const modelOptions = { ...this.defaultOptions, ...optionsArg.options };
|
||||
|
||||
// Format history messages with optional images
|
||||
// Format history messages with optional images, reasoning, tool_calls, and tool role
|
||||
const historyMessages = optionsArg.messageHistory.map((msg) => {
|
||||
const formatted: { role: string; content: string; images?: string[] } = {
|
||||
// Handle tool result messages
|
||||
if ((msg as any).role === 'tool') {
|
||||
return {
|
||||
role: 'tool',
|
||||
content: msg.content,
|
||||
tool_name: (msg as any).toolName,
|
||||
};
|
||||
}
|
||||
|
||||
const formatted: { role: string; content: string; images?: string[]; reasoning?: string; tool_calls?: any[] } = {
|
||||
role: msg.role,
|
||||
content: msg.content,
|
||||
};
|
||||
if (msg.images && msg.images.length > 0) {
|
||||
formatted.images = msg.images;
|
||||
}
|
||||
if (msg.reasoning) {
|
||||
formatted.reasoning = msg.reasoning;
|
||||
}
|
||||
// CRITICAL: Include tool_calls in history for native tool calling
|
||||
// Without this, the model doesn't know it already called a tool and may call it again
|
||||
if ((msg as any).tool_calls && Array.isArray((msg as any).tool_calls)) {
|
||||
formatted.tool_calls = (msg as any).tool_calls;
|
||||
}
|
||||
return formatted;
|
||||
});
|
||||
|
||||
@@ -437,15 +543,28 @@ export class OllamaProvider extends MultiModalModel {
|
||||
userMessage,
|
||||
];
|
||||
|
||||
const response = await fetch(`${this.baseUrl}/api/chat`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
// Build request body with optional tools and think parameters
|
||||
const requestBody: Record<string, unknown> = {
|
||||
model,
|
||||
messages,
|
||||
stream: false,
|
||||
options: modelOptions,
|
||||
}),
|
||||
};
|
||||
|
||||
// Add think parameter for reasoning models (GPT-OSS, QwQ, etc.)
|
||||
if (modelOptions.think !== undefined) {
|
||||
requestBody.think = modelOptions.think;
|
||||
}
|
||||
|
||||
// Add tools for native function calling
|
||||
if (optionsArg.tools && optionsArg.tools.length > 0) {
|
||||
requestBody.tools = optionsArg.tools;
|
||||
}
|
||||
|
||||
const response = await fetch(`${this.baseUrl}/api/chat`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(requestBody),
|
||||
signal: AbortSignal.timeout(timeout),
|
||||
});
|
||||
|
||||
@@ -454,10 +573,26 @@ export class OllamaProvider extends MultiModalModel {
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
// Parse tool_calls from response
|
||||
let toolCalls: IOllamaToolCall[] | undefined;
|
||||
if (result.message?.tool_calls && Array.isArray(result.message.tool_calls)) {
|
||||
toolCalls = result.message.tool_calls.map((tc: any) => ({
|
||||
function: {
|
||||
name: tc.function?.name || '',
|
||||
arguments: typeof tc.function?.arguments === 'string'
|
||||
? JSON.parse(tc.function.arguments)
|
||||
: tc.function?.arguments || {},
|
||||
index: tc.index,
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
return {
|
||||
role: 'assistant' as const,
|
||||
message: result.message.content,
|
||||
message: result.message.content || '',
|
||||
thinking: result.message.thinking,
|
||||
toolCalls,
|
||||
stats: {
|
||||
totalDuration: result.total_duration,
|
||||
evalCount: result.eval_count,
|
||||
|
||||
Reference in New Issue
Block a user