Skip to main content

数学工具

解决问题

def solve_problem(problem: str, **config) -> str

(openai<1) 解决数学问题。

参数

  • problem str - 问题描述。
  • config 可选, dict - API 调用的配置。

返回值

  • str - 问题的解决方案。

移除方框

def remove_boxed(string: str) -> Optional[str]

来源:https://github.com/hendrycks/math 提取 \boxed{...} 环境中的文本。

示例

remove_boxed("\boxed{\frac{2}{3}}")

\frac{2}{3}

最后一个方框内的字符串

def last_boxed_only_string(string: str) -> Optional[str]

来源:https://github.com/hendrycks/math 从字符串中提取最后一个 \boxed{...} 或 \fbox{...} 元素。

判断等价性

def is_equiv(str1: Optional[str], str2: Optional[str]) -> float

返回(作为浮点数)两个包含数学内容的字符串是否在以下方面等价,即格式的差异:

判断思路链的等价性

def is_equiv_chain_of_thought(str1: str, str2: str) -> float

在调用 is_equiv 之前先去除解决方案。

评估数学回答

def eval_math_responses(responses, solution=None, **args)

使用投票选择数学问题的回答,并在提供解决方案的情况下检查回答是否正确。

参数

  • responses list - 回答列表。
  • solution str - 规范解决方案。

返回值

  • dict - 成功指标。