-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-examples.ts
More file actions
42 lines (34 loc) · 1.35 KB
/
test-examples.ts
File metadata and controls
42 lines (34 loc) · 1.35 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
#!/usr/bin/env tsx
import { Opper } from "./src/index.js";
// Configuration - you can set these environment variables or modify them here
const OPPER_API_KEY = process.env.OPPER_API_KEY || process.env.OPPER_HTTP_BEARER;
if (!OPPER_API_KEY) {
console.error("Error: OPPER_API_KEY or OPPER_HTTP_BEARER environment variable required");
process.exit(1);
}
const OPPER_SERVER_URL = process.env.OPPER_SERVER_URL || "https://api.opper.ai/v2";
const opper = new Opper({
serverURL: OPPER_SERVER_URL,
httpBearer: OPPER_API_KEY,
});
// Create embedding for a single text
const singleEmbedding = await opper.embeddings.create({
input: "The quick brown fox jumps over the lazy dog",
model: "azure/text-embedding-3-large"
});
console.log(`Model: ${singleEmbedding.model}`);
console.log(`Embedding dimensions: ${singleEmbedding.data[0].embedding.length}`);
console.log(`Usage:`, singleEmbedding.usage);
// Create embeddings for multiple texts
const multipleEmbeddings = await opper.embeddings.create({
input: [
"What is machine learning?",
"How do neural networks work?",
"Explain artificial intelligence"
],
model: "azure/text-embedding-3-large"
});
console.log(`\nCreated ${multipleEmbeddings.data.length} embeddings`);
multipleEmbeddings.data.forEach((embeddingData, i) => {
console.log(`Embedding ${i}: ${embeddingData.embedding.length} dimensions`);
});