mirror of
				https://github.com/linux-do/new-api.git
				synced 2025-11-04 05:13:41 +08:00 
			
		
		
		
	feat: 上游渠道为OpenAI渠道类型时,透传请求 (close #532)
This commit is contained in:
		@@ -76,6 +76,7 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// map model name
 | 
			
		||||
	isModelMapped := false
 | 
			
		||||
	modelMapping := c.GetString("model_mapping")
 | 
			
		||||
	//isModelMapped := false
 | 
			
		||||
	if modelMapping != "" && modelMapping != "{}" {
 | 
			
		||||
@@ -85,6 +86,7 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
 | 
			
		||||
			return service.OpenAIErrorWrapperLocal(err, "unmarshal_model_mapping_failed", http.StatusInternalServerError)
 | 
			
		||||
		}
 | 
			
		||||
		if modelMap[textRequest.Model] != "" {
 | 
			
		||||
			isModelMapped = true
 | 
			
		||||
			textRequest.Model = modelMap[textRequest.Model]
 | 
			
		||||
			// set upstream model name
 | 
			
		||||
			//isModelMapped = true
 | 
			
		||||
@@ -159,6 +161,13 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
 | 
			
		||||
	adaptor.Init(relayInfo)
 | 
			
		||||
	var requestBody io.Reader
 | 
			
		||||
 | 
			
		||||
	if relayInfo.ChannelType == common.ChannelTypeOpenAI && !isModelMapped {
 | 
			
		||||
		body, err := common.GetRequestBody(c)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return service.OpenAIErrorWrapperLocal(err, "get_request_body_failed", http.StatusInternalServerError)
 | 
			
		||||
		}
 | 
			
		||||
		requestBody = bytes.NewBuffer(body)
 | 
			
		||||
	} else {
 | 
			
		||||
		convertedRequest, err := adaptor.ConvertRequest(c, relayInfo, textRequest)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return service.OpenAIErrorWrapperLocal(err, "convert_request_failed", http.StatusInternalServerError)
 | 
			
		||||
@@ -168,6 +177,7 @@ func TextHelper(c *gin.Context) *dto.OpenAIErrorWithStatusCode {
 | 
			
		||||
			return service.OpenAIErrorWrapperLocal(err, "json_marshal_failed", http.StatusInternalServerError)
 | 
			
		||||
		}
 | 
			
		||||
		requestBody = bytes.NewBuffer(jsonData)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	statusCodeMappingStr := c.GetString("status_code_mapping")
 | 
			
		||||
	resp, err := adaptor.DoRequest(c, relayInfo, requestBody)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user