aboutsummaryrefslogtreecommitdiff
path: root/packages/docs-test/tests/integrations/ai-sdk.ts
blob: f6d4f1d2b431186d16b4cc04d46497e7870582fa (plain) (blame)
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
import "dotenv/config"
import { openai } from "@ai-sdk/openai"
import { createAnthropic } from "@ai-sdk/anthropic"
import {
	withSupermemory,
	supermemoryTools,
	searchMemoriesTool,
	addMemoryTool,
	type MemoryPromptData,
} from "@supermemory/tools/ai-sdk"

async function testMiddleware() {
	console.log("=== Middleware ===")

	// Basic wrapper
	const model = withSupermemory(openai("gpt-4"), "user-123")
	console.log("✓ withSupermemory basic")

	// With addMemory option
	const modelWithAdd = withSupermemory(openai("gpt-4"), "user-123", {
		addMemory: "always",
	})
	console.log("✓ withSupermemory with addMemory")

	// With verbose logging
	const modelVerbose = withSupermemory(openai("gpt-4"), "user-123", {
		verbose: true,
	})
	console.log("✓ withSupermemory with verbose")
}

async function testSearchModes() {
	console.log("\n=== Search Modes ===")

	const profileModel = withSupermemory(openai("gpt-4"), "user-123", {
		mode: "profile",
	})
	console.log("✓ mode: profile")

	const queryModel = withSupermemory(openai("gpt-4"), "user-123", {
		mode: "query",
	})
	console.log("✓ mode: query")

	const fullModel = withSupermemory(openai("gpt-4"), "user-123", {
		mode: "full",
	})
	console.log("✓ mode: full")
}

async function testCustomPrompt() {
	console.log("\n=== Custom Prompt Template ===")

	const anthropic = createAnthropic({ apiKey: "test-key" })

	const claudePrompt = (data: MemoryPromptData) =>
		`
<context>
  <user_profile>${data.userMemories}</user_profile>
  <relevant_memories>${data.generalSearchMemories}</relevant_memories>
</context>
`.trim()

	const model = withSupermemory(
		anthropic("claude-3-sonnet-20240229"),
		"user-123",
		{
			mode: "full",
			promptTemplate: claudePrompt,
		},
	)
	console.log("✓ Custom prompt template")
}

async function testTools() {
	console.log("\n=== Memory Tools ===")

	// All tools
	const tools = supermemoryTools("YOUR_API_KEY")
	console.log("✓ supermemoryTools")

	// Individual tools
	const searchTool = searchMemoriesTool("API_KEY", { projectId: "personal" })
	console.log("✓ searchMemoriesTool")

	const addTool = addMemoryTool("API_KEY")
	console.log("✓ addMemoryTool")

	// Combined
	const toolsObj = {
		searchMemories: searchTool,
		addMemory: addTool,
	}
	console.log("✓ Combined tools object")
}

async function main() {
	console.log("AI SDK Integration Tests")
	console.log("========================\n")

	await testMiddleware()
	await testSearchModes()
	await testCustomPrompt()
	await testTools()

	console.log("\n========================")
	console.log("✅ All AI SDK tests passed!")
}

main().catch(console.error)