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.

Files changed (161) 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.4.1.dist-info/METADATA +0 -500
  5. ag2-0.4.1.dist-info/RECORD +0 -158
  6. ag2-0.4.1.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 -788
  15. autogen/agentchat/contrib/agent_eval/agent_eval.py +0 -107
  16. autogen/agentchat/contrib/agent_eval/criterion.py +0 -47
  17. autogen/agentchat/contrib/agent_eval/critic_agent.py +0 -47
  18. autogen/agentchat/contrib/agent_eval/quantifier_agent.py +0 -42
  19. autogen/agentchat/contrib/agent_eval/subcritic_agent.py +0 -48
  20. autogen/agentchat/contrib/agent_eval/task.py +0 -43
  21. autogen/agentchat/contrib/agent_optimizer.py +0 -450
  22. autogen/agentchat/contrib/capabilities/__init__.py +0 -0
  23. autogen/agentchat/contrib/capabilities/agent_capability.py +0 -21
  24. autogen/agentchat/contrib/capabilities/generate_images.py +0 -297
  25. autogen/agentchat/contrib/capabilities/teachability.py +0 -406
  26. autogen/agentchat/contrib/capabilities/text_compressors.py +0 -72
  27. autogen/agentchat/contrib/capabilities/transform_messages.py +0 -92
  28. autogen/agentchat/contrib/capabilities/transforms.py +0 -565
  29. autogen/agentchat/contrib/capabilities/transforms_util.py +0 -120
  30. autogen/agentchat/contrib/capabilities/vision_capability.py +0 -217
  31. autogen/agentchat/contrib/captainagent/tools/__init__.py +0 -0
  32. autogen/agentchat/contrib/captainagent/tools/data_analysis/calculate_correlation.py +0 -41
  33. autogen/agentchat/contrib/captainagent/tools/data_analysis/calculate_skewness_and_kurtosis.py +0 -29
  34. autogen/agentchat/contrib/captainagent/tools/data_analysis/detect_outlier_iqr.py +0 -29
  35. autogen/agentchat/contrib/captainagent/tools/data_analysis/detect_outlier_zscore.py +0 -29
  36. autogen/agentchat/contrib/captainagent/tools/data_analysis/explore_csv.py +0 -22
  37. autogen/agentchat/contrib/captainagent/tools/data_analysis/shapiro_wilk_test.py +0 -31
  38. autogen/agentchat/contrib/captainagent/tools/information_retrieval/arxiv_download.py +0 -26
  39. autogen/agentchat/contrib/captainagent/tools/information_retrieval/arxiv_search.py +0 -55
  40. autogen/agentchat/contrib/captainagent/tools/information_retrieval/extract_pdf_image.py +0 -54
  41. autogen/agentchat/contrib/captainagent/tools/information_retrieval/extract_pdf_text.py +0 -39
  42. autogen/agentchat/contrib/captainagent/tools/information_retrieval/get_wikipedia_text.py +0 -22
  43. autogen/agentchat/contrib/captainagent/tools/information_retrieval/get_youtube_caption.py +0 -35
  44. autogen/agentchat/contrib/captainagent/tools/information_retrieval/image_qa.py +0 -61
  45. autogen/agentchat/contrib/captainagent/tools/information_retrieval/optical_character_recognition.py +0 -62
  46. autogen/agentchat/contrib/captainagent/tools/information_retrieval/perform_web_search.py +0 -48
  47. autogen/agentchat/contrib/captainagent/tools/information_retrieval/scrape_wikipedia_tables.py +0 -34
  48. autogen/agentchat/contrib/captainagent/tools/information_retrieval/transcribe_audio_file.py +0 -22
  49. autogen/agentchat/contrib/captainagent/tools/information_retrieval/youtube_download.py +0 -36
  50. autogen/agentchat/contrib/captainagent/tools/math/calculate_circle_area_from_diameter.py +0 -22
  51. autogen/agentchat/contrib/captainagent/tools/math/calculate_day_of_the_week.py +0 -19
  52. autogen/agentchat/contrib/captainagent/tools/math/calculate_fraction_sum.py +0 -29
  53. autogen/agentchat/contrib/captainagent/tools/math/calculate_matrix_power.py +0 -32
  54. autogen/agentchat/contrib/captainagent/tools/math/calculate_reflected_point.py +0 -17
  55. autogen/agentchat/contrib/captainagent/tools/math/complex_numbers_product.py +0 -26
  56. autogen/agentchat/contrib/captainagent/tools/math/compute_currency_conversion.py +0 -24
  57. autogen/agentchat/contrib/captainagent/tools/math/count_distinct_permutations.py +0 -28
  58. autogen/agentchat/contrib/captainagent/tools/math/evaluate_expression.py +0 -29
  59. autogen/agentchat/contrib/captainagent/tools/math/find_continuity_point.py +0 -35
  60. autogen/agentchat/contrib/captainagent/tools/math/fraction_to_mixed_numbers.py +0 -40
  61. autogen/agentchat/contrib/captainagent/tools/math/modular_inverse_sum.py +0 -23
  62. autogen/agentchat/contrib/captainagent/tools/math/simplify_mixed_numbers.py +0 -37
  63. autogen/agentchat/contrib/captainagent/tools/math/sum_of_digit_factorials.py +0 -16
  64. autogen/agentchat/contrib/captainagent/tools/math/sum_of_primes_below.py +0 -16
  65. autogen/agentchat/contrib/captainagent/tools/requirements.txt +0 -10
  66. autogen/agentchat/contrib/captainagent/tools/tool_description.tsv +0 -34
  67. autogen/agentchat/contrib/captainagent.py +0 -490
  68. autogen/agentchat/contrib/gpt_assistant_agent.py +0 -545
  69. autogen/agentchat/contrib/graph_rag/__init__.py +0 -0
  70. autogen/agentchat/contrib/graph_rag/document.py +0 -30
  71. autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +0 -111
  72. autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py +0 -81
  73. autogen/agentchat/contrib/graph_rag/graph_query_engine.py +0 -56
  74. autogen/agentchat/contrib/graph_rag/graph_rag_capability.py +0 -64
  75. autogen/agentchat/contrib/img_utils.py +0 -390
  76. autogen/agentchat/contrib/llamaindex_conversable_agent.py +0 -123
  77. autogen/agentchat/contrib/llava_agent.py +0 -176
  78. autogen/agentchat/contrib/math_user_proxy_agent.py +0 -471
  79. autogen/agentchat/contrib/multimodal_conversable_agent.py +0 -128
  80. autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py +0 -325
  81. autogen/agentchat/contrib/retrieve_assistant_agent.py +0 -56
  82. autogen/agentchat/contrib/retrieve_user_proxy_agent.py +0 -705
  83. autogen/agentchat/contrib/society_of_mind_agent.py +0 -203
  84. autogen/agentchat/contrib/swarm_agent.py +0 -463
  85. autogen/agentchat/contrib/text_analyzer_agent.py +0 -76
  86. autogen/agentchat/contrib/tool_retriever.py +0 -120
  87. autogen/agentchat/contrib/vectordb/__init__.py +0 -0
  88. autogen/agentchat/contrib/vectordb/base.py +0 -243
  89. autogen/agentchat/contrib/vectordb/chromadb.py +0 -326
  90. autogen/agentchat/contrib/vectordb/mongodb.py +0 -559
  91. autogen/agentchat/contrib/vectordb/pgvectordb.py +0 -958
  92. autogen/agentchat/contrib/vectordb/qdrant.py +0 -334
  93. autogen/agentchat/contrib/vectordb/utils.py +0 -126
  94. autogen/agentchat/contrib/web_surfer.py +0 -305
  95. autogen/agentchat/conversable_agent.py +0 -2908
  96. autogen/agentchat/groupchat.py +0 -1668
  97. autogen/agentchat/user_proxy_agent.py +0 -109
  98. autogen/agentchat/utils.py +0 -207
  99. autogen/browser_utils.py +0 -291
  100. autogen/cache/__init__.py +0 -10
  101. autogen/cache/abstract_cache_base.py +0 -78
  102. autogen/cache/cache.py +0 -182
  103. autogen/cache/cache_factory.py +0 -85
  104. autogen/cache/cosmos_db_cache.py +0 -150
  105. autogen/cache/disk_cache.py +0 -109
  106. autogen/cache/in_memory_cache.py +0 -61
  107. autogen/cache/redis_cache.py +0 -128
  108. autogen/code_utils.py +0 -745
  109. autogen/coding/__init__.py +0 -22
  110. autogen/coding/base.py +0 -113
  111. autogen/coding/docker_commandline_code_executor.py +0 -262
  112. autogen/coding/factory.py +0 -45
  113. autogen/coding/func_with_reqs.py +0 -203
  114. autogen/coding/jupyter/__init__.py +0 -22
  115. autogen/coding/jupyter/base.py +0 -32
  116. autogen/coding/jupyter/docker_jupyter_server.py +0 -164
  117. autogen/coding/jupyter/embedded_ipython_code_executor.py +0 -182
  118. autogen/coding/jupyter/jupyter_client.py +0 -224
  119. autogen/coding/jupyter/jupyter_code_executor.py +0 -161
  120. autogen/coding/jupyter/local_jupyter_server.py +0 -168
  121. autogen/coding/local_commandline_code_executor.py +0 -410
  122. autogen/coding/markdown_code_extractor.py +0 -44
  123. autogen/coding/utils.py +0 -57
  124. autogen/exception_utils.py +0 -46
  125. autogen/extensions/__init__.py +0 -0
  126. autogen/formatting_utils.py +0 -76
  127. autogen/function_utils.py +0 -362
  128. autogen/graph_utils.py +0 -148
  129. autogen/io/__init__.py +0 -15
  130. autogen/io/base.py +0 -105
  131. autogen/io/console.py +0 -43
  132. autogen/io/websockets.py +0 -213
  133. autogen/logger/__init__.py +0 -11
  134. autogen/logger/base_logger.py +0 -140
  135. autogen/logger/file_logger.py +0 -287
  136. autogen/logger/logger_factory.py +0 -29
  137. autogen/logger/logger_utils.py +0 -42
  138. autogen/logger/sqlite_logger.py +0 -459
  139. autogen/math_utils.py +0 -356
  140. autogen/oai/__init__.py +0 -33
  141. autogen/oai/anthropic.py +0 -428
  142. autogen/oai/bedrock.py +0 -606
  143. autogen/oai/cerebras.py +0 -270
  144. autogen/oai/client.py +0 -1148
  145. autogen/oai/client_utils.py +0 -167
  146. autogen/oai/cohere.py +0 -453
  147. autogen/oai/completion.py +0 -1216
  148. autogen/oai/gemini.py +0 -469
  149. autogen/oai/groq.py +0 -281
  150. autogen/oai/mistral.py +0 -279
  151. autogen/oai/ollama.py +0 -582
  152. autogen/oai/openai_utils.py +0 -811
  153. autogen/oai/together.py +0 -343
  154. autogen/retrieve_utils.py +0 -487
  155. autogen/runtime_logging.py +0 -163
  156. autogen/token_count_utils.py +0 -259
  157. autogen/types.py +0 -20
  158. autogen/version.py +0 -7
  159. {ag2-0.4.1.dist-info → ag2-0.4.2b1.dist-info}/LICENSE +0 -0
  160. {ag2-0.4.1.dist-info → ag2-0.4.2b1.dist-info}/NOTICE.md +0 -0
  161. {ag2-0.4.1.dist-info → ag2-0.4.2b1.dist-info}/WHEEL +0 -0
@@ -1,259 +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
- import json
8
- import logging
9
- import re
10
- from typing import Dict, List, Union
11
-
12
- import tiktoken
13
-
14
- try:
15
- from autogen.agentchat.contrib.img_utils import num_tokens_from_gpt_image
16
-
17
- img_util_imported = True
18
- except ImportError:
19
-
20
- def num_tokens_from_gpt_image(*args, **kwargs):
21
- return 0
22
-
23
- img_util_imported = False
24
-
25
-
26
- logger = logging.getLogger(__name__)
27
- logger.img_dependency_warned = False # member variable to track if the warning has been logged
28
-
29
-
30
- def get_max_token_limit(model: str = "gpt-3.5-turbo-0613") -> int:
31
- # Handle common azure model names/aliases
32
- model = re.sub(r"^gpt\-?35", "gpt-3.5", model)
33
- model = re.sub(r"^gpt4", "gpt-4", model)
34
-
35
- max_token_limit = {
36
- "gpt-3.5-turbo": 16385,
37
- "gpt-3.5-turbo-0125": 16385,
38
- "gpt-3.5-turbo-0301": 4096,
39
- "gpt-3.5-turbo-0613": 4096,
40
- "gpt-3.5-turbo-instruct": 4096,
41
- "gpt-3.5-turbo-16k": 16385,
42
- "gpt-3.5-turbo-16k-0613": 16385,
43
- "gpt-3.5-turbo-1106": 16385,
44
- "gpt-4": 8192,
45
- "gpt-4-turbo": 128000,
46
- "gpt-4-turbo-2024-04-09": 128000,
47
- "gpt-4-32k": 32768,
48
- "gpt-4-32k-0314": 32768, # deprecate in Sep
49
- "gpt-4-0314": 8192, # deprecate in Sep
50
- "gpt-4-0613": 8192,
51
- "gpt-4-32k-0613": 32768,
52
- "gpt-4-1106-preview": 128000,
53
- "gpt-4-0125-preview": 128000,
54
- "gpt-4-turbo-preview": 128000,
55
- "gpt-4-vision-preview": 128000,
56
- "gpt-4o": 128000,
57
- "gpt-4o-2024-05-13": 128000,
58
- "gpt-4o-2024-08-06": 128000,
59
- "gpt-4o-2024-11-20": 128000,
60
- "gpt-4o-mini": 128000,
61
- "gpt-4o-mini-2024-07-18": 128000,
62
- }
63
- return max_token_limit[model]
64
-
65
-
66
- def percentile_used(input, model="gpt-3.5-turbo-0613"):
67
- return count_token(input) / get_max_token_limit(model)
68
-
69
-
70
- def token_left(input: Union[str, List, Dict], model="gpt-3.5-turbo-0613") -> int:
71
- """Count number of tokens left for an OpenAI model.
72
-
73
- Args:
74
- input: (str, list, dict): Input to the model.
75
- model: (str): Model name.
76
-
77
- Returns:
78
- int: Number of tokens left that the model can use for completion.
79
- """
80
- return get_max_token_limit(model) - count_token(input, model=model)
81
-
82
-
83
- def count_token(input: Union[str, List, Dict], model: str = "gpt-3.5-turbo-0613") -> int:
84
- """Count number of tokens used by an OpenAI model.
85
- Args:
86
- input: (str, list, dict): Input to the model.
87
- model: (str): Model name.
88
-
89
- Returns:
90
- int: Number of tokens from the input.
91
- """
92
- if isinstance(input, str):
93
- return _num_token_from_text(input, model=model)
94
- elif isinstance(input, list) or isinstance(input, dict):
95
- return _num_token_from_messages(input, model=model)
96
- else:
97
- raise ValueError(f"input must be str, list or dict, but we got {type(input)}")
98
-
99
-
100
- def _num_token_from_text(text: str, model: str = "gpt-3.5-turbo-0613"):
101
- """Return the number of tokens used by a string."""
102
- try:
103
- encoding = tiktoken.encoding_for_model(model)
104
- except KeyError:
105
- logger.warning(f"Model {model} not found. Using cl100k_base encoding.")
106
- encoding = tiktoken.get_encoding("cl100k_base")
107
- return len(encoding.encode(text))
108
-
109
-
110
- def _num_token_from_messages(messages: Union[List, Dict], model="gpt-3.5-turbo-0613"):
111
- """Return the number of tokens used by a list of messages.
112
-
113
- retrieved from https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb/
114
- """
115
- if isinstance(messages, dict):
116
- messages = [messages]
117
-
118
- try:
119
- encoding = tiktoken.encoding_for_model(model)
120
- except KeyError:
121
- logger.warning(f"Model {model} not found. Using cl100k_base encoding.")
122
- encoding = tiktoken.get_encoding("cl100k_base")
123
- if model in {
124
- "gpt-3.5-turbo-0613",
125
- "gpt-3.5-turbo-16k-0613",
126
- "gpt-4-0314",
127
- "gpt-4-32k-0314",
128
- "gpt-4-0613",
129
- "gpt-4-32k-0613",
130
- "gpt-4-turbo-preview",
131
- "gpt-4-vision-preview",
132
- "gpt-4o",
133
- "gpt-4o-2024-05-13",
134
- "gpt-4o-2024-08-06",
135
- "gpt-4o-2024-11-20",
136
- "gpt-4o-mini",
137
- "gpt-4o-mini-2024-07-18",
138
- }:
139
- tokens_per_message = 3
140
- tokens_per_name = 1
141
- elif model == "gpt-3.5-turbo-0301":
142
- tokens_per_message = 4 # every message follows <|start|>{role/name}\n{content}<|end|>\n
143
- tokens_per_name = -1 # if there's a name, the role is omitted
144
- elif "gpt-3.5-turbo" in model:
145
- logger.info("gpt-3.5-turbo may update over time. Returning num tokens assuming gpt-3.5-turbo-0613.")
146
- return _num_token_from_messages(messages, model="gpt-3.5-turbo-0613")
147
- elif "gpt-4" in model:
148
- logger.info("gpt-4 may update over time. Returning num tokens assuming gpt-4-0613.")
149
- return _num_token_from_messages(messages, model="gpt-4-0613")
150
- elif "gemini" in model:
151
- logger.info("Gemini is not supported in tiktoken. Returning num tokens assuming gpt-4-0613.")
152
- return _num_token_from_messages(messages, model="gpt-4-0613")
153
- elif "claude" in model:
154
- logger.info("Claude is not supported in tiktoken. Returning num tokens assuming gpt-4-0613.")
155
- return _num_token_from_messages(messages, model="gpt-4-0613")
156
- elif "mistral-" in model or "mixtral-" in model:
157
- logger.info("Mistral.AI models are not supported in tiktoken. Returning num tokens assuming gpt-4-0613.")
158
- return _num_token_from_messages(messages, model="gpt-4-0613")
159
- else:
160
- raise NotImplementedError(
161
- f"""_num_token_from_messages() is not implemented for model {model}. See https://github.com/openai/openai-python/blob/main/chatml.md for information on how messages are converted to tokens."""
162
- )
163
- num_tokens = 0
164
- for message in messages:
165
- num_tokens += tokens_per_message
166
- for key, value in message.items():
167
- if value is None:
168
- continue
169
-
170
- # handle content if images are in GPT-4-vision
171
- if key == "content" and isinstance(value, list):
172
- for part in value:
173
- if not isinstance(part, dict) or "type" not in part:
174
- continue
175
- if part["type"] == "text":
176
- num_tokens += len(encoding.encode(part["text"]))
177
- if "image_url" in part:
178
- assert "url" in part["image_url"]
179
- if not img_util_imported and not logger.img_dependency_warned:
180
- logger.warning(
181
- "img_utils or PIL not imported. Skipping image token count."
182
- "Please install autogen with [lmm] option.",
183
- )
184
- logger.img_dependency_warned = True
185
- is_low_quality = "detail" in part["image_url"] and part["image_url"]["detail"] == "low"
186
- try:
187
- num_tokens += num_tokens_from_gpt_image(
188
- image_data=part["image_url"]["url"], model=model, low_quality=is_low_quality
189
- )
190
- except ValueError as e:
191
- logger.warning(f"Error in num_tokens_from_gpt_image: {e}")
192
- continue
193
-
194
- # function calls
195
- if not isinstance(value, str):
196
- try:
197
- value = json.dumps(value)
198
- except TypeError:
199
- logger.warning(
200
- f"Value {value} is not a string and cannot be converted to json. It is a type: {type(value)} Skipping."
201
- )
202
- continue
203
-
204
- num_tokens += len(encoding.encode(value))
205
- if key == "name":
206
- num_tokens += tokens_per_name
207
- num_tokens += 3 # every reply is primed with <|start|>assistant<|message|>
208
- return num_tokens
209
-
210
-
211
- def num_tokens_from_functions(functions, model="gpt-3.5-turbo-0613") -> int:
212
- """Return the number of tokens used by a list of functions.
213
-
214
- Args:
215
- functions: (list): List of function descriptions that will be passed in model.
216
- model: (str): Model name.
217
-
218
- Returns:
219
- int: Number of tokens from the function descriptions.
220
- """
221
- try:
222
- encoding = tiktoken.encoding_for_model(model)
223
- except KeyError:
224
- logger.warning(f"Model {model} not found. Using cl100k_base encoding.")
225
- encoding = tiktoken.get_encoding("cl100k_base")
226
-
227
- num_tokens = 0
228
- for function in functions:
229
- function_tokens = len(encoding.encode(function["name"]))
230
- function_tokens += len(encoding.encode(function["description"]))
231
- function_tokens -= 2
232
- if "parameters" in function:
233
- parameters = function["parameters"]
234
- if "properties" in parameters:
235
- for propertiesKey in parameters["properties"]:
236
- function_tokens += len(encoding.encode(propertiesKey))
237
- v = parameters["properties"][propertiesKey]
238
- for field in v:
239
- if field == "type":
240
- function_tokens += 2
241
- function_tokens += len(encoding.encode(v["type"]))
242
- elif field == "description":
243
- function_tokens += 2
244
- function_tokens += len(encoding.encode(v["description"]))
245
- elif field == "enum":
246
- function_tokens -= 3
247
- for o in v["enum"]:
248
- function_tokens += 3
249
- function_tokens += len(encoding.encode(o))
250
- else:
251
- logger.warning(f"Not supported field {field}")
252
- function_tokens += 11
253
- if len(parameters["properties"]) == 0:
254
- function_tokens -= 2
255
-
256
- num_tokens += function_tokens
257
-
258
- num_tokens += 12
259
- return num_tokens
autogen/types.py DELETED
@@ -1,20 +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 Dict, List, Literal, TypedDict, Union
8
-
9
- MessageContentType = Union[str, List[Union[Dict, str]], None]
10
-
11
-
12
- class UserMessageTextContentPart(TypedDict):
13
- type: Literal["text"]
14
- text: str
15
-
16
-
17
- class UserMessageImageContentPart(TypedDict):
18
- type: Literal["image_url"]
19
- # Ignoring the other "detail param for now"
20
- image_url: Dict[Literal["url"], str]
autogen/version.py DELETED
@@ -1,7 +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
- __version__ = "0.4.1"
File without changes
File without changes
File without changes