feat(provider.ollama): add chain-of-thought reasoning support to chat messages and Ollama provider
This commit is contained in:
@@ -1,5 +1,12 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
|||||||
@@ -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.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.'
|
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;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -205,13 +205,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;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -254,6 +257,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 +287,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 +301,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;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -410,15 +418,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;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user