refactor(openai): 移除不必要的 seedOpenAISessionHeaders 函数
This commit is contained in:
@@ -96,8 +96,6 @@ func (h *OpenAIGatewayHandler) Responses(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
seedOpenAISessionHeaders(c, reqBody)
|
||||
|
||||
userAgent := c.GetHeader("User-Agent")
|
||||
if !openai.IsCodexCLIRequest(userAgent) {
|
||||
existingInstructions, _ := reqBody["instructions"].(string)
|
||||
@@ -301,37 +299,6 @@ func (h *OpenAIGatewayHandler) handleFailoverExhausted(c *gin.Context, statusCod
|
||||
h.handleStreamingAwareError(c, status, errType, errMsg, streamStarted)
|
||||
}
|
||||
|
||||
func seedOpenAISessionHeaders(c *gin.Context, reqBody map[string]any) {
|
||||
if c.GetHeader("session_id") == "" {
|
||||
if v := firstNonEmptyString(
|
||||
reqBody["prompt_cache_key"],
|
||||
reqBody["session_id"],
|
||||
reqBody["conversation_id"],
|
||||
reqBody["previous_response_id"],
|
||||
); v != "" {
|
||||
c.Request.Header.Set("session_id", v)
|
||||
}
|
||||
}
|
||||
if c.GetHeader("conversation_id") == "" {
|
||||
if v := firstNonEmptyString(reqBody["prompt_cache_key"], reqBody["conversation_id"]); v != "" {
|
||||
c.Request.Header.Set("conversation_id", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func firstNonEmptyString(values ...any) string {
|
||||
for _, value := range values {
|
||||
s, ok := value.(string)
|
||||
if ok {
|
||||
s = strings.TrimSpace(s)
|
||||
if s != "" {
|
||||
return s
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (h *OpenAIGatewayHandler) mapUpstreamError(statusCode int) (int, string, string) {
|
||||
switch statusCode {
|
||||
case 401:
|
||||
|
||||
Reference in New Issue
Block a user