From 60d7ed3fb5cf7da842e97eb1b85dcf397de75d37 Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Mon, 8 Apr 2024 13:48:36 +0800 Subject: [PATCH] fix: distributor panic --- middleware/distributor.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/middleware/distributor.go b/middleware/distributor.go index e922662..108c783 100644 --- a/middleware/distributor.go +++ b/middleware/distributor.go @@ -160,6 +160,10 @@ func getModelRequest(c *gin.Context) (*ModelRequest, bool, error) { } func SetupContextForSelectedChannel(c *gin.Context, channel *model.Channel, modelName string) { + c.Set("original_model", modelName) // for retry + if channel == nil { + return + } c.Set("channel", channel.Type) c.Set("channel_id", channel.Id) c.Set("channel_name", channel.Name) @@ -173,7 +177,6 @@ func SetupContextForSelectedChannel(c *gin.Context, channel *model.Channel, mode } c.Set("auto_ban", ban) c.Set("model_mapping", channel.GetModelMapping()) - c.Set("original_model", modelName) // for retry c.Request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", channel.Key)) c.Set("base_url", channel.GetBaseURL()) // TODO: api_version统一