From 68ce68f2903603b072f4c6f2d843dd96e9c744ff Mon Sep 17 00:00:00 2001 From: Peng Qu <82029664+pengqu123@users.noreply.github.com> Date: Sat, 4 Mar 2023 23:56:07 +0800 Subject: [PATCH] Fix an unusual issue that occurs when using OpenAIChat for llm_math (#1410) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix an issue that occurs when using OpenAIChat for llm_math, refer to the code style of the "Final Answer:" in Mrkl。 the reason is I found a issue when I try OpenAIChat for llm_math, when I try the question in Chinese, the model generate the format like "\n\nQuestion: What is the square of 29?\nAnswer: 841", it translate the question first , then answer. below is my snapshot: snapshot --- langchain/chains/llm_math/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/langchain/chains/llm_math/base.py b/langchain/chains/llm_math/base.py index e7e9c3a6..3faebe3a 100644 --- a/langchain/chains/llm_math/base.py +++ b/langchain/chains/llm_math/base.py @@ -62,6 +62,8 @@ class LLMMathChain(Chain, BaseModel): answer = "Answer: " + output elif t.startswith("Answer:"): answer = t + elif "Answer:" in t: + answer = "Answer: " + t.split("Answer:")[-1] else: raise ValueError(f"unknown format from LLM: {t}") return {self.output_key: answer}