Compare commits

...

8 Commits

Author SHA1 Message Date
d296a1b676 v0.13.2
Some checks failed
Default (tags) / security (push) Failing after 1s
Default (tags) / test (push) Failing after 1s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-01-20 02:50:46 +00:00
f74d1cf2ba fix(repo): no changes detected in diff; nothing to commit 2026-01-20 02:50:46 +00:00
b29d7f5df3 fix(classes.smartai): use IOllamaModelOptions type for defaultOptions instead of inline type 2026-01-20 02:50:32 +00:00
00b8312fa7 v0.13.1
Some checks failed
Default (tags) / security (push) Failing after 1s
Default (tags) / test (push) Failing after 1s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-01-20 02:40:29 +00:00
4be91d678a fix(): no changes detected; no release required 2026-01-20 02:40:29 +00:00
1156320546 feat(provider.ollama): add native tool calling support for Ollama API
- Add IOllamaTool and IOllamaToolCall types for native function calling
- Add think parameter to IOllamaModelOptions for reasoning models (GPT-OSS, QwQ)
- Add tools parameter to IOllamaChatOptions
- Add toolCalls to response interfaces (IOllamaStreamChunk, IOllamaChatResponse)
- Update chat(), chatStreamResponse(), collectStreamResponse(), chatWithOptions() to support native tools
- Parse tool_calls from Ollama API responses
- Add support for tool message role in conversation history
2026-01-20 02:39:28 +00:00
7cb9bc24dc v0.13.0
Some checks failed
Default (tags) / security (push) Failing after 1s
Default (tags) / test (push) Failing after 1s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-01-20 02:03:20 +00:00
9ad039f77b feat(provider.ollama): add chain-of-thought reasoning support to chat messages and Ollama provider 2026-01-20 02:03:20 +00:00
6 changed files with 176 additions and 37 deletions

View File

@@ -1,5 +1,24 @@
# Changelog # Changelog
## 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) ## 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 update documentation: clarify provider capabilities, add provider capabilities summary, polish examples and formatting, and remove Serena project config

View File

@@ -1,6 +1,6 @@
{ {
"name": "@push.rocks/smartai", "name": "@push.rocks/smartai",
"version": "0.12.1", "version": "0.13.2",
"private": false, "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.", "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", "main": "dist_ts/index.js",

View File

@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartai', name: '@push.rocks/smartai',
version: '0.12.1', version: '0.13.2',
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.' 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

@@ -8,6 +8,8 @@ export interface ChatMessage {
content: string; content: string;
/** Base64-encoded images for vision-capable models */ /** Base64-encoded images for vision-capable models */
images?: string[]; 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 { export interface ChatResponse {
role: 'assistant'; role: 'assistant';
message: string; message: string;
/** Chain-of-thought reasoning from reasoning models */
reasoning?: string;
} }
/** /**

View File

@@ -3,7 +3,7 @@ import * as plugins from './plugins.js';
import { AnthropicProvider } from './provider.anthropic.js'; import { AnthropicProvider } from './provider.anthropic.js';
import { ElevenLabsProvider } from './provider.elevenlabs.js'; import { ElevenLabsProvider } from './provider.elevenlabs.js';
import { MistralProvider } from './provider.mistral.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 { OpenAiProvider } from './provider.openai.js';
import { PerplexityProvider } from './provider.perplexity.js'; import { PerplexityProvider } from './provider.perplexity.js';
import { ExoProvider } from './provider.exo.js'; import { ExoProvider } from './provider.exo.js';
@@ -32,16 +32,7 @@ export interface ISmartAiOptions {
baseUrl?: string; baseUrl?: string;
model?: string; model?: string;
visionModel?: string; visionModel?: string;
defaultOptions?: { defaultOptions?: IOllamaModelOptions;
num_ctx?: number;
temperature?: number;
top_k?: number;
top_p?: number;
repeat_penalty?: number;
num_predict?: number;
stop?: string[];
seed?: number;
};
defaultTimeout?: number; defaultTimeout?: number;
}; };
elevenlabs?: { elevenlabs?: {

View File

@@ -26,6 +26,39 @@ export interface IOllamaModelOptions {
num_predict?: number; // Max tokens to predict num_predict?: number; // Max tokens to predict
stop?: string[]; // Stop sequences stop?: string[]; // Stop sequences
seed?: number; // Random seed for reproducibility 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 { export interface IOllamaProviderOptions {
@@ -43,6 +76,7 @@ export interface IOllamaChatOptions extends ChatOptions {
options?: IOllamaModelOptions; // Per-request model options options?: IOllamaModelOptions; // Per-request model options
timeout?: number; // Per-request timeout in ms timeout?: number; // Per-request timeout in ms
model?: string; // Per-request model override model?: string; // Per-request model override
tools?: IOllamaTool[]; // Available tools for native function calling
// images is inherited from ChatOptions // images is inherited from ChatOptions
} }
@@ -52,6 +86,7 @@ export interface IOllamaChatOptions extends ChatOptions {
export interface IOllamaStreamChunk { export interface IOllamaStreamChunk {
content: string; content: string;
thinking?: string; // For models with extended thinking thinking?: string; // For models with extended thinking
toolCalls?: IOllamaToolCall[]; // Tool calls in streaming mode
done: boolean; done: boolean;
stats?: { stats?: {
totalDuration?: number; totalDuration?: number;
@@ -64,6 +99,7 @@ export interface IOllamaStreamChunk {
*/ */
export interface IOllamaChatResponse extends ChatResponse { export interface IOllamaChatResponse extends ChatResponse {
thinking?: string; thinking?: string;
toolCalls?: IOllamaToolCall[]; // Tool calls from model (native tool calling)
stats?: { stats?: {
totalDuration?: number; totalDuration?: number;
evalCount?: number; evalCount?: number;
@@ -205,13 +241,16 @@ export class OllamaProvider extends MultiModalModel {
public async chat(optionsArg: ChatOptions): Promise<ChatResponse> { public async chat(optionsArg: ChatOptions): Promise<ChatResponse> {
// Format messages for Ollama // Format messages for Ollama
const historyMessages = optionsArg.messageHistory.map((msg) => { 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, role: msg.role,
content: msg.content, content: msg.content,
}; };
if (msg.images && msg.images.length > 0) { if (msg.images && msg.images.length > 0) {
formatted.images = msg.images; formatted.images = msg.images;
} }
if (msg.reasoning) {
formatted.reasoning = msg.reasoning;
}
return formatted; return formatted;
}); });
@@ -230,18 +269,26 @@ export class OllamaProvider extends MultiModalModel {
userMessage, 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 // Make API call to Ollama with defaultOptions and timeout
const response = await fetch(`${this.baseUrl}/api/chat`, { const response = await fetch(`${this.baseUrl}/api/chat`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify({ body: JSON.stringify(requestBody),
model: this.model,
messages: messages,
stream: false,
options: this.defaultOptions,
}),
signal: AbortSignal.timeout(this.defaultTimeout), signal: AbortSignal.timeout(this.defaultTimeout),
}); });
@@ -254,6 +301,7 @@ export class OllamaProvider extends MultiModalModel {
return { return {
role: 'assistant' as const, role: 'assistant' as const,
message: result.message.content, message: result.message.content,
reasoning: result.message.thinking || result.message.reasoning,
}; };
} }
@@ -283,6 +331,7 @@ export class OllamaProvider extends MultiModalModel {
return { return {
role: 'assistant' as const, role: 'assistant' as const,
message: response.message, message: response.message,
reasoning: response.thinking,
}; };
} }
@@ -296,15 +345,18 @@ export class OllamaProvider extends MultiModalModel {
const timeout = optionsArg.timeout || this.defaultTimeout; const timeout = optionsArg.timeout || this.defaultTimeout;
const modelOptions = { ...this.defaultOptions, ...optionsArg.options }; const modelOptions = { ...this.defaultOptions, ...optionsArg.options };
// Format history messages with optional images // Format history messages with optional images and reasoning
const historyMessages = optionsArg.messageHistory.map((msg) => { 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, role: msg.role,
content: msg.content, content: msg.content,
}; };
if (msg.images && msg.images.length > 0) { if (msg.images && msg.images.length > 0) {
formatted.images = msg.images; formatted.images = msg.images;
} }
if (msg.reasoning) {
formatted.reasoning = msg.reasoning;
}
return formatted; return formatted;
}); });
@@ -323,15 +375,28 @@ export class OllamaProvider extends MultiModalModel {
userMessage, userMessage,
]; ];
// 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`, { const response = await fetch(`${this.baseUrl}/api/chat`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ body: JSON.stringify(requestBody),
model,
messages,
stream: true,
options: modelOptions,
}),
signal: AbortSignal.timeout(timeout), signal: AbortSignal.timeout(timeout),
}); });
@@ -356,9 +421,25 @@ export class OllamaProvider extends MultiModalModel {
if (!line.trim()) continue; if (!line.trim()) continue;
try { try {
const json = JSON.parse(line); 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 { yield {
content: json.message?.content || '', content: json.message?.content || '',
thinking: json.message?.thinking, thinking: json.message?.thinking,
toolCalls,
done: json.done || false, done: json.done || false,
stats: json.done ? { stats: json.done ? {
totalDuration: json.total_duration, totalDuration: json.total_duration,
@@ -385,11 +466,13 @@ export class OllamaProvider extends MultiModalModel {
const stream = await this.chatStreamResponse(optionsArg); const stream = await this.chatStreamResponse(optionsArg);
let content = ''; let content = '';
let thinking = ''; let thinking = '';
let toolCalls: IOllamaToolCall[] = [];
let stats: IOllamaChatResponse['stats']; let stats: IOllamaChatResponse['stats'];
for await (const chunk of stream) { for await (const chunk of stream) {
if (chunk.content) content += chunk.content; if (chunk.content) content += chunk.content;
if (chunk.thinking) thinking += chunk.thinking; if (chunk.thinking) thinking += chunk.thinking;
if (chunk.toolCalls) toolCalls = toolCalls.concat(chunk.toolCalls);
if (chunk.stats) stats = chunk.stats; if (chunk.stats) stats = chunk.stats;
if (onChunk) onChunk(chunk); if (onChunk) onChunk(chunk);
} }
@@ -398,6 +481,7 @@ export class OllamaProvider extends MultiModalModel {
role: 'assistant' as const, role: 'assistant' as const,
message: content, message: content,
thinking: thinking || undefined, thinking: thinking || undefined,
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
stats, stats,
}; };
} }
@@ -410,15 +494,27 @@ export class OllamaProvider extends MultiModalModel {
const timeout = optionsArg.timeout || this.defaultTimeout; const timeout = optionsArg.timeout || this.defaultTimeout;
const modelOptions = { ...this.defaultOptions, ...optionsArg.options }; const modelOptions = { ...this.defaultOptions, ...optionsArg.options };
// Format history messages with optional images // Format history messages with optional images, reasoning, and tool role
const historyMessages = optionsArg.messageHistory.map((msg) => { 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 } = {
role: msg.role, role: msg.role,
content: msg.content, content: msg.content,
}; };
if (msg.images && msg.images.length > 0) { if (msg.images && msg.images.length > 0) {
formatted.images = msg.images; formatted.images = msg.images;
} }
if (msg.reasoning) {
formatted.reasoning = msg.reasoning;
}
return formatted; return formatted;
}); });
@@ -437,15 +533,28 @@ export class OllamaProvider extends MultiModalModel {
userMessage, userMessage,
]; ];
// 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`, { const response = await fetch(`${this.baseUrl}/api/chat`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ body: JSON.stringify(requestBody),
model,
messages,
stream: false,
options: modelOptions,
}),
signal: AbortSignal.timeout(timeout), signal: AbortSignal.timeout(timeout),
}); });
@@ -454,10 +563,26 @@ export class OllamaProvider extends MultiModalModel {
} }
const result = await response.json(); 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 { return {
role: 'assistant' as const, role: 'assistant' as const,
message: result.message.content, message: result.message.content || '',
thinking: result.message.thinking, thinking: result.message.thinking,
toolCalls,
stats: { stats: {
totalDuration: result.total_duration, totalDuration: result.total_duration,
evalCount: result.eval_count, evalCount: result.eval_count,