Trim unexposed server-side state inputs and attach session_hash in Gradio call requests
This commit is contained in:
@@ -2350,6 +2350,54 @@ func InspectSpace(client *http.Client, rawURL, userAgent string) (*SpaceDiscover
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the endpoint has canonical parameters exposed via /gradio_api/info,
|
||||
// and trailing inputs in bestMatchingDep.Inputs are unexposed server-side state components,
|
||||
// do not pad them with null so Gradio preserves its internal server state.
|
||||
if bestEndpointInfo != nil && len(bestEndpointInfo.Parameters) > 0 && len(bestMatchingDep.Inputs) > len(bestEndpointInfo.Parameters) {
|
||||
allTrailingAreState := true
|
||||
for i := len(bestEndpointInfo.Parameters); i < len(bestMatchingDep.Inputs); i++ {
|
||||
cID := bestMatchingDep.Inputs[i]
|
||||
if comp, exists := compMap[cID]; exists {
|
||||
cType := strings.ToLower(comp.Type)
|
||||
if cType != "state" && cType != "browserstate" {
|
||||
allTrailingAreState = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if allTrailingAreState {
|
||||
discovery.TotalInputs = len(bestEndpointInfo.Parameters)
|
||||
discovery.DefaultInputs = discovery.DefaultInputs[:discovery.TotalInputs]
|
||||
if len(discovery.ParamMappings) > discovery.TotalInputs {
|
||||
discovery.ParamMappings = discovery.ParamMappings[:discovery.TotalInputs]
|
||||
}
|
||||
if discovery.MessageIndex >= discovery.TotalInputs {
|
||||
discovery.MessageIndex = -1
|
||||
}
|
||||
if discovery.HistoryIndex >= discovery.TotalInputs {
|
||||
discovery.HistoryIndex = -1
|
||||
}
|
||||
if discovery.SystemIndex >= discovery.TotalInputs {
|
||||
discovery.SystemIndex = -1
|
||||
}
|
||||
if discovery.FunctionsJSONIndex >= discovery.TotalInputs {
|
||||
discovery.FunctionsJSONIndex = -1
|
||||
}
|
||||
if discovery.TempIndex >= discovery.TotalInputs {
|
||||
discovery.TempIndex = -1
|
||||
}
|
||||
if discovery.MaxTokensIndex >= discovery.TotalInputs {
|
||||
discovery.MaxTokensIndex = -1
|
||||
}
|
||||
if discovery.TopPIndex >= discovery.TotalInputs {
|
||||
discovery.TopPIndex = -1
|
||||
}
|
||||
if discovery.StreamIndex >= discovery.TotalInputs {
|
||||
discovery.StreamIndex = -1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Refine history format or discover tools from bestEndpointInfo
|
||||
@@ -3415,7 +3463,10 @@ func (g *GradioGateway) ExecuteChatCompletion(w http.ResponseWriter, r *http.Req
|
||||
return g.executePredictCompletion(w, r, disc, gradioData, req, completionID, createdTime, modelName, effUA)
|
||||
}
|
||||
|
||||
payloadMap := map[string]interface{}{"data": gradioData}
|
||||
payloadMap := map[string]interface{}{
|
||||
"data": gradioData,
|
||||
"session_hash": GenerateUUID(),
|
||||
}
|
||||
jsonPayload, err := json.Marshal(payloadMap)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to encode request: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user