From 27a817b517d8c42465d0ce6add444a64531d2818 Mon Sep 17 00:00:00 2001 From: buhe Date: Sun, 21 Jan 2024 11:17:23 +0800 Subject: [PATCH] "Update cache only if llmResult has non-nil llm_output." --- Sources/LangChain/llms/LLM.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/LangChain/llms/LLM.swift b/Sources/LangChain/llms/LLM.swift index c958772..538fa00 100644 --- a/Sources/LangChain/llms/LLM.swift +++ b/Sources/LangChain/llms/LLM.swift @@ -36,7 +36,9 @@ public class LLM { } let llmResult = try await _send(text: text, stops: stops) if let cache = self.cache { - await cache.update(prompt: text, return_val: llmResult) + if llmResult.llm_output != nil { + await cache.update(prompt: text, return_val: llmResult) + } } cost = Date.now.timeIntervalSince1970 - now if !llmResult.stream {