aboutsummaryrefslogtreecommitdiff
path: root/packages/tools/test-supermemory.ts
blob: b3863c7ea316dbfb4049d4ed35ef7a7c0d941b27 (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
import { OpenAI } from "openai"
import { withSupermemory } from "./src/openai"

// Make sure to set these environment variables:
// OPENAI_API_KEY=your_openai_api_key
// SUPERMEMORY_API_KEY=your_supermemory_api_key

const openai = new OpenAI({
	apiKey: process.env.OPENAI_API_KEY,
})

// Wrap OpenAI client with supermemory
const openaiWithSupermemory = withSupermemory(openai, "test_user_123", {
	verbose: true, // Enable logging to see what's happening
	mode: "full", // Search both profile and query memories
	addMemory: "always", // Auto-save conversations as memories
})

// async function testChatCompletion() {
// 	console.log("\n=== Testing Chat Completion ===")
// 	const response = await openaiWithSupermemory.chat.completions.create({
// 		model: "gpt-4o-mini",
// 		messages: [
// 			{ role: "user", content: "My favorite color is blue" },
// 		],
// 	})

// 	console.log("Response:", response.choices[0]?.message.content)
// }

async function testResponses() {
	console.log("\n=== Testing Responses API ===")
	const response = await openaiWithSupermemory.chat.completions.create({
		model: "gpt-4o",
		messages: [{ role: "user", content: "what's my favoritge color?" }],
	})

	console.log(
		"Response:",
		JSON.stringify(response.choices[0]?.message.content, null, 2),
	)
}

// Run tests
async function main() {
	try {
		// await testChatCompletion()
		await testResponses()
	} catch (error) {
		console.error("Error:", error)
	}
}

main()