feat: support mistral (#94)

This commit is contained in:
Buer
2024-03-10 01:53:33 +08:00
committed by GitHub
parent d8d880bf85
commit 6329db1a49
10 changed files with 340 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
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
}