mirror of
https://github.com/hanzoai/dashscopego.git
synced 2026-10-30 18:41:14 +00:00
28 lines
656 B
Go
28 lines
656 B
Go
package embedding
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hanzoai/dashscopego/httpclient"
|
|
)
|
|
|
|
//nolint:lll
|
|
func CreateEmbedding(ctx context.Context, req *Request, cli httpclient.IHttpClient, token string) (*Response, error) {
|
|
if req.Model == "" {
|
|
req.Model = TextEmbeddingV2
|
|
}
|
|
if req.Params.TextType == "" {
|
|
req.Params.TextType = TypeDocument
|
|
}
|
|
|
|
resp := Response{}
|
|
tokenOption := httpclient.WithTokenHeaderOption(token)
|
|
headerOption := httpclient.WithHeader(httpclient.HeaderMap{"content-type": "application/json"})
|
|
err := cli.Post(ctx, embeddingURL, req, &resp, tokenOption, headerOption)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &resp, nil
|
|
}
|