feat(provider.ollama): add chain-of-thought reasoning support to chat messages and Ollama provider
This commit is contained in:
@@ -205,13 +205,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;
|
||||
});
|
||||
|
||||
@@ -254,6 +257,7 @@ export class OllamaProvider extends MultiModalModel {
|
||||
return {
|
||||
role: 'assistant' as const,
|
||||
message: result.message.content,
|
||||
reasoning: result.message.thinking || result.message.reasoning,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -283,6 +287,7 @@ export class OllamaProvider extends MultiModalModel {
|
||||
return {
|
||||
role: 'assistant' as const,
|
||||
message: response.message,
|
||||
reasoning: response.thinking,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -296,15 +301,18 @@ 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 and reasoning
|
||||
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;
|
||||
});
|
||||
|
||||
@@ -410,15 +418,18 @@ 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 and reasoning
|
||||
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;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user