ag2 0.4b1__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.

Files changed (118) hide show
  1. ag2-0.4.2b1.dist-info/METADATA +19 -0
  2. ag2-0.4.2b1.dist-info/RECORD +6 -0
  3. ag2-0.4.2b1.dist-info/top_level.txt +1 -0
  4. ag2-0.4b1.dist-info/METADATA +0 -496
  5. ag2-0.4b1.dist-info/RECORD +0 -115
  6. ag2-0.4b1.dist-info/top_level.txt +0 -1
  7. autogen/__init__.py +0 -17
  8. autogen/_pydantic.py +0 -116
  9. autogen/agentchat/__init__.py +0 -42
  10. autogen/agentchat/agent.py +0 -142
  11. autogen/agentchat/assistant_agent.py +0 -85
  12. autogen/agentchat/chat.py +0 -306
  13. autogen/agentchat/contrib/__init__.py +0 -0
  14. autogen/agentchat/contrib/agent_builder.py +0 -787
  15. autogen/agentchat/contrib/agent_optimizer.py +0 -450
  16. autogen/agentchat/contrib/capabilities/__init__.py +0 -0
  17. autogen/agentchat/contrib/capabilities/agent_capability.py +0 -21
  18. autogen/agentchat/contrib/capabilities/generate_images.py +0 -297
  19. autogen/agentchat/contrib/capabilities/teachability.py +0 -406
  20. autogen/agentchat/contrib/capabilities/text_compressors.py +0 -72
  21. autogen/agentchat/contrib/capabilities/transform_messages.py +0 -92
  22. autogen/agentchat/contrib/capabilities/transforms.py +0 -565
  23. autogen/agentchat/contrib/capabilities/transforms_util.py +0 -120
  24. autogen/agentchat/contrib/capabilities/vision_capability.py +0 -217
  25. autogen/agentchat/contrib/captainagent.py +0 -487
  26. autogen/agentchat/contrib/gpt_assistant_agent.py +0 -545
  27. autogen/agentchat/contrib/graph_rag/__init__.py +0 -0
  28. autogen/agentchat/contrib/graph_rag/document.py +0 -24
  29. autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +0 -76
  30. autogen/agentchat/contrib/graph_rag/graph_query_engine.py +0 -50
  31. autogen/agentchat/contrib/graph_rag/graph_rag_capability.py +0 -56
  32. autogen/agentchat/contrib/img_utils.py +0 -390
  33. autogen/agentchat/contrib/llamaindex_conversable_agent.py +0 -123
  34. autogen/agentchat/contrib/llava_agent.py +0 -176
  35. autogen/agentchat/contrib/math_user_proxy_agent.py +0 -471
  36. autogen/agentchat/contrib/multimodal_conversable_agent.py +0 -128
  37. autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py +0 -325
  38. autogen/agentchat/contrib/retrieve_assistant_agent.py +0 -56
  39. autogen/agentchat/contrib/retrieve_user_proxy_agent.py +0 -701
  40. autogen/agentchat/contrib/society_of_mind_agent.py +0 -203
  41. autogen/agentchat/contrib/swarm_agent.py +0 -414
  42. autogen/agentchat/contrib/text_analyzer_agent.py +0 -76
  43. autogen/agentchat/contrib/tool_retriever.py +0 -114
  44. autogen/agentchat/contrib/vectordb/__init__.py +0 -0
  45. autogen/agentchat/contrib/vectordb/base.py +0 -243
  46. autogen/agentchat/contrib/vectordb/chromadb.py +0 -326
  47. autogen/agentchat/contrib/vectordb/mongodb.py +0 -559
  48. autogen/agentchat/contrib/vectordb/pgvectordb.py +0 -958
  49. autogen/agentchat/contrib/vectordb/qdrant.py +0 -334
  50. autogen/agentchat/contrib/vectordb/utils.py +0 -126
  51. autogen/agentchat/contrib/web_surfer.py +0 -305
  52. autogen/agentchat/conversable_agent.py +0 -2908
  53. autogen/agentchat/groupchat.py +0 -1668
  54. autogen/agentchat/user_proxy_agent.py +0 -109
  55. autogen/agentchat/utils.py +0 -207
  56. autogen/browser_utils.py +0 -291
  57. autogen/cache/__init__.py +0 -10
  58. autogen/cache/abstract_cache_base.py +0 -78
  59. autogen/cache/cache.py +0 -182
  60. autogen/cache/cache_factory.py +0 -85
  61. autogen/cache/cosmos_db_cache.py +0 -150
  62. autogen/cache/disk_cache.py +0 -109
  63. autogen/cache/in_memory_cache.py +0 -61
  64. autogen/cache/redis_cache.py +0 -128
  65. autogen/code_utils.py +0 -745
  66. autogen/coding/__init__.py +0 -22
  67. autogen/coding/base.py +0 -113
  68. autogen/coding/docker_commandline_code_executor.py +0 -262
  69. autogen/coding/factory.py +0 -45
  70. autogen/coding/func_with_reqs.py +0 -203
  71. autogen/coding/jupyter/__init__.py +0 -22
  72. autogen/coding/jupyter/base.py +0 -32
  73. autogen/coding/jupyter/docker_jupyter_server.py +0 -164
  74. autogen/coding/jupyter/embedded_ipython_code_executor.py +0 -182
  75. autogen/coding/jupyter/jupyter_client.py +0 -224
  76. autogen/coding/jupyter/jupyter_code_executor.py +0 -161
  77. autogen/coding/jupyter/local_jupyter_server.py +0 -168
  78. autogen/coding/local_commandline_code_executor.py +0 -410
  79. autogen/coding/markdown_code_extractor.py +0 -44
  80. autogen/coding/utils.py +0 -57
  81. autogen/exception_utils.py +0 -46
  82. autogen/extensions/__init__.py +0 -0
  83. autogen/formatting_utils.py +0 -76
  84. autogen/function_utils.py +0 -362
  85. autogen/graph_utils.py +0 -148
  86. autogen/io/__init__.py +0 -15
  87. autogen/io/base.py +0 -105
  88. autogen/io/console.py +0 -43
  89. autogen/io/websockets.py +0 -213
  90. autogen/logger/__init__.py +0 -11
  91. autogen/logger/base_logger.py +0 -140
  92. autogen/logger/file_logger.py +0 -287
  93. autogen/logger/logger_factory.py +0 -29
  94. autogen/logger/logger_utils.py +0 -42
  95. autogen/logger/sqlite_logger.py +0 -459
  96. autogen/math_utils.py +0 -356
  97. autogen/oai/__init__.py +0 -33
  98. autogen/oai/anthropic.py +0 -428
  99. autogen/oai/bedrock.py +0 -600
  100. autogen/oai/cerebras.py +0 -264
  101. autogen/oai/client.py +0 -1148
  102. autogen/oai/client_utils.py +0 -167
  103. autogen/oai/cohere.py +0 -453
  104. autogen/oai/completion.py +0 -1216
  105. autogen/oai/gemini.py +0 -469
  106. autogen/oai/groq.py +0 -281
  107. autogen/oai/mistral.py +0 -279
  108. autogen/oai/ollama.py +0 -576
  109. autogen/oai/openai_utils.py +0 -810
  110. autogen/oai/together.py +0 -343
  111. autogen/retrieve_utils.py +0 -487
  112. autogen/runtime_logging.py +0 -163
  113. autogen/token_count_utils.py +0 -257
  114. autogen/types.py +0 -20
  115. autogen/version.py +0 -7
  116. {ag2-0.4b1.dist-info → ag2-0.4.2b1.dist-info}/LICENSE +0 -0
  117. {ag2-0.4b1.dist-info → ag2-0.4.2b1.dist-info}/NOTICE.md +0 -0
  118. {ag2-0.4b1.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
- ]