generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 596
Expand file tree
/
Copy pathmodelAdapter.test.ts
More file actions
171 lines (135 loc) · 6.85 KB
/
modelAdapter.test.ts
File metadata and controls
171 lines (135 loc) · 6.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import { ModelAdapterFactory, joinPromptSections } from "./modelAdapter";
import { ToolMetadata } from "@/tools/ToolRegistry";
describe("ModelAdapter", () => {
describe("enhanceSystemPrompt", () => {
const basePrompt = "You are a helpful assistant.";
const toolDescriptions = "Tool descriptions here";
const createToolMetadata = (id: string, instructions: string): ToolMetadata => ({
id,
displayName: `${id} Display`,
description: `${id} description`,
category: "custom",
customPromptInstructions: instructions,
});
it("should include tool instructions when tools are enabled", () => {
const mockModel = { modelName: "gpt-4" } as any;
const adapter = ModelAdapterFactory.createAdapter(mockModel);
const toolMetadata: ToolMetadata[] = [
createToolMetadata("localSearch", "LocalSearch specific instructions"),
createToolMetadata("webSearch", "WebSearch specific instructions"),
createToolMetadata("writeFile", "WriteToFile specific instructions"),
];
const enhancedPrompt = adapter.enhanceSystemPrompt(
basePrompt,
toolDescriptions,
["localSearch", "webSearch", "writeFile"],
toolMetadata
);
// Check that tool instructions are included
expect(enhancedPrompt).toContain("LocalSearch specific instructions");
expect(enhancedPrompt).toContain("WebSearch specific instructions");
expect(enhancedPrompt).toContain("WriteToFile specific instructions");
});
it("should only include instructions for enabled tools", () => {
const mockModel = { modelName: "gpt-4" } as any;
const adapter = ModelAdapterFactory.createAdapter(mockModel);
const toolMetadata: ToolMetadata[] = [
createToolMetadata("localSearch", "LocalSearch specific instructions"),
createToolMetadata("webSearch", "WebSearch specific instructions"),
createToolMetadata("writeFile", "WriteToFile specific instructions"),
];
// Only pass localSearch as enabled
const enhancedPrompt = adapter.enhanceSystemPrompt(
basePrompt,
toolDescriptions,
["localSearch"],
[toolMetadata[0]] // Only localSearch metadata
);
// Should include localSearch instructions
expect(enhancedPrompt).toContain("LocalSearch specific instructions");
// Should NOT include other tool instructions
expect(enhancedPrompt).not.toContain("WebSearch specific instructions");
expect(enhancedPrompt).not.toContain("WriteToFile specific instructions");
});
it("should include base structure elements", () => {
const mockModel = { modelName: "gpt-4" } as any;
const adapter = ModelAdapterFactory.createAdapter(mockModel);
const enhancedPrompt = adapter.enhanceSystemPrompt(basePrompt, toolDescriptions, [], []);
// Check base sections exist
expect(enhancedPrompt).toContain("# Autonomous Agent Mode");
expect(enhancedPrompt).toContain("## Time-based Queries");
expect(enhancedPrompt).toContain("## General Guidelines");
});
it("should handle GPT-specific enhancements", () => {
const mockModel = { modelName: "gpt-4" } as any;
const adapter = ModelAdapterFactory.createAdapter(mockModel);
const enhancedPrompt = adapter.enhanceSystemPrompt(basePrompt, toolDescriptions, [], []);
// Check GPT-specific sections
expect(enhancedPrompt).toContain("CRITICAL FOR GPT MODELS");
expect(enhancedPrompt).toContain("FINAL REMINDER FOR GPT MODELS");
});
it("should handle Claude-specific enhancements", () => {
const mockModel = { modelName: "claude-3-7-sonnet" } as any;
const adapter = ModelAdapterFactory.createAdapter(mockModel);
const enhancedPrompt = adapter.enhanceSystemPrompt(basePrompt, toolDescriptions, [], []);
// Check Claude-specific sections
expect(enhancedPrompt).toContain("IMPORTANT FOR CLAUDE THINKING MODELS");
});
it("should handle Gemini-specific enhancements", () => {
const mockModel = { modelName: "gemini-pro" } as any;
const adapter = ModelAdapterFactory.createAdapter(mockModel);
const enhancedPrompt = adapter.enhanceSystemPrompt(basePrompt, toolDescriptions, [], []);
// Check Gemini-specific sections
expect(enhancedPrompt).toContain("CRITICAL INSTRUCTIONS FOR GEMINI");
});
it("should exclude instructions when no metadata provided", () => {
const mockModel = { modelName: "gpt-4" } as any;
const adapter = ModelAdapterFactory.createAdapter(mockModel);
const enhancedPrompt = adapter.enhanceSystemPrompt(
basePrompt,
toolDescriptions,
["localSearch", "webSearch"],
[] // No metadata
);
// Should not include any tool-specific instructions
expect(enhancedPrompt).not.toContain("LocalSearch specific instructions");
expect(enhancedPrompt).not.toContain("WebSearch specific instructions");
});
it("should include composer-specific examples for GPT when file tools are enabled", () => {
const mockModel = { modelName: "gpt-4" } as any;
const adapter = ModelAdapterFactory.createAdapter(mockModel);
const enhancedPrompt = adapter.enhanceSystemPrompt(
basePrompt,
toolDescriptions,
["editFile", "writeFile"],
[]
);
// Check for composer-specific GPT instructions (simplified without XML examples)
expect(enhancedPrompt).toContain("FILE EDITING WITH COMPOSER TOOLS");
expect(enhancedPrompt).toContain("editFile");
expect(enhancedPrompt).toContain("writeFile");
expect(enhancedPrompt).toContain("oldText");
});
it("should rebuild enhanceSystemPrompt output from section metadata", () => {
const mockModel = { modelName: "gpt-4" } as any;
const adapter = ModelAdapterFactory.createAdapter(mockModel);
const sections = adapter.buildSystemPromptSections(basePrompt, toolDescriptions, [], []);
expect(sections.length).toBeGreaterThan(0);
expect(sections[0].id).toBe("base-system-prompt");
const reconstructed = joinPromptSections(sections);
const enhancedPrompt = adapter.enhanceSystemPrompt(basePrompt, toolDescriptions, [], []);
expect(reconstructed).toEqual(enhancedPrompt);
expect(enhancedPrompt).toContain("Available tools:\nTool descriptions here");
expect(enhancedPrompt).not.toContain("Available tools:\n\nTool descriptions here");
});
it("should enhance file editing messages for GPT", () => {
const mockModel = { modelName: "gpt-4" } as any;
const adapter = ModelAdapterFactory.createAdapter(mockModel);
const editMessage = "fix the typo in my note";
const enhanced = adapter.enhanceUserMessage(editMessage, true);
expect(enhanced).toContain("GPT REMINDER");
expect(enhanced).toContain("editFile");
expect(enhanced).toContain("oldText/newText parameters");
});
});
});