🎨 结构中继控制器

This commit is contained in:
MartialBE
2023-12-02 03:28:18 +08:00
parent 2114bc1982
commit be364ae09b
45 changed files with 1267 additions and 204 deletions

View File

@@ -97,7 +97,7 @@ func (p *AliProvider) ChatAction(request *types.ChatCompletionRequest, isModelMa
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
if request.Stream {
@@ -157,7 +157,7 @@ func (p *AliProvider) sendStreamRequest(req *http.Request) (usage *types.Usage,
// 发送请求
resp, err := common.HttpClient.Do(req)
if err != nil {
return nil, types.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError)
}
if common.IsFailureStatusCode(resp) {

View File

@@ -59,7 +59,7 @@ func (p *AliProvider) EmbeddingsAction(request *types.EmbeddingRequest, isModelM
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
aliEmbeddingResponse := &AliEmbeddingResponse{}

View File

@@ -25,13 +25,13 @@ func (c *ImageAzureResponse) ResponseHandler(resp *http.Response) (OpenAIRespons
operation_location := resp.Header.Get("operation-location")
if operation_location == "" {
return nil, types.ErrorWrapper(errors.New("image url is empty"), "get_images_url_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(errors.New("image url is empty"), "get_images_url_failed", http.StatusInternalServerError)
}
client := common.NewClient()
req, err := client.NewRequest("GET", operation_location, common.WithHeader(c.Header))
if err != nil {
return nil, types.ErrorWrapper(err, "get_images_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "get_images_request_failed", http.StatusInternalServerError)
}
getImageAzureResponse := ImageAzureResponse{}
@@ -59,14 +59,14 @@ func (c *ImageAzureResponse) ResponseHandler(resp *http.Response) (OpenAIRespons
}
}
return nil, types.ErrorWrapper(errors.New("get image Timeout"), "get_images_url_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(errors.New("get image Timeout"), "get_images_url_failed", http.StatusInternalServerError)
}
func (p *AzureProvider) ImageGenerationsAction(request *types.ImageRequest, isModelMapped bool, promptTokens int) (usage *types.Usage, errWithCode *types.OpenAIErrorWithStatusCode) {
requestBody, err := p.GetRequestBody(&request, isModelMapped)
if err != nil {
return nil, types.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
}
fullRequestURL := p.GetFullRequestURL(p.ImagesGenerations, request.Model)
@@ -75,7 +75,7 @@ func (p *AzureProvider) ImageGenerationsAction(request *types.ImageRequest, isMo
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
if request.Model == "dall-e-2" {

View File

@@ -73,7 +73,7 @@ func (p *BaiduProvider) ChatAction(request *types.ChatCompletionRequest, isModel
requestBody := p.getChatRequestBody(request)
fullRequestURL := p.GetFullRequestURL(p.ChatCompletions, request.Model)
if fullRequestURL == "" {
return nil, types.ErrorWrapper(nil, "invalid_baidu_config", http.StatusInternalServerError)
return nil, common.ErrorWrapper(nil, "invalid_baidu_config", http.StatusInternalServerError)
}
headers := p.GetRequestHeaders()
@@ -84,7 +84,7 @@ func (p *BaiduProvider) ChatAction(request *types.ChatCompletionRequest, isModel
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
if request.Stream {
@@ -130,7 +130,7 @@ func (p *BaiduProvider) sendStreamRequest(req *http.Request) (usage *types.Usage
// 发送请求
resp, err := common.HttpClient.Do(req)
if err != nil {
return nil, types.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError)
}
if common.IsFailureStatusCode(resp) {

View File

@@ -48,14 +48,14 @@ func (p *BaiduProvider) EmbeddingsAction(request *types.EmbeddingRequest, isMode
requestBody := p.getEmbeddingsRequestBody(request)
fullRequestURL := p.GetFullRequestURL(p.Embeddings, request.Model)
if fullRequestURL == "" {
return nil, types.ErrorWrapper(nil, "invalid_baidu_config", http.StatusInternalServerError)
return nil, common.ErrorWrapper(nil, "invalid_baidu_config", http.StatusInternalServerError)
}
headers := p.GetRequestHeaders()
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
baiduEmbeddingResponse := &BaiduEmbeddingResponse{}

View File

@@ -79,19 +79,19 @@ func (p *BaseProvider) SendRequest(req *http.Request, response ProviderResponseH
p.Context.Writer.WriteHeader(resp.StatusCode)
_, err := io.Copy(p.Context.Writer, resp.Body)
if err != nil {
return types.ErrorWrapper(err, "copy_response_body_failed", http.StatusInternalServerError)
return common.ErrorWrapper(err, "copy_response_body_failed", http.StatusInternalServerError)
}
} else {
jsonResponse, err := json.Marshal(openAIResponse)
if err != nil {
return types.ErrorWrapper(err, "marshal_response_body_failed", http.StatusInternalServerError)
return common.ErrorWrapper(err, "marshal_response_body_failed", http.StatusInternalServerError)
}
p.Context.Writer.Header().Set("Content-Type", "application/json")
p.Context.Writer.WriteHeader(resp.StatusCode)
_, err = p.Context.Writer.Write(jsonResponse)
if err != nil {
return types.ErrorWrapper(err, "write_response_body_failed", http.StatusInternalServerError)
return common.ErrorWrapper(err, "write_response_body_failed", http.StatusInternalServerError)
}
}
@@ -104,7 +104,7 @@ func (p *BaseProvider) SendRequestRaw(req *http.Request) (openAIErrorWithStatusC
// 发送请求
resp, err := common.HttpClient.Do(req)
if err != nil {
return types.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError)
return common.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError)
}
defer resp.Body.Close()
@@ -122,7 +122,7 @@ func (p *BaseProvider) SendRequestRaw(req *http.Request) (openAIErrorWithStatusC
_, err = io.Copy(p.Context.Writer, resp.Body)
if err != nil {
return types.ErrorWrapper(err, "write_response_body_failed", http.StatusInternalServerError)
return common.ErrorWrapper(err, "write_response_body_failed", http.StatusInternalServerError)
}
return nil

View File

@@ -88,7 +88,7 @@ func (p *ClaudeProvider) ChatAction(request *types.ChatCompletionRequest, isMode
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
if request.Stream {
@@ -139,7 +139,7 @@ func (p *ClaudeProvider) sendStreamRequest(req *http.Request) (*types.OpenAIErro
// 发送请求
resp, err := common.HttpClient.Do(req)
if err != nil {
return types.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError), ""
return common.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError), ""
}
if common.IsFailureStatusCode(resp) {

View File

@@ -106,7 +106,7 @@ func (p *OpenAIProvider) sendStreamRequest(req *http.Request, response OpenAIPro
resp, err := common.HttpClient.Do(req)
if err != nil {
return types.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError), ""
return common.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError), ""
}
if common.IsFailureStatusCode(resp) {

View File

@@ -28,7 +28,7 @@ func (c *OpenAIProviderChatStreamResponse) responseStreamHandler() (responseText
func (p *OpenAIProvider) ChatAction(request *types.ChatCompletionRequest, isModelMapped bool, promptTokens int) (usage *types.Usage, errWithCode *types.OpenAIErrorWithStatusCode) {
requestBody, err := p.GetRequestBody(&request, isModelMapped)
if err != nil {
return nil, types.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
}
fullRequestURL := p.GetFullRequestURL(p.ChatCompletions, request.Model)
@@ -40,7 +40,7 @@ func (p *OpenAIProvider) ChatAction(request *types.ChatCompletionRequest, isMode
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
if request.Stream {

View File

@@ -28,7 +28,7 @@ func (c *OpenAIProviderCompletionResponse) responseStreamHandler() (responseText
func (p *OpenAIProvider) CompleteAction(request *types.CompletionRequest, isModelMapped bool, promptTokens int) (usage *types.Usage, errWithCode *types.OpenAIErrorWithStatusCode) {
requestBody, err := p.GetRequestBody(&request, isModelMapped)
if err != nil {
return nil, types.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
}
fullRequestURL := p.GetFullRequestURL(p.Completions, request.Model)
@@ -40,7 +40,7 @@ func (p *OpenAIProvider) CompleteAction(request *types.CompletionRequest, isMode
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
openAIProviderCompletionResponse := &OpenAIProviderCompletionResponse{}

View File

@@ -21,7 +21,7 @@ func (p *OpenAIProvider) EmbeddingsAction(request *types.EmbeddingRequest, isMod
requestBody, err := p.GetRequestBody(&request, isModelMapped)
if err != nil {
return nil, types.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
}
fullRequestURL := p.GetFullRequestURL(p.Embeddings, request.Model)
@@ -30,7 +30,7 @@ func (p *OpenAIProvider) EmbeddingsAction(request *types.EmbeddingRequest, isMod
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
openAIProviderEmbeddingsResponse := &OpenAIProviderEmbeddingsResponse{}

View File

@@ -20,7 +20,7 @@ func (p *OpenAIProvider) ImageEditsAction(request *types.ImageEditRequest, isMod
if isModelMapped {
builder := client.CreateFormBuilder(&formBody)
if err := imagesEditsMultipartForm(request, builder); err != nil {
return nil, types.ErrorWrapper(err, "create_form_builder_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "create_form_builder_failed", http.StatusInternalServerError)
}
req, err = client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(&formBody), common.WithHeader(headers), common.WithContentType(builder.FormDataContentType()))
req.ContentLength = int64(formBody.Len())
@@ -31,7 +31,7 @@ func (p *OpenAIProvider) ImageEditsAction(request *types.ImageEditRequest, isMod
}
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
openAIProviderImageResponseResponse := &OpenAIProviderImageResponseResponse{}

View File

@@ -21,7 +21,7 @@ func (p *OpenAIProvider) ImageGenerationsAction(request *types.ImageRequest, isM
requestBody, err := p.GetRequestBody(&request, isModelMapped)
if err != nil {
return nil, types.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
}
fullRequestURL := p.GetFullRequestURL(p.ImagesGenerations, request.Model)
@@ -30,7 +30,7 @@ func (p *OpenAIProvider) ImageGenerationsAction(request *types.ImageRequest, isM
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
openAIProviderImageResponseResponse := &OpenAIProviderImageResponseResponse{}

View File

@@ -19,7 +19,7 @@ func (p *OpenAIProvider) ImageVariationsAction(request *types.ImageEditRequest,
if isModelMapped {
builder := client.CreateFormBuilder(&formBody)
if err := imagesEditsMultipartForm(request, builder); err != nil {
return nil, types.ErrorWrapper(err, "create_form_builder_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "create_form_builder_failed", http.StatusInternalServerError)
}
req, err = client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(&formBody), common.WithHeader(headers), common.WithContentType(builder.FormDataContentType()))
req.ContentLength = int64(formBody.Len())
@@ -30,7 +30,7 @@ func (p *OpenAIProvider) ImageVariationsAction(request *types.ImageEditRequest,
}
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
openAIProviderImageResponseResponse := &OpenAIProviderImageResponseResponse{}

View File

@@ -21,7 +21,7 @@ func (p *OpenAIProvider) ModerationAction(request *types.ModerationRequest, isMo
requestBody, err := p.GetRequestBody(&request, isModelMapped)
if err != nil {
return nil, types.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
}
fullRequestURL := p.GetFullRequestURL(p.Moderation, request.Model)
@@ -30,7 +30,7 @@ func (p *OpenAIProvider) ModerationAction(request *types.ModerationRequest, isMo
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
openAIProviderModerationResponse := &OpenAIProviderModerationResponse{}

View File

@@ -10,7 +10,7 @@ func (p *OpenAIProvider) SpeechAction(request *types.SpeechAudioRequest, isModel
requestBody, err := p.GetRequestBody(&request, isModelMapped)
if err != nil {
return nil, types.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
}
fullRequestURL := p.GetFullRequestURL(p.AudioSpeech, request.Model)
@@ -19,7 +19,7 @@ func (p *OpenAIProvider) SpeechAction(request *types.SpeechAudioRequest, isModel
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
errWithCode = p.SendRequestRaw(req)

View File

@@ -39,7 +39,7 @@ func (p *OpenAIProvider) TranscriptionsAction(request *types.AudioRequest, isMod
if isModelMapped {
builder := client.CreateFormBuilder(&formBody)
if err := audioMultipartForm(request, builder); err != nil {
return nil, types.ErrorWrapper(err, "create_form_builder_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "create_form_builder_failed", http.StatusInternalServerError)
}
req, err = client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(&formBody), common.WithHeader(headers), common.WithContentType(builder.FormDataContentType()))
req.ContentLength = int64(formBody.Len())
@@ -50,7 +50,7 @@ func (p *OpenAIProvider) TranscriptionsAction(request *types.AudioRequest, isMod
}
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
var textResponse string

View File

@@ -19,7 +19,7 @@ func (p *OpenAIProvider) TranslationAction(request *types.AudioRequest, isModelM
if isModelMapped {
builder := client.CreateFormBuilder(&formBody)
if err := audioMultipartForm(request, builder); err != nil {
return nil, types.ErrorWrapper(err, "create_form_builder_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "create_form_builder_failed", http.StatusInternalServerError)
}
req, err = client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(&formBody), common.WithHeader(headers), common.WithContentType(builder.FormDataContentType()))
req.ContentLength = int64(formBody.Len())
@@ -30,7 +30,7 @@ func (p *OpenAIProvider) TranslationAction(request *types.AudioRequest, isModelM
}
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
var textResponse string

View File

@@ -82,7 +82,7 @@ func (p *PalmProvider) ChatAction(request *types.ChatCompletionRequest, isModelM
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
if request.Stream {
@@ -133,7 +133,7 @@ func (p *PalmProvider) sendStreamRequest(req *http.Request) (*types.OpenAIErrorW
// 发送请求
resp, err := common.HttpClient.Do(req)
if err != nil {
return types.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError), ""
return common.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError), ""
}
if common.IsFailureStatusCode(resp) {

View File

@@ -82,7 +82,7 @@ func (p *TencentProvider) ChatAction(request *types.ChatCompletionRequest, isMod
requestBody := p.getChatRequestBody(request)
sign := p.getTencentSign(*requestBody)
if sign == "" {
return nil, types.ErrorWrapper(errors.New("get tencent sign failed"), "get_tencent_sign_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(errors.New("get tencent sign failed"), "get_tencent_sign_failed", http.StatusInternalServerError)
}
fullRequestURL := p.GetFullRequestURL(p.ChatCompletions, request.Model)
@@ -95,7 +95,7 @@ func (p *TencentProvider) ChatAction(request *types.ChatCompletionRequest, isMod
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
if request.Stream {
@@ -144,7 +144,7 @@ func (p *TencentProvider) sendStreamRequest(req *http.Request) (*types.OpenAIErr
// 发送请求
resp, err := common.HttpClient.Do(req)
if err != nil {
return types.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError), ""
return common.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError), ""
}
if common.IsFailureStatusCode(resp) {

View File

@@ -26,7 +26,7 @@ func (p *XunfeiProvider) sendRequest(request *types.ChatCompletionRequest, authU
usage = &types.Usage{}
dataChan, stopChan, err := p.xunfeiMakeRequest(request, authUrl)
if err != nil {
return nil, types.ErrorWrapper(err, "make xunfei request err", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "make xunfei request err", http.StatusInternalServerError)
}
var content string
@@ -51,7 +51,7 @@ func (p *XunfeiProvider) sendRequest(request *types.ChatCompletionRequest, authU
response := p.responseXunfei2OpenAI(&xunfeiResponse)
jsonResponse, err := json.Marshal(response)
if err != nil {
return nil, types.ErrorWrapper(err, "marshal_response_body_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "marshal_response_body_failed", http.StatusInternalServerError)
}
p.Context.Writer.Header().Set("Content-Type", "application/json")
_, _ = p.Context.Writer.Write(jsonResponse)
@@ -62,7 +62,7 @@ func (p *XunfeiProvider) sendStreamRequest(request *types.ChatCompletionRequest,
usage = &types.Usage{}
dataChan, stopChan, err := p.xunfeiMakeRequest(request, authUrl)
if err != nil {
return nil, types.ErrorWrapper(err, "make xunfei request err", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "make xunfei request err", http.StatusInternalServerError)
}
common.SetEventStreamHeaders(p.Context)
p.Context.Stream(func(w io.Writer) bool {

View File

@@ -90,7 +90,7 @@ func (p *ZhipuProvider) ChatAction(request *types.ChatCompletionRequest, isModel
client := common.NewClient()
req, err := client.NewRequest(p.Context.Request.Method, fullRequestURL, common.WithBody(requestBody), common.WithHeader(headers))
if err != nil {
return nil, types.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
return nil, common.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
}
if request.Stream {
@@ -144,7 +144,7 @@ func (p *ZhipuProvider) sendStreamRequest(req *http.Request) (*types.OpenAIError
// 发送请求
resp, err := common.HttpClient.Do(req)
if err != nil {
return types.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError), nil
return common.ErrorWrapper(err, "http_request_failed", http.StatusInternalServerError), nil
}
if common.IsFailureStatusCode(resp) {