mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-28 06:24:40 +00:00
Community fixes for the docs-test runner. - Python examples run on Windows: the runner picks `.venv/Scripts/python.exe` and reports a missing venv as a failed test (#1487). - TypeScript examples exit 1 when `main()` rejects, so broken examples no longer count as passed (#1495). Co-Authored-By: abhinav7x94 <204053250+abhinav7x94@users.noreply.github.com>
124 lines
2.9 KiB
TypeScript
124 lines
2.9 KiB
TypeScript
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"), {
|
|
containerTag: "user-123",
|
|
customId: "conv-1",
|
|
})
|
|
console.log("✓ withSupermemory basic")
|
|
|
|
// With addMemory option
|
|
const _modelWithAdd = withSupermemory(openai("gpt-4"), {
|
|
containerTag: "user-123",
|
|
customId: "conv-1",
|
|
addMemory: "always",
|
|
})
|
|
console.log("✓ withSupermemory with addMemory")
|
|
|
|
// With verbose logging
|
|
const _modelVerbose = withSupermemory(openai("gpt-4"), {
|
|
containerTag: "user-123",
|
|
customId: "conv-1",
|
|
verbose: true,
|
|
})
|
|
console.log("✓ withSupermemory with verbose")
|
|
}
|
|
|
|
async function testSearchModes() {
|
|
console.log("\n=== Search Modes ===")
|
|
|
|
const _profileModel = withSupermemory(openai("gpt-4"), {
|
|
containerTag: "user-123",
|
|
customId: "conv-1",
|
|
mode: "profile",
|
|
})
|
|
console.log("✓ mode: profile")
|
|
|
|
const _queryModel = withSupermemory(openai("gpt-4"), {
|
|
containerTag: "user-123",
|
|
customId: "conv-1",
|
|
mode: "query",
|
|
})
|
|
console.log("✓ mode: query")
|
|
|
|
const _fullModel = withSupermemory(openai("gpt-4"), {
|
|
containerTag: "user-123",
|
|
customId: "conv-1",
|
|
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"), {
|
|
containerTag: "user-123",
|
|
customId: "conv-1",
|
|
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((error) => {
|
|
console.error(error)
|
|
process.exitCode = 1
|
|
})
|