This commit is contained in:
2026-02-22 20:27:09 -05:00
parent 7b326a112e
commit 92024c8a64
37 changed files with 6785 additions and 3344 deletions
+43 -10
View File
@@ -24,7 +24,21 @@ class OllamaProvider {
temperature: this.config.temperature || 1,
top_p: this.config.topP || 0.95,
top_k: this.config.topK || 64,
num_predict: this.config.maxOutputTokens || 8192,
num_predict: this.config.maxOutputTokens || 2048,
};
}
__jsonFormat() {
return {
type: 'array',
items: {
type: 'object',
properties: {
text: { type: 'string' },
delay: { type: 'number' }
},
required: ['text', 'delay']
}
};
}
@@ -46,15 +60,19 @@ class OllamaProvider {
}
];
// console.log('Ollama messages', messages)
const requestBody = {
model: this.model,
messages: messages,
stream: false,
format: this.__jsonFormat(),
options: this.__settings()
};
// console.log('Ollama request:', JSON.stringify(requestBody, null, 2));
const response = await axios.post(
`${this.baseUrl}/api/chat`,
{
model: this.model,
messages: messages,
stream: false,
format: 'json', // Request JSON response
options: this.__settings()
},
requestBody,
{
timeout: this.config.timeout || 30000,
headers: {
@@ -63,6 +81,11 @@ class OllamaProvider {
}
);
// Log raw response for debugging
const rawContent = response.data.message.content;
// console.log('Ollama raw response:', JSON.stringify(rawContent));
// console.log('Ollama raw response length:', rawContent?.length);
// Update history
this.messages.push({
role: 'user',
@@ -72,8 +95,8 @@ class OllamaProvider {
this.messages.push({
role: 'model',
parts: [{ text: response.data.message.content }],
content: response.data.message.content
parts: [{ text: rawContent }],
content: rawContent
});
// Return in a format compatible with the Ai class
@@ -83,6 +106,16 @@ class OllamaProvider {
}
};
} catch (error) {
// Log detailed error information
const errorDetails = {
message: error.message,
status: error.response?.status,
data: error.response?.data,
url: error.config?.url,
retryCount: retryCount
};
console.log('Ollama API error details:', errorDetails);
if (retryCount > 3) {
throw new Error(`Ollama API error after ${retryCount} retries: ${error.message}`);
}