mirror of
https://github.com/zadam/trilium.git
synced 2026-05-07 11:17:01 +02:00
chore(llm): address requested changes
This commit is contained in:
@@ -113,9 +113,13 @@ export class AnthropicProvider extends BaseProvider {
|
||||
for (let i = 0; i < chatMessages.length; i++) {
|
||||
const m = chatMessages[i];
|
||||
const isLastBeforeNewTurn = i === chatMessages.length - 2;
|
||||
// Anthropic rejects empty text content blocks. Replace empty
|
||||
// content (e.g. tool-only assistant turns) with a placeholder
|
||||
// to preserve conversation flow.
|
||||
const content = m.content || "(tool use)";
|
||||
coreMessages.push({
|
||||
role: m.role as "user" | "assistant",
|
||||
content: m.content,
|
||||
content,
|
||||
...(isLastBeforeNewTurn && { providerOptions: CACHE_CONTROL })
|
||||
});
|
||||
}
|
||||
@@ -132,7 +136,7 @@ export class AnthropicProvider extends BaseProvider {
|
||||
}
|
||||
|
||||
const systemPrompt = this.buildSystemPrompt(messages, config);
|
||||
const chatMessages = messages.filter(m => m.role !== "system" && m.content);
|
||||
const chatMessages = messages.filter(m => m.role !== "system");
|
||||
const coreMessages = this.buildMessages(chatMessages, systemPrompt);
|
||||
|
||||
const thinkingBudget = config.thinkingBudget || 10000;
|
||||
|
||||
@@ -144,7 +144,7 @@ export abstract class BaseProvider implements LlmProvider {
|
||||
|
||||
chat(messages: LlmMessage[], config: LlmProviderConfig): StreamResult {
|
||||
const systemPrompt = this.buildSystemPrompt(messages, config);
|
||||
const chatMessages = messages.filter(m => m.role !== "system" && m.content);
|
||||
const chatMessages = messages.filter(m => m.role !== "system");
|
||||
const coreMessages = this.buildMessages(chatMessages, systemPrompt);
|
||||
|
||||
const streamOptions: Parameters<typeof streamText>[0] = {
|
||||
|
||||
@@ -15,14 +15,14 @@ const { models: AVAILABLE_MODELS, pricing: MODEL_PRICING } = buildModelList([
|
||||
id: "gemini-2.5-pro",
|
||||
name: "Gemini 2.5 Pro",
|
||||
pricing: { input: 1.25, output: 10 },
|
||||
contextWindow: 1048576,
|
||||
isDefault: true
|
||||
contextWindow: 1048576
|
||||
},
|
||||
{
|
||||
id: "gemini-2.5-flash",
|
||||
name: "Gemini 2.5 Flash",
|
||||
pricing: { input: 0.3, output: 2.5 },
|
||||
contextWindow: 1048576
|
||||
contextWindow: 1048576,
|
||||
isDefault: true
|
||||
},
|
||||
{
|
||||
id: "gemini-2.5-flash-lite",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import { tool } from "ai";
|
||||
import { readFileSync } from "fs";
|
||||
import { readFile } from "fs/promises";
|
||||
import { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { z } from "zod";
|
||||
@@ -36,12 +36,12 @@ const SKILLS: SkillDefinition[] = [
|
||||
}
|
||||
];
|
||||
|
||||
function loadSkillContent(name: string): string | null {
|
||||
async function loadSkillContent(name: string): Promise<string | null> {
|
||||
const skill = SKILLS.find((s) => s.name === name);
|
||||
if (!skill) {
|
||||
return null;
|
||||
}
|
||||
return readFileSync(join(__dirname, skill.file), "utf-8");
|
||||
return readFile(join(__dirname, skill.file), "utf-8");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ export const loadSkill = tool({
|
||||
name: z.string().describe("The skill name to load")
|
||||
}),
|
||||
execute: async ({ name }) => {
|
||||
const content = loadSkillContent(name);
|
||||
const content = await loadSkillContent(name);
|
||||
if (!content) {
|
||||
return { error: `Unknown skill: '${name}'. Available: ${SKILLS.map((s) => s.name).join(", ")}` };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user