-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (35 loc) · 981 Bytes
/
Copy pathmain.go
File metadata and controls
42 lines (35 loc) · 981 Bytes
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
package main
import (
"context"
"fmt"
"log"
"os"
openrouter "github.com/OpenRouterTeam/go-sdk"
"github.com/OpenRouterTeam/go-sdk/models/operations"
)
func main() {
ctx := context.Background()
s := openrouter.New(
openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
)
res, err := s.Embeddings.Generate(ctx, operations.CreateEmbeddingsRequest{
Model: "openai/text-embedding-3-small",
Input: operations.CreateInputUnionStr("OpenRouter Go SDK embed example"),
})
if err != nil {
log.Fatal(err)
}
if res == nil || res.CreateEmbeddingsResponseBody == nil {
log.Fatal("empty embeddings response")
}
body := res.CreateEmbeddingsResponseBody
fmt.Printf("model: %s\n", body.Model)
if body.Usage != nil {
fmt.Printf("tokens: %d\n", body.Usage.TotalTokens)
}
for _, item := range body.Data {
if item.Embedding.Type == operations.EmbeddingTypeArrayOfNumber {
fmt.Printf("embedding dimensions: %d\n", len(item.Embedding.ArrayOfNumber))
}
}
}