ag2 0.4.1__py3-none-any.whl → 0.4.2b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ag2 might be problematic. Click here for more details.
- ag2-0.4.2b1.dist-info/METADATA +19 -0
- ag2-0.4.2b1.dist-info/RECORD +6 -0
- ag2-0.4.2b1.dist-info/top_level.txt +1 -0
- ag2-0.4.1.dist-info/METADATA +0 -500
- ag2-0.4.1.dist-info/RECORD +0 -158
- ag2-0.4.1.dist-info/top_level.txt +0 -1
- autogen/__init__.py +0 -17
- autogen/_pydantic.py +0 -116
- autogen/agentchat/__init__.py +0 -42
- autogen/agentchat/agent.py +0 -142
- autogen/agentchat/assistant_agent.py +0 -85
- autogen/agentchat/chat.py +0 -306
- autogen/agentchat/contrib/__init__.py +0 -0
- autogen/agentchat/contrib/agent_builder.py +0 -788
- autogen/agentchat/contrib/agent_eval/agent_eval.py +0 -107
- autogen/agentchat/contrib/agent_eval/criterion.py +0 -47
- autogen/agentchat/contrib/agent_eval/critic_agent.py +0 -47
- autogen/agentchat/contrib/agent_eval/quantifier_agent.py +0 -42
- autogen/agentchat/contrib/agent_eval/subcritic_agent.py +0 -48
- autogen/agentchat/contrib/agent_eval/task.py +0 -43
- autogen/agentchat/contrib/agent_optimizer.py +0 -450
- autogen/agentchat/contrib/capabilities/__init__.py +0 -0
- autogen/agentchat/contrib/capabilities/agent_capability.py +0 -21
- autogen/agentchat/contrib/capabilities/generate_images.py +0 -297
- autogen/agentchat/contrib/capabilities/teachability.py +0 -406
- autogen/agentchat/contrib/capabilities/text_compressors.py +0 -72
- autogen/agentchat/contrib/capabilities/transform_messages.py +0 -92
- autogen/agentchat/contrib/capabilities/transforms.py +0 -565
- autogen/agentchat/contrib/capabilities/transforms_util.py +0 -120
- autogen/agentchat/contrib/capabilities/vision_capability.py +0 -217
- autogen/agentchat/contrib/captainagent/tools/__init__.py +0 -0
- autogen/agentchat/contrib/captainagent/tools/data_analysis/calculate_correlation.py +0 -41
- autogen/agentchat/contrib/captainagent/tools/data_analysis/calculate_skewness_and_kurtosis.py +0 -29
- autogen/agentchat/contrib/captainagent/tools/data_analysis/detect_outlier_iqr.py +0 -29
- autogen/agentchat/contrib/captainagent/tools/data_analysis/detect_outlier_zscore.py +0 -29
- autogen/agentchat/contrib/captainagent/tools/data_analysis/explore_csv.py +0 -22
- autogen/agentchat/contrib/captainagent/tools/data_analysis/shapiro_wilk_test.py +0 -31
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/arxiv_download.py +0 -26
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/arxiv_search.py +0 -55
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/extract_pdf_image.py +0 -54
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/extract_pdf_text.py +0 -39
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/get_wikipedia_text.py +0 -22
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/get_youtube_caption.py +0 -35
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/image_qa.py +0 -61
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/optical_character_recognition.py +0 -62
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/perform_web_search.py +0 -48
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/scrape_wikipedia_tables.py +0 -34
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/transcribe_audio_file.py +0 -22
- autogen/agentchat/contrib/captainagent/tools/information_retrieval/youtube_download.py +0 -36
- autogen/agentchat/contrib/captainagent/tools/math/calculate_circle_area_from_diameter.py +0 -22
- autogen/agentchat/contrib/captainagent/tools/math/calculate_day_of_the_week.py +0 -19
- autogen/agentchat/contrib/captainagent/tools/math/calculate_fraction_sum.py +0 -29
- autogen/agentchat/contrib/captainagent/tools/math/calculate_matrix_power.py +0 -32
- autogen/agentchat/contrib/captainagent/tools/math/calculate_reflected_point.py +0 -17
- autogen/agentchat/contrib/captainagent/tools/math/complex_numbers_product.py +0 -26
- autogen/agentchat/contrib/captainagent/tools/math/compute_currency_conversion.py +0 -24
- autogen/agentchat/contrib/captainagent/tools/math/count_distinct_permutations.py +0 -28
- autogen/agentchat/contrib/captainagent/tools/math/evaluate_expression.py +0 -29
- autogen/agentchat/contrib/captainagent/tools/math/find_continuity_point.py +0 -35
- autogen/agentchat/contrib/captainagent/tools/math/fraction_to_mixed_numbers.py +0 -40
- autogen/agentchat/contrib/captainagent/tools/math/modular_inverse_sum.py +0 -23
- autogen/agentchat/contrib/captainagent/tools/math/simplify_mixed_numbers.py +0 -37
- autogen/agentchat/contrib/captainagent/tools/math/sum_of_digit_factorials.py +0 -16
- autogen/agentchat/contrib/captainagent/tools/math/sum_of_primes_below.py +0 -16
- autogen/agentchat/contrib/captainagent/tools/requirements.txt +0 -10
- autogen/agentchat/contrib/captainagent/tools/tool_description.tsv +0 -34
- autogen/agentchat/contrib/captainagent.py +0 -490
- autogen/agentchat/contrib/gpt_assistant_agent.py +0 -545
- autogen/agentchat/contrib/graph_rag/__init__.py +0 -0
- autogen/agentchat/contrib/graph_rag/document.py +0 -30
- autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +0 -111
- autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py +0 -81
- autogen/agentchat/contrib/graph_rag/graph_query_engine.py +0 -56
- autogen/agentchat/contrib/graph_rag/graph_rag_capability.py +0 -64
- autogen/agentchat/contrib/img_utils.py +0 -390
- autogen/agentchat/contrib/llamaindex_conversable_agent.py +0 -123
- autogen/agentchat/contrib/llava_agent.py +0 -176
- autogen/agentchat/contrib/math_user_proxy_agent.py +0 -471
- autogen/agentchat/contrib/multimodal_conversable_agent.py +0 -128
- autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py +0 -325
- autogen/agentchat/contrib/retrieve_assistant_agent.py +0 -56
- autogen/agentchat/contrib/retrieve_user_proxy_agent.py +0 -705
- autogen/agentchat/contrib/society_of_mind_agent.py +0 -203
- autogen/agentchat/contrib/swarm_agent.py +0 -463
- autogen/agentchat/contrib/text_analyzer_agent.py +0 -76
- autogen/agentchat/contrib/tool_retriever.py +0 -120
- autogen/agentchat/contrib/vectordb/__init__.py +0 -0
- autogen/agentchat/contrib/vectordb/base.py +0 -243
- autogen/agentchat/contrib/vectordb/chromadb.py +0 -326
- autogen/agentchat/contrib/vectordb/mongodb.py +0 -559
- autogen/agentchat/contrib/vectordb/pgvectordb.py +0 -958
- autogen/agentchat/contrib/vectordb/qdrant.py +0 -334
- autogen/agentchat/contrib/vectordb/utils.py +0 -126
- autogen/agentchat/contrib/web_surfer.py +0 -305
- autogen/agentchat/conversable_agent.py +0 -2908
- autogen/agentchat/groupchat.py +0 -1668
- autogen/agentchat/user_proxy_agent.py +0 -109
- autogen/agentchat/utils.py +0 -207
- autogen/browser_utils.py +0 -291
- autogen/cache/__init__.py +0 -10
- autogen/cache/abstract_cache_base.py +0 -78
- autogen/cache/cache.py +0 -182
- autogen/cache/cache_factory.py +0 -85
- autogen/cache/cosmos_db_cache.py +0 -150
- autogen/cache/disk_cache.py +0 -109
- autogen/cache/in_memory_cache.py +0 -61
- autogen/cache/redis_cache.py +0 -128
- autogen/code_utils.py +0 -745
- autogen/coding/__init__.py +0 -22
- autogen/coding/base.py +0 -113
- autogen/coding/docker_commandline_code_executor.py +0 -262
- autogen/coding/factory.py +0 -45
- autogen/coding/func_with_reqs.py +0 -203
- autogen/coding/jupyter/__init__.py +0 -22
- autogen/coding/jupyter/base.py +0 -32
- autogen/coding/jupyter/docker_jupyter_server.py +0 -164
- autogen/coding/jupyter/embedded_ipython_code_executor.py +0 -182
- autogen/coding/jupyter/jupyter_client.py +0 -224
- autogen/coding/jupyter/jupyter_code_executor.py +0 -161
- autogen/coding/jupyter/local_jupyter_server.py +0 -168
- autogen/coding/local_commandline_code_executor.py +0 -410
- autogen/coding/markdown_code_extractor.py +0 -44
- autogen/coding/utils.py +0 -57
- autogen/exception_utils.py +0 -46
- autogen/extensions/__init__.py +0 -0
- autogen/formatting_utils.py +0 -76
- autogen/function_utils.py +0 -362
- autogen/graph_utils.py +0 -148
- autogen/io/__init__.py +0 -15
- autogen/io/base.py +0 -105
- autogen/io/console.py +0 -43
- autogen/io/websockets.py +0 -213
- autogen/logger/__init__.py +0 -11
- autogen/logger/base_logger.py +0 -140
- autogen/logger/file_logger.py +0 -287
- autogen/logger/logger_factory.py +0 -29
- autogen/logger/logger_utils.py +0 -42
- autogen/logger/sqlite_logger.py +0 -459
- autogen/math_utils.py +0 -356
- autogen/oai/__init__.py +0 -33
- autogen/oai/anthropic.py +0 -428
- autogen/oai/bedrock.py +0 -606
- autogen/oai/cerebras.py +0 -270
- autogen/oai/client.py +0 -1148
- autogen/oai/client_utils.py +0 -167
- autogen/oai/cohere.py +0 -453
- autogen/oai/completion.py +0 -1216
- autogen/oai/gemini.py +0 -469
- autogen/oai/groq.py +0 -281
- autogen/oai/mistral.py +0 -279
- autogen/oai/ollama.py +0 -582
- autogen/oai/openai_utils.py +0 -811
- autogen/oai/together.py +0 -343
- autogen/retrieve_utils.py +0 -487
- autogen/runtime_logging.py +0 -163
- autogen/token_count_utils.py +0 -259
- autogen/types.py +0 -20
- autogen/version.py +0 -7
- {ag2-0.4.1.dist-info → ag2-0.4.2b1.dist-info}/LICENSE +0 -0
- {ag2-0.4.1.dist-info → ag2-0.4.2b1.dist-info}/NOTICE.md +0 -0
- {ag2-0.4.1.dist-info → ag2-0.4.2b1.dist-info}/WHEEL +0 -0
autogen/math_utils.py
DELETED
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2023 - 2024, Owners of https://github.com/ag2ai
|
|
2
|
-
#
|
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
#
|
|
5
|
-
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
|
-
# SPDX-License-Identifier: MIT
|
|
7
|
-
from typing import Optional
|
|
8
|
-
|
|
9
|
-
from autogen import DEFAULT_MODEL, oai
|
|
10
|
-
|
|
11
|
-
_MATH_PROMPT = "{problem} Solve the problem carefully. Simplify your answer as much as possible. Put the final answer in \\boxed{{}}."
|
|
12
|
-
_MATH_CONFIG = {
|
|
13
|
-
"model": DEFAULT_MODEL,
|
|
14
|
-
"prompt": _MATH_PROMPT,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def solve_problem(problem: str, **config) -> str:
|
|
19
|
-
"""(openai<1) Solve the math problem.
|
|
20
|
-
|
|
21
|
-
Args:
|
|
22
|
-
problem (str): The problem statement.
|
|
23
|
-
config (Optional, dict): The configuration for the API call.
|
|
24
|
-
|
|
25
|
-
Returns:
|
|
26
|
-
str: The solution to the problem.
|
|
27
|
-
"""
|
|
28
|
-
params = {**_MATH_CONFIG, **config}
|
|
29
|
-
response = oai.Completion.create({"problem": problem}, **params)
|
|
30
|
-
results = eval_math_responses(oai.Completion.extract_text(response))
|
|
31
|
-
return results.get("voted_answer"), response["cost"]
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def remove_boxed(string: str) -> Optional[str]:
|
|
35
|
-
"""Source: https://github.com/hendrycks/math
|
|
36
|
-
Extract the text within a \\boxed{...} environment.
|
|
37
|
-
Example:
|
|
38
|
-
|
|
39
|
-
> remove_boxed("\\boxed{\\frac{2}{3}}")
|
|
40
|
-
|
|
41
|
-
\\frac{2}{3}
|
|
42
|
-
"""
|
|
43
|
-
left = "\\boxed{"
|
|
44
|
-
try:
|
|
45
|
-
if not all((string[: len(left)] == left, string[-1] == "}")):
|
|
46
|
-
raise AssertionError
|
|
47
|
-
|
|
48
|
-
return string[len(left) : -1]
|
|
49
|
-
except Exception:
|
|
50
|
-
return None
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def last_boxed_only_string(string: str) -> Optional[str]:
|
|
54
|
-
"""Source: https://github.com/hendrycks/math
|
|
55
|
-
Extract the last \\boxed{...} or \\fbox{...} element from a string.
|
|
56
|
-
"""
|
|
57
|
-
idx = string.rfind("\\boxed")
|
|
58
|
-
if idx < 0:
|
|
59
|
-
idx = string.rfind("\\fbox")
|
|
60
|
-
if idx < 0:
|
|
61
|
-
return None
|
|
62
|
-
|
|
63
|
-
i = idx
|
|
64
|
-
right_brace_idx = None
|
|
65
|
-
num_left_braces_open = 0
|
|
66
|
-
while i < len(string):
|
|
67
|
-
if string[i] == "{":
|
|
68
|
-
num_left_braces_open += 1
|
|
69
|
-
if string[i] == "}":
|
|
70
|
-
num_left_braces_open -= 1
|
|
71
|
-
if num_left_braces_open == 0:
|
|
72
|
-
right_brace_idx = i
|
|
73
|
-
break
|
|
74
|
-
i += 1
|
|
75
|
-
|
|
76
|
-
if right_brace_idx is None:
|
|
77
|
-
retval = None
|
|
78
|
-
else:
|
|
79
|
-
retval = string[idx : right_brace_idx + 1]
|
|
80
|
-
|
|
81
|
-
return retval
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def _fix_fracs(string: str) -> str:
|
|
85
|
-
"""Source: https://github.com/hendrycks/math
|
|
86
|
-
Reformat fractions.
|
|
87
|
-
Examples:
|
|
88
|
-
>>> _fix_fracs("\\frac1b")
|
|
89
|
-
\frac{1}{b}
|
|
90
|
-
>>> _fix_fracs("\\frac12")
|
|
91
|
-
\frac{1}{2}
|
|
92
|
-
>>> _fix_fracs("\\frac1{72}")
|
|
93
|
-
\frac{1}{72}
|
|
94
|
-
"""
|
|
95
|
-
substrs = string.split("\\frac")
|
|
96
|
-
new_str = substrs[0]
|
|
97
|
-
if len(substrs) > 1:
|
|
98
|
-
substrs = substrs[1:]
|
|
99
|
-
for substr in substrs:
|
|
100
|
-
new_str += "\\frac"
|
|
101
|
-
if substr[0] == "{":
|
|
102
|
-
new_str += substr
|
|
103
|
-
else:
|
|
104
|
-
try:
|
|
105
|
-
if not len(substr) >= 2:
|
|
106
|
-
raise AssertionError
|
|
107
|
-
except Exception:
|
|
108
|
-
return string
|
|
109
|
-
a = substr[0]
|
|
110
|
-
b = substr[1]
|
|
111
|
-
if b != "{":
|
|
112
|
-
if len(substr) > 2:
|
|
113
|
-
post_substr = substr[2:]
|
|
114
|
-
new_str += "{" + a + "}{" + b + "}" + post_substr
|
|
115
|
-
else:
|
|
116
|
-
new_str += "{" + a + "}{" + b + "}"
|
|
117
|
-
else:
|
|
118
|
-
if len(substr) > 2:
|
|
119
|
-
post_substr = substr[2:]
|
|
120
|
-
new_str += "{" + a + "}" + b + post_substr
|
|
121
|
-
else:
|
|
122
|
-
new_str += "{" + a + "}" + b
|
|
123
|
-
string = new_str
|
|
124
|
-
return string
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
def _fix_a_slash_b(string: str) -> str:
|
|
128
|
-
"""Source: https://github.com/hendrycks/math
|
|
129
|
-
Reformat fractions formatted as a/b to \\frac{a}{b}.
|
|
130
|
-
Example:
|
|
131
|
-
>>> _fix_a_slash_b("2/3")
|
|
132
|
-
\frac{2}{3}
|
|
133
|
-
"""
|
|
134
|
-
if len(string.split("/")) != 2:
|
|
135
|
-
return string
|
|
136
|
-
a_str = string.split("/")[0]
|
|
137
|
-
b_str = string.split("/")[1]
|
|
138
|
-
try:
|
|
139
|
-
a = int(a_str)
|
|
140
|
-
b = int(b_str)
|
|
141
|
-
if not string == "{}/{}".format(a, b):
|
|
142
|
-
raise AssertionError
|
|
143
|
-
new_string = "\\frac{" + str(a) + "}{" + str(b) + "}"
|
|
144
|
-
return new_string
|
|
145
|
-
except Exception:
|
|
146
|
-
return string
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
def _remove_right_units(string: str) -> str:
|
|
150
|
-
"""Source: https://github.com/hendrycks/math
|
|
151
|
-
Remove units (on the right).
|
|
152
|
-
"\\text{ " only ever occurs (at least in the val set) when describing units.
|
|
153
|
-
"""
|
|
154
|
-
if "\\text{ " in string:
|
|
155
|
-
splits = string.split("\\text{ ")
|
|
156
|
-
if not len(splits) == 2:
|
|
157
|
-
raise AssertionError
|
|
158
|
-
return splits[0]
|
|
159
|
-
else:
|
|
160
|
-
return string
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
def _fix_sqrt(string: str) -> str:
|
|
164
|
-
"""Source: https://github.com/hendrycks/math
|
|
165
|
-
Reformat square roots.
|
|
166
|
-
Example:
|
|
167
|
-
>>> _fix_sqrt("\\sqrt3")
|
|
168
|
-
\\sqrt{3}
|
|
169
|
-
"""
|
|
170
|
-
if "\\sqrt" not in string:
|
|
171
|
-
return string
|
|
172
|
-
splits = string.split("\\sqrt")
|
|
173
|
-
new_string = splits[0]
|
|
174
|
-
for split in splits[1:]:
|
|
175
|
-
if split[0] != "{":
|
|
176
|
-
a = split[0]
|
|
177
|
-
new_substr = "\\sqrt{" + a + "}" + split[1:]
|
|
178
|
-
else:
|
|
179
|
-
new_substr = "\\sqrt" + split
|
|
180
|
-
new_string += new_substr
|
|
181
|
-
return new_string
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
def _strip_string(string: str) -> str:
|
|
185
|
-
"""Source: https://github.com/hendrycks/math
|
|
186
|
-
Apply the reformatting helper functions above.
|
|
187
|
-
"""
|
|
188
|
-
# linebreaks
|
|
189
|
-
string = string.replace("\n", "")
|
|
190
|
-
# print(string)
|
|
191
|
-
|
|
192
|
-
# remove inverse spaces
|
|
193
|
-
string = string.replace("\\!", "")
|
|
194
|
-
# print(string)
|
|
195
|
-
|
|
196
|
-
# replace \\ with \
|
|
197
|
-
string = string.replace("\\\\", "\\")
|
|
198
|
-
# print(string)
|
|
199
|
-
|
|
200
|
-
# replace tfrac and dfrac with frac
|
|
201
|
-
string = string.replace("tfrac", "frac")
|
|
202
|
-
string = string.replace("dfrac", "frac")
|
|
203
|
-
# print(string)
|
|
204
|
-
|
|
205
|
-
# remove \left and \right
|
|
206
|
-
string = string.replace("\\left", "")
|
|
207
|
-
string = string.replace("\\right", "")
|
|
208
|
-
# print(string)
|
|
209
|
-
|
|
210
|
-
# Remove circ (degrees)
|
|
211
|
-
string = string.replace("^{\\circ}", "")
|
|
212
|
-
string = string.replace("^\\circ", "")
|
|
213
|
-
|
|
214
|
-
# remove dollar signs
|
|
215
|
-
string = string.replace("\\$", "")
|
|
216
|
-
|
|
217
|
-
# remove units (on the right)
|
|
218
|
-
string = _remove_right_units(string)
|
|
219
|
-
|
|
220
|
-
# remove percentage
|
|
221
|
-
string = string.replace("\\%", "")
|
|
222
|
-
string = string.replace("%", "")
|
|
223
|
-
|
|
224
|
-
# " 0." equivalent to " ." and "{0." equivalent to "{." Alternatively, add "0" if "." is the start of the string
|
|
225
|
-
string = string.replace(" .", " 0.")
|
|
226
|
-
string = string.replace("{.", "{0.")
|
|
227
|
-
# if empty, return empty string
|
|
228
|
-
if len(string) == 0:
|
|
229
|
-
return string
|
|
230
|
-
if string[0] == ".":
|
|
231
|
-
string = "0" + string
|
|
232
|
-
|
|
233
|
-
# to consider: get rid of e.g. "k = " or "q = " at beginning
|
|
234
|
-
if len(string.split("=")) == 2:
|
|
235
|
-
if len(string.split("=")[0]) <= 2:
|
|
236
|
-
string = string.split("=")[1]
|
|
237
|
-
|
|
238
|
-
# fix sqrt3 --> sqrt{3}
|
|
239
|
-
string = _fix_sqrt(string)
|
|
240
|
-
|
|
241
|
-
# remove spaces
|
|
242
|
-
string = string.replace(" ", "")
|
|
243
|
-
|
|
244
|
-
# \frac1b or \frac12 --> \frac{1}{b} and \frac{1}{2}, etc.
|
|
245
|
-
# Even works with \frac1{72} (but not \frac{72}1).
|
|
246
|
-
# Also does a/b --> \\frac{a}{b}
|
|
247
|
-
string = _fix_fracs(string)
|
|
248
|
-
|
|
249
|
-
# manually change 0.5 --> \frac{1}{2}
|
|
250
|
-
if string == "0.5":
|
|
251
|
-
string = "\\frac{1}{2}"
|
|
252
|
-
|
|
253
|
-
# NOTE: X/Y changed to \frac{X}{Y} in dataset, but in simple cases fix in case the model output is X/Y
|
|
254
|
-
string = _fix_a_slash_b(string)
|
|
255
|
-
|
|
256
|
-
return string
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
def get_answer(solution: Optional[str]) -> Optional[str]:
|
|
260
|
-
if solution is None:
|
|
261
|
-
return None
|
|
262
|
-
last_boxed = last_boxed_only_string(solution)
|
|
263
|
-
if last_boxed is None:
|
|
264
|
-
return None
|
|
265
|
-
answer = remove_boxed(last_boxed)
|
|
266
|
-
if answer is None:
|
|
267
|
-
return None
|
|
268
|
-
return answer
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
def is_equiv(str1: Optional[str], str2: Optional[str]) -> float:
|
|
272
|
-
"""Returns (as a float) whether two strings containing math are equivalent up to differences of formatting in
|
|
273
|
-
- units
|
|
274
|
-
- fractions
|
|
275
|
-
- square roots
|
|
276
|
-
- superfluous LaTeX.
|
|
277
|
-
Source: https://github.com/hendrycks/math
|
|
278
|
-
"""
|
|
279
|
-
if str1 is None and str2 is None:
|
|
280
|
-
print("WARNING: Both None")
|
|
281
|
-
return 1.0
|
|
282
|
-
if str1 is None or str2 is None:
|
|
283
|
-
return 0.0
|
|
284
|
-
|
|
285
|
-
try:
|
|
286
|
-
ss1 = _strip_string(str1)
|
|
287
|
-
ss2 = _strip_string(str2)
|
|
288
|
-
return float(ss1 == ss2)
|
|
289
|
-
except Exception:
|
|
290
|
-
return float(str1 == str2)
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
def is_equiv_chain_of_thought(str1: str, str2: str) -> float:
|
|
294
|
-
"""Strips the solution first before calling `is_equiv`."""
|
|
295
|
-
ans1 = get_answer(str1)
|
|
296
|
-
ans2 = get_answer(str2)
|
|
297
|
-
|
|
298
|
-
return is_equiv(ans1, ans2)
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
def voting_counts(responses):
|
|
302
|
-
answers = {}
|
|
303
|
-
for i in range(len(responses)):
|
|
304
|
-
equiv = i
|
|
305
|
-
if get_answer(responses[i]) is None:
|
|
306
|
-
# ignore None answers
|
|
307
|
-
continue
|
|
308
|
-
for j in answers:
|
|
309
|
-
if is_equiv_chain_of_thought(responses[i], responses[j]):
|
|
310
|
-
equiv = j
|
|
311
|
-
break
|
|
312
|
-
if equiv in answers:
|
|
313
|
-
answers[equiv] += 1
|
|
314
|
-
else:
|
|
315
|
-
answers[equiv] = 1
|
|
316
|
-
return answers
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
def eval_math_responses(responses, solution=None, **args):
|
|
320
|
-
"""Select a response for a math problem using voting, and check if the response is correct if the solution is provided.
|
|
321
|
-
|
|
322
|
-
Args:
|
|
323
|
-
responses (list): The list of responses.
|
|
324
|
-
solution (str): The canonical solution.
|
|
325
|
-
|
|
326
|
-
Returns:
|
|
327
|
-
dict: The success metrics.
|
|
328
|
-
"""
|
|
329
|
-
n = len(responses)
|
|
330
|
-
if not n:
|
|
331
|
-
return {
|
|
332
|
-
"expected_success": 0,
|
|
333
|
-
"success": False,
|
|
334
|
-
"success_vote": 0,
|
|
335
|
-
"voted_answer": None,
|
|
336
|
-
"votes": 0,
|
|
337
|
-
}
|
|
338
|
-
success_list = []
|
|
339
|
-
if solution is not None:
|
|
340
|
-
for i in range(n):
|
|
341
|
-
response = responses[i]
|
|
342
|
-
succeed = is_equiv_chain_of_thought(response, solution)
|
|
343
|
-
success_list.append(succeed)
|
|
344
|
-
# voting
|
|
345
|
-
answers = voting_counts(responses)
|
|
346
|
-
# find the answer with highest votes in answers
|
|
347
|
-
answer, votes = max(answers.items(), key=lambda x: x[1], default=(0, 0))
|
|
348
|
-
# check if the answer is correct
|
|
349
|
-
success_vote = is_equiv_chain_of_thought(responses[answer], solution)
|
|
350
|
-
return {
|
|
351
|
-
"expected_success": 1 - pow(1 - sum(success_list) / n, n),
|
|
352
|
-
"success": any(s for s in success_list),
|
|
353
|
-
"success_vote": success_vote,
|
|
354
|
-
"voted_answer": responses[answer],
|
|
355
|
-
"votes": votes,
|
|
356
|
-
}
|
autogen/oai/__init__.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2023 - 2024, Owners of https://github.com/ag2ai
|
|
2
|
-
#
|
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
#
|
|
5
|
-
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
|
|
6
|
-
# SPDX-License-Identifier: MIT
|
|
7
|
-
from autogen.cache.cache import Cache
|
|
8
|
-
from autogen.oai.client import ModelClient, OpenAIWrapper
|
|
9
|
-
from autogen.oai.completion import ChatCompletion, Completion
|
|
10
|
-
from autogen.oai.openai_utils import (
|
|
11
|
-
config_list_from_dotenv,
|
|
12
|
-
config_list_from_json,
|
|
13
|
-
config_list_from_models,
|
|
14
|
-
config_list_gpt4_gpt35,
|
|
15
|
-
config_list_openai_aoai,
|
|
16
|
-
filter_config,
|
|
17
|
-
get_config_list,
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
__all__ = [
|
|
21
|
-
"OpenAIWrapper",
|
|
22
|
-
"ModelClient",
|
|
23
|
-
"Completion",
|
|
24
|
-
"ChatCompletion",
|
|
25
|
-
"get_config_list",
|
|
26
|
-
"config_list_gpt4_gpt35",
|
|
27
|
-
"config_list_openai_aoai",
|
|
28
|
-
"config_list_from_models",
|
|
29
|
-
"config_list_from_json",
|
|
30
|
-
"config_list_from_dotenv",
|
|
31
|
-
"filter_config",
|
|
32
|
-
"Cache",
|
|
33
|
-
]
|