Skip to content

Commit 7272eff

Browse files
authored
update ai-cache extension (#1746)
1 parent a84a382 commit 7272eff

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

plugins/wasm-go/extensions/ai-cache/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LLM 结果缓存插件,默认配置方式可以直接用于 openai 协议的
3030

3131
## 配置说明
3232

33-
本插件同时支持基于向量数据库的语义化缓存和基于字符串匹配的缓存方法,如果同时配置了向量数据库和缓存数据库,优先使用向量数据库
33+
本插件同时支持基于向量数据库的语义化缓存和基于字符串匹配的缓存方法,如果同时配置了向量数据库和缓存数据库,优先使用缓存数据库,未命中场景下使用向量数据库能力
3434

3535
*Note*: 向量数据库(vector) 和 缓存数据库(cache) 不能同时为空,否则本插件无法提供缓存服务。
3636

plugins/wasm-go/extensions/ai-cache/main.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ func onHttpRequestBody(ctx wrapper.HttpContext, c config.PluginConfig, body []by
104104
key = strings.Join(userMessages, "\n")
105105
} else if c.CacheKeyStrategy == config.CACHE_KEY_STRATEGY_DISABLED {
106106
log.Info("[onHttpRequestBody] cache key strategy is disabled")
107-
ctx.DontReadRequestBody()
107+
ctx.DontReadResponseBody()
108108
return types.ActionContinue
109109
} else {
110110
log.Warnf("[onHttpRequestBody] unknown cache key strategy: %s", c.CacheKeyStrategy)
111-
ctx.DontReadRequestBody()
111+
ctx.DontReadResponseBody()
112112
return types.ActionContinue
113113
}
114114

@@ -147,19 +147,14 @@ func onHttpResponseHeaders(ctx wrapper.HttpContext, c config.PluginConfig, log w
147147
ctx.SetResponseBodyBufferLimit(DEFAULT_MAX_BODY_BYTES)
148148
}
149149

150-
if ctx.GetContext(ERROR_PARTIAL_MESSAGE_KEY) != nil {
151-
ctx.DontReadResponseBody()
152-
return types.ActionContinue
153-
}
154-
155150
return types.ActionContinue
156151
}
157152

158153
func onHttpResponseBody(ctx wrapper.HttpContext, c config.PluginConfig, chunk []byte, isLastChunk bool, log wrapper.Log) []byte {
159154
log.Debugf("[onHttpResponseBody] is last chunk: %v", isLastChunk)
160155
log.Debugf("[onHttpResponseBody] chunk: %s", string(chunk))
161156

162-
if ctx.GetContext(TOOL_CALLS_CONTEXT_KEY) != nil {
157+
if ctx.GetContext(TOOL_CALLS_CONTEXT_KEY) != nil || ctx.GetContext(ERROR_PARTIAL_MESSAGE_KEY) != nil {
163158
return chunk
164159
}
165160

0 commit comments

Comments
 (0)