From e78b914b0bf33bd1ac308f8eba5c01cb2bac76f4 Mon Sep 17 00:00:00 2001 From: qhd <1766646056@qq.com> Date: Tue, 1 Sep 2026 10:19:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=87=8D=E8=AF=95=E8=AE=B0=E5=BF=86=E8=A1=A8/entity/consts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consts/public/table_name.go | 1 + model/entity/error_memory.go | 37 ++++++++++++++++++++++++++++++++++++ update.sql | 26 ++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 model/entity/error_memory.go diff --git a/consts/public/table_name.go b/consts/public/table_name.go index a7486f3..7980793 100644 --- a/consts/public/table_name.go +++ b/consts/public/table_name.go @@ -9,4 +9,5 @@ const ( TableNameModelSession = "model_session" TableNameModelTaskStart = "model_task_start" TableNameModelTaskEnd = "model_task_end" + TableNameErrorMemory = "error_memory" ) diff --git a/model/entity/error_memory.go b/model/entity/error_memory.go new file mode 100644 index 0000000..c71df0e --- /dev/null +++ b/model/entity/error_memory.go @@ -0,0 +1,37 @@ +package entity + +import "gitea.redpowerfuture.com/red-future/common/beans" + +type errorMemoryCol struct { + beans.SQLBaseCol + MemoryKey string + Upstream string + ErrorCode string + MsgFingerprint string + Retryable string + Reason string + AnalyzedBy string +} + +var ErrorMemoryCol = errorMemoryCol{ + SQLBaseCol: beans.DefSQLBaseCol, + MemoryKey: "memory_key", + Upstream: "upstream", + ErrorCode: "error_code", + MsgFingerprint: "msg_fingerprint", + Retryable: "retryable", + Reason: "reason", + AnalyzedBy: "analyzed_by", +} + +// ErrorMemory 错误重试记忆(LLM 分析结论持久化,永久有效) +type ErrorMemory struct { + beans.SQLBaseDO `orm:",inline"` + MemoryKey string `orm:"memory_key" json:"memoryKey" dc:"记忆键=SHA-256(upstream|code|归一化消息)"` + Upstream string `orm:"upstream" json:"upstream" dc:"失败上游BaseURL"` + ErrorCode string `orm:"error_code" json:"errorCode" dc:"错误码"` + MsgFingerprint string `orm:"msg_fingerprint" json:"msgFingerprint" dc:"归一化消息md5"` + Retryable bool `orm:"retryable" json:"retryable" dc:"是否可重试"` + Reason string `orm:"reason" json:"reason" dc:"分析原因"` + AnalyzedBy string `orm:"analyzed_by" json:"analyzedBy" dc:"分析模型名"` +} diff --git a/update.sql b/update.sql index 6f7f2d2..83de068 100644 --- a/update.sql +++ b/update.sql @@ -361,4 +361,28 @@ WHERE r.system_model = false AND s.system_model = true ALTER TABLE model_gateway_model_manage ADD COLUMN IF NOT EXISTS error_message_mapping JSONB DEFAULT NULL; COMMENT ON COLUMN model_gateway_model_manage.error_message_mapping - IS '错误消息映射:{code,message} 的 schema 树(type/attrs/value/defaultValue),解析模型错误响应,defaultValue 为成功码'; \ No newline at end of file + IS '错误消息映射:{code,message} 的 schema 树(type/attrs/value/defaultValue),解析模型错误响应,defaultValue 为成功码'; + +-- ========================= +-- 错误重试记忆:LLM 分析上游模型错误是否可重试的持久知识库 +-- memory_key = SHA-256(upstream|error_code|归一化消息),唯一;命中直接复用,永久有效 +-- ========================= +CREATE TABLE IF NOT EXISTS model_gateway_error_memory ( + id BIGSERIAL PRIMARY KEY, + tenant_id BIGINT DEFAULT 0, + creator VARCHAR(64) DEFAULT '', + created_at TIMESTAMPTZ DEFAULT now(), + updater VARCHAR(64) DEFAULT '', + updated_at TIMESTAMPTZ DEFAULT now(), + deleted_at TIMESTAMPTZ DEFAULT NULL, + memory_key CHAR(64) NOT NULL, + upstream VARCHAR(512) NOT NULL DEFAULT '', + error_code VARCHAR(128) NOT NULL DEFAULT '', + msg_fingerprint CHAR(32) NOT NULL DEFAULT '', + retryable BOOLEAN NOT NULL DEFAULT false, + reason VARCHAR(512) NOT NULL DEFAULT '', + analyzed_by VARCHAR(128) NOT NULL DEFAULT '' +); +CREATE UNIQUE INDEX IF NOT EXISTS uk_error_memory_memory_key + ON model_gateway_error_memory (memory_key) + WHERE deleted_at IS NULL; \ No newline at end of file