跳到主要内容

math_utils

解决问题

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

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

参数:

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

返回:

  • str - 问题的解决方案。

remove_boxed

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

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

示例:

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

\frac{2}{3}

last_boxed_only_string

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

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

is_equiv

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

返回(作为浮点数)两个包含数学的字符串在格式化差异方面是否等效

is_equiv_chain_of_thought

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

在调用is_equiv之前先清理解决方案。

eval_math_responses

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

使用投票为数学问题选择一个响应,如果提供了解决方案,则检查响应是否正确。

参数:

  • responses 列表 - 响应列表。
  • solution str - 规范解决方案。

返回:

  • dict - 成功指标。