mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-29 22:56:39 +08:00
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package mistral
|
|
|
|
import (
|
|
"net/http"
|
|
"one-api/common"
|
|
"one-api/types"
|
|
)
|
|
|
|
func (p *MistralProvider) CreateEmbeddings(request *types.EmbeddingRequest) (*types.EmbeddingResponse, *types.OpenAIErrorWithStatusCode) {
|
|
url, errWithCode := p.GetSupportedAPIUri(common.RelayModeEmbeddings)
|
|
if errWithCode != nil {
|
|
return nil, errWithCode
|
|
}
|
|
// 获取请求地址
|
|
fullRequestURL := p.GetFullRequestURL(url, request.Model)
|
|
if fullRequestURL == "" {
|
|
return nil, common.ErrorWrapper(nil, "invalid_mistral_config", http.StatusInternalServerError)
|
|
}
|
|
|
|
// 获取请求头
|
|
headers := p.GetRequestHeaders()
|
|
|
|
// 创建请求
|
|
req, err := p.Requester.NewRequest(http.MethodPost, fullRequestURL, p.Requester.WithBody(request), p.Requester.WithHeader(headers))
|
|
if err != nil {
|
|
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
|
|
}
|
|
defer req.Body.Close()
|
|
|
|
mistralResponse := &types.EmbeddingResponse{}
|
|
|
|
// 发送请求
|
|
_, errWithCode = p.Requester.SendRequest(req, mistralResponse, false)
|
|
if errWithCode != nil {
|
|
return nil, errWithCode
|
|
}
|
|
|
|
return mistralResponse, nil
|
|
}
|