-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
43 lines (35 loc) · 858 Bytes
/
main.go
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
package main
import (
"context"
"fmt"
"os"
"github.com/devinyf/dashscopego"
"github.com/devinyf/dashscopego/embedding"
)
func main() {
model := embedding.TextEmbeddingV2
token := os.Getenv("DASHSCOPE_API_KEY")
if token == "" {
panic("token is empty")
}
textInputs := []string{"风急天高猿啸哀", "渚清沙白鸟飞回", "无边落木萧萧下", "不尽长江滚滚来"}
cli := dashscopego.NewTongyiClient(model, token)
ctx := context.TODO()
req := &embedding.Request{
Model: model,
Params: embedding.Params{
TextType: embedding.TypeDocument, // 默认值
},
Input: embedding.Input{
Texts: textInputs,
},
}
embeddings, totalToken, err := cli.CreateEmbedding(ctx, req)
if err != nil {
panic(err)
}
//nolint:all
fmt.Println("embeddings:", embeddings)
//nolint:all
fmt.Println("used tokens:", totalToken)
}