mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-11-18 08:51:37 +08:00
well this works for tool calling the "readNote" func
This commit is contained in:
parent
683d1a5481
commit
7373249dee
@ -27,17 +27,17 @@ export class ModelSelectionStage extends BasePipelineStage<ModelSelectionInput,
|
|||||||
|
|
||||||
// Get default model based on provider precedence
|
// Get default model based on provider precedence
|
||||||
let defaultModel = 'openai:gpt-3.5-turbo'; // Fallback default
|
let defaultModel = 'openai:gpt-3.5-turbo'; // Fallback default
|
||||||
|
|
||||||
// Enable tools by default unless explicitly disabled
|
// Enable tools by default unless explicitly disabled
|
||||||
updatedOptions.enableTools = updatedOptions.enableTools !== false;
|
updatedOptions.enableTools = updatedOptions.enableTools !== false;
|
||||||
|
|
||||||
// Add tools if not already provided
|
// Add tools if not already provided
|
||||||
if (updatedOptions.enableTools && (!updatedOptions.tools || updatedOptions.tools.length === 0)) {
|
if (updatedOptions.enableTools && (!updatedOptions.tools || updatedOptions.tools.length === 0)) {
|
||||||
try {
|
try {
|
||||||
// Import tool registry and fetch tool definitions
|
// Import tool registry and fetch tool definitions
|
||||||
const toolRegistry = (await import('../../tools/tool_registry.js')).default;
|
const toolRegistry = (await import('../../tools/tool_registry.js')).default;
|
||||||
const toolDefinitions = toolRegistry.getAllToolDefinitions();
|
const toolDefinitions = toolRegistry.getAllToolDefinitions();
|
||||||
|
|
||||||
if (toolDefinitions.length > 0) {
|
if (toolDefinitions.length > 0) {
|
||||||
updatedOptions.tools = toolDefinitions;
|
updatedOptions.tools = toolDefinitions;
|
||||||
log.info(`Added ${toolDefinitions.length} tools to options`);
|
log.info(`Added ${toolDefinitions.length} tools to options`);
|
||||||
@ -47,7 +47,7 @@ export class ModelSelectionStage extends BasePipelineStage<ModelSelectionInput,
|
|||||||
try {
|
try {
|
||||||
const toolInitializer = await import('../../tools/tool_initializer.js');
|
const toolInitializer = await import('../../tools/tool_initializer.js');
|
||||||
await toolInitializer.default.initializeTools();
|
await toolInitializer.default.initializeTools();
|
||||||
|
|
||||||
// Try again after initialization
|
// Try again after initialization
|
||||||
const reinitToolDefinitions = toolRegistry.getAllToolDefinitions();
|
const reinitToolDefinitions = toolRegistry.getAllToolDefinitions();
|
||||||
updatedOptions.tools = reinitToolDefinitions;
|
updatedOptions.tools = reinitToolDefinitions;
|
||||||
@ -90,22 +90,11 @@ export class ModelSelectionStage extends BasePipelineStage<ModelSelectionInput,
|
|||||||
const model = await options.getOption('ollamaDefaultModel');
|
const model = await options.getOption('ollamaDefaultModel');
|
||||||
if (model) {
|
if (model) {
|
||||||
defaultModel = `ollama:${model}`;
|
defaultModel = `ollama:${model}`;
|
||||||
|
|
||||||
// Special configuration for Ollama
|
// Enable tools for all Ollama models
|
||||||
// Since Ollama models have different requirements for tool calling,
|
// The Ollama API will handle models that don't support tool calling
|
||||||
// configure based on the model being used
|
log.info(`Using Ollama model ${model} with tool calling enabled`);
|
||||||
const modelLower = model.toLowerCase();
|
updatedOptions.enableTools = true;
|
||||||
|
|
||||||
if (modelLower.includes('llama3') ||
|
|
||||||
modelLower.includes('mistral') ||
|
|
||||||
modelLower.includes('dolphin') ||
|
|
||||||
modelLower.includes('neural') ||
|
|
||||||
modelLower.includes('mist') ||
|
|
||||||
modelLower.includes('wizard')) {
|
|
||||||
// These models are known to support tool calling
|
|
||||||
log.info(`Using Ollama model ${model} with tool calling support`);
|
|
||||||
updatedOptions.enableTools = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -200,9 +200,23 @@ export class OllamaService extends BaseAIService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log full request body (this will create large logs but is helpful for debugging)
|
// Log full request body (with improved logging for debug purposes)
|
||||||
const requestStr = JSON.stringify(requestBody);
|
const requestStr = JSON.stringify(requestBody);
|
||||||
log.info(`Full Ollama request (truncated): ${requestStr.substring(0, 1000)}...`);
|
log.info(`========== FULL OLLAMA REQUEST ==========`);
|
||||||
|
|
||||||
|
// Log request in manageable chunks
|
||||||
|
const maxChunkSize = 4000;
|
||||||
|
if (requestStr.length > maxChunkSize) {
|
||||||
|
let i = 0;
|
||||||
|
while (i < requestStr.length) {
|
||||||
|
const chunk = requestStr.substring(i, i + maxChunkSize);
|
||||||
|
log.info(`Request part ${Math.floor(i/maxChunkSize) + 1}/${Math.ceil(requestStr.length/maxChunkSize)}: ${chunk}`);
|
||||||
|
i += maxChunkSize;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.info(`Full request: ${requestStr}`);
|
||||||
|
}
|
||||||
|
log.info(`========== END FULL OLLAMA REQUEST ==========`);
|
||||||
log.info(`========== END OLLAMA REQUEST ==========`);
|
log.info(`========== END OLLAMA REQUEST ==========`);
|
||||||
|
|
||||||
// Make API request
|
// Make API request
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user