ag2 0.4.1__py3-none-any.whl → 0.5.0b2__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 (160) hide show
  1. {ag2-0.4.1.dist-info → ag2-0.5.0b2.dist-info}/METADATA +5 -146
  2. ag2-0.5.0b2.dist-info/RECORD +6 -0
  3. ag2-0.5.0b2.dist-info/top_level.txt +1 -0
  4. ag2-0.4.1.dist-info/RECORD +0 -158
  5. ag2-0.4.1.dist-info/top_level.txt +0 -1
  6. autogen/__init__.py +0 -17
  7. autogen/_pydantic.py +0 -116
  8. autogen/agentchat/__init__.py +0 -42
  9. autogen/agentchat/agent.py +0 -142
  10. autogen/agentchat/assistant_agent.py +0 -85
  11. autogen/agentchat/chat.py +0 -306
  12. autogen/agentchat/contrib/__init__.py +0 -0
  13. autogen/agentchat/contrib/agent_builder.py +0 -788
  14. autogen/agentchat/contrib/agent_eval/agent_eval.py +0 -107
  15. autogen/agentchat/contrib/agent_eval/criterion.py +0 -47
  16. autogen/agentchat/contrib/agent_eval/critic_agent.py +0 -47
  17. autogen/agentchat/contrib/agent_eval/quantifier_agent.py +0 -42
  18. autogen/agentchat/contrib/agent_eval/subcritic_agent.py +0 -48
  19. autogen/agentchat/contrib/agent_eval/task.py +0 -43
  20. autogen/agentchat/contrib/agent_optimizer.py +0 -450
  21. autogen/agentchat/contrib/capabilities/__init__.py +0 -0
  22. autogen/agentchat/contrib/capabilities/agent_capability.py +0 -21
  23. autogen/agentchat/contrib/capabilities/generate_images.py +0 -297
  24. autogen/agentchat/contrib/capabilities/teachability.py +0 -406
  25. autogen/agentchat/contrib/capabilities/text_compressors.py +0 -72
  26. autogen/agentchat/contrib/capabilities/transform_messages.py +0 -92
  27. autogen/agentchat/contrib/capabilities/transforms.py +0 -565
  28. autogen/agentchat/contrib/capabilities/transforms_util.py +0 -120
  29. autogen/agentchat/contrib/capabilities/vision_capability.py +0 -217
  30. autogen/agentchat/contrib/captainagent/tools/__init__.py +0 -0
  31. autogen/agentchat/contrib/captainagent/tools/data_analysis/calculate_correlation.py +0 -41
  32. autogen/agentchat/contrib/captainagent/tools/data_analysis/calculate_skewness_and_kurtosis.py +0 -29
  33. autogen/agentchat/contrib/captainagent/tools/data_analysis/detect_outlier_iqr.py +0 -29
  34. autogen/agentchat/contrib/captainagent/tools/data_analysis/detect_outlier_zscore.py +0 -29
  35. autogen/agentchat/contrib/captainagent/tools/data_analysis/explore_csv.py +0 -22
  36. autogen/agentchat/contrib/captainagent/tools/data_analysis/shapiro_wilk_test.py +0 -31
  37. autogen/agentchat/contrib/captainagent/tools/information_retrieval/arxiv_download.py +0 -26
  38. autogen/agentchat/contrib/captainagent/tools/information_retrieval/arxiv_search.py +0 -55
  39. autogen/agentchat/contrib/captainagent/tools/information_retrieval/extract_pdf_image.py +0 -54
  40. autogen/agentchat/contrib/captainagent/tools/information_retrieval/extract_pdf_text.py +0 -39
  41. autogen/agentchat/contrib/captainagent/tools/information_retrieval/get_wikipedia_text.py +0 -22
  42. autogen/agentchat/contrib/captainagent/tools/information_retrieval/get_youtube_caption.py +0 -35
  43. autogen/agentchat/contrib/captainagent/tools/information_retrieval/image_qa.py +0 -61
  44. autogen/agentchat/contrib/captainagent/tools/information_retrieval/optical_character_recognition.py +0 -62
  45. autogen/agentchat/contrib/captainagent/tools/information_retrieval/perform_web_search.py +0 -48
  46. autogen/agentchat/contrib/captainagent/tools/information_retrieval/scrape_wikipedia_tables.py +0 -34
  47. autogen/agentchat/contrib/captainagent/tools/information_retrieval/transcribe_audio_file.py +0 -22
  48. autogen/agentchat/contrib/captainagent/tools/information_retrieval/youtube_download.py +0 -36
  49. autogen/agentchat/contrib/captainagent/tools/math/calculate_circle_area_from_diameter.py +0 -22
  50. autogen/agentchat/contrib/captainagent/tools/math/calculate_day_of_the_week.py +0 -19
  51. autogen/agentchat/contrib/captainagent/tools/math/calculate_fraction_sum.py +0 -29
  52. autogen/agentchat/contrib/captainagent/tools/math/calculate_matrix_power.py +0 -32
  53. autogen/agentchat/contrib/captainagent/tools/math/calculate_reflected_point.py +0 -17
  54. autogen/agentchat/contrib/captainagent/tools/math/complex_numbers_product.py +0 -26
  55. autogen/agentchat/contrib/captainagent/tools/math/compute_currency_conversion.py +0 -24
  56. autogen/agentchat/contrib/captainagent/tools/math/count_distinct_permutations.py +0 -28
  57. autogen/agentchat/contrib/captainagent/tools/math/evaluate_expression.py +0 -29
  58. autogen/agentchat/contrib/captainagent/tools/math/find_continuity_point.py +0 -35
  59. autogen/agentchat/contrib/captainagent/tools/math/fraction_to_mixed_numbers.py +0 -40
  60. autogen/agentchat/contrib/captainagent/tools/math/modular_inverse_sum.py +0 -23
  61. autogen/agentchat/contrib/captainagent/tools/math/simplify_mixed_numbers.py +0 -37
  62. autogen/agentchat/contrib/captainagent/tools/math/sum_of_digit_factorials.py +0 -16
  63. autogen/agentchat/contrib/captainagent/tools/math/sum_of_primes_below.py +0 -16
  64. autogen/agentchat/contrib/captainagent/tools/requirements.txt +0 -10
  65. autogen/agentchat/contrib/captainagent/tools/tool_description.tsv +0 -34
  66. autogen/agentchat/contrib/captainagent.py +0 -490
  67. autogen/agentchat/contrib/gpt_assistant_agent.py +0 -545
  68. autogen/agentchat/contrib/graph_rag/__init__.py +0 -0
  69. autogen/agentchat/contrib/graph_rag/document.py +0 -30
  70. autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py +0 -111
  71. autogen/agentchat/contrib/graph_rag/falkor_graph_rag_capability.py +0 -81
  72. autogen/agentchat/contrib/graph_rag/graph_query_engine.py +0 -56
  73. autogen/agentchat/contrib/graph_rag/graph_rag_capability.py +0 -64
  74. autogen/agentchat/contrib/img_utils.py +0 -390
  75. autogen/agentchat/contrib/llamaindex_conversable_agent.py +0 -123
  76. autogen/agentchat/contrib/llava_agent.py +0 -176
  77. autogen/agentchat/contrib/math_user_proxy_agent.py +0 -471
  78. autogen/agentchat/contrib/multimodal_conversable_agent.py +0 -128
  79. autogen/agentchat/contrib/qdrant_retrieve_user_proxy_agent.py +0 -325
  80. autogen/agentchat/contrib/retrieve_assistant_agent.py +0 -56
  81. autogen/agentchat/contrib/retrieve_user_proxy_agent.py +0 -705
  82. autogen/agentchat/contrib/society_of_mind_agent.py +0 -203
  83. autogen/agentchat/contrib/swarm_agent.py +0 -463
  84. autogen/agentchat/contrib/text_analyzer_agent.py +0 -76
  85. autogen/agentchat/contrib/tool_retriever.py +0 -120
  86. autogen/agentchat/contrib/vectordb/__init__.py +0 -0
  87. autogen/agentchat/contrib/vectordb/base.py +0 -243
  88. autogen/agentchat/contrib/vectordb/chromadb.py +0 -326
  89. autogen/agentchat/contrib/vectordb/mongodb.py +0 -559
  90. autogen/agentchat/contrib/vectordb/pgvectordb.py +0 -958
  91. autogen/agentchat/contrib/vectordb/qdrant.py +0 -334
  92. autogen/agentchat/contrib/vectordb/utils.py +0 -126
  93. autogen/agentchat/contrib/web_surfer.py +0 -305
  94. autogen/agentchat/conversable_agent.py +0 -2908
  95. autogen/agentchat/groupchat.py +0 -1668
  96. autogen/agentchat/user_proxy_agent.py +0 -109
  97. autogen/agentchat/utils.py +0 -207
  98. autogen/browser_utils.py +0 -291
  99. autogen/cache/__init__.py +0 -10
  100. autogen/cache/abstract_cache_base.py +0 -78
  101. autogen/cache/cache.py +0 -182
  102. autogen/cache/cache_factory.py +0 -85
  103. autogen/cache/cosmos_db_cache.py +0 -150
  104. autogen/cache/disk_cache.py +0 -109
  105. autogen/cache/in_memory_cache.py +0 -61
  106. autogen/cache/redis_cache.py +0 -128
  107. autogen/code_utils.py +0 -745
  108. autogen/coding/__init__.py +0 -22
  109. autogen/coding/base.py +0 -113
  110. autogen/coding/docker_commandline_code_executor.py +0 -262
  111. autogen/coding/factory.py +0 -45
  112. autogen/coding/func_with_reqs.py +0 -203
  113. autogen/coding/jupyter/__init__.py +0 -22
  114. autogen/coding/jupyter/base.py +0 -32
  115. autogen/coding/jupyter/docker_jupyter_server.py +0 -164
  116. autogen/coding/jupyter/embedded_ipython_code_executor.py +0 -182
  117. autogen/coding/jupyter/jupyter_client.py +0 -224
  118. autogen/coding/jupyter/jupyter_code_executor.py +0 -161
  119. autogen/coding/jupyter/local_jupyter_server.py +0 -168
  120. autogen/coding/local_commandline_code_executor.py +0 -410
  121. autogen/coding/markdown_code_extractor.py +0 -44
  122. autogen/coding/utils.py +0 -57
  123. autogen/exception_utils.py +0 -46
  124. autogen/extensions/__init__.py +0 -0
  125. autogen/formatting_utils.py +0 -76
  126. autogen/function_utils.py +0 -362
  127. autogen/graph_utils.py +0 -148
  128. autogen/io/__init__.py +0 -15
  129. autogen/io/base.py +0 -105
  130. autogen/io/console.py +0 -43
  131. autogen/io/websockets.py +0 -213
  132. autogen/logger/__init__.py +0 -11
  133. autogen/logger/base_logger.py +0 -140
  134. autogen/logger/file_logger.py +0 -287
  135. autogen/logger/logger_factory.py +0 -29
  136. autogen/logger/logger_utils.py +0 -42
  137. autogen/logger/sqlite_logger.py +0 -459
  138. autogen/math_utils.py +0 -356
  139. autogen/oai/__init__.py +0 -33
  140. autogen/oai/anthropic.py +0 -428
  141. autogen/oai/bedrock.py +0 -606
  142. autogen/oai/cerebras.py +0 -270
  143. autogen/oai/client.py +0 -1148
  144. autogen/oai/client_utils.py +0 -167
  145. autogen/oai/cohere.py +0 -453
  146. autogen/oai/completion.py +0 -1216
  147. autogen/oai/gemini.py +0 -469
  148. autogen/oai/groq.py +0 -281
  149. autogen/oai/mistral.py +0 -279
  150. autogen/oai/ollama.py +0 -582
  151. autogen/oai/openai_utils.py +0 -811
  152. autogen/oai/together.py +0 -343
  153. autogen/retrieve_utils.py +0 -487
  154. autogen/runtime_logging.py +0 -163
  155. autogen/token_count_utils.py +0 -259
  156. autogen/types.py +0 -20
  157. autogen/version.py +0 -7
  158. {ag2-0.4.1.dist-info → ag2-0.5.0b2.dist-info}/LICENSE +0 -0
  159. {ag2-0.4.1.dist-info → ag2-0.5.0b2.dist-info}/NOTICE.md +0 -0
  160. {ag2-0.4.1.dist-info → ag2-0.5.0b2.dist-info}/WHEEL +0 -0
autogen/oai/cerebras.py DELETED
@@ -1,270 +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
- """Create an OpenAI-compatible client using Cerebras's API.
8
-
9
- Example:
10
- llm_config={
11
- "config_list": [{
12
- "api_type": "cerebras",
13
- "model": "llama3.1-8b",
14
- "api_key": os.environ.get("CEREBRAS_API_KEY")
15
- }]
16
- }
17
-
18
- agent = autogen.AssistantAgent("my_agent", llm_config=llm_config)
19
-
20
- Install Cerebras's python library using: pip install --upgrade cerebras_cloud_sdk
21
-
22
- Resources:
23
- - https://inference-docs.cerebras.ai/quickstart
24
- """
25
-
26
- from __future__ import annotations
27
-
28
- import copy
29
- import os
30
- import time
31
- import warnings
32
- from typing import Any, Dict, List
33
-
34
- from cerebras.cloud.sdk import Cerebras, Stream
35
- from openai.types.chat import ChatCompletion, ChatCompletionMessageToolCall
36
- from openai.types.chat.chat_completion import ChatCompletionMessage, Choice
37
- from openai.types.completion_usage import CompletionUsage
38
-
39
- from autogen.oai.client_utils import should_hide_tools, validate_parameter
40
-
41
- CEREBRAS_PRICING_1K = {
42
- # Convert pricing per million to per thousand tokens.
43
- "llama3.1-8b": (0.10 / 1000, 0.10 / 1000),
44
- "llama3.1-70b": (0.60 / 1000, 0.60 / 1000),
45
- }
46
-
47
-
48
- class CerebrasClient:
49
- """Client for Cerebras's API."""
50
-
51
- def __init__(self, api_key=None, **kwargs):
52
- """Requires api_key or environment variable to be set
53
-
54
- Args:
55
- api_key (str): The API key for using Cerebras (or environment variable CEREBRAS_API_KEY needs to be set)
56
- """
57
- # Ensure we have the api_key upon instantiation
58
- self.api_key = api_key
59
- if not self.api_key:
60
- self.api_key = os.getenv("CEREBRAS_API_KEY")
61
-
62
- assert (
63
- self.api_key
64
- ), "Please include the api_key in your config list entry for Cerebras or set the CEREBRAS_API_KEY env variable."
65
-
66
- def message_retrieval(self, response: ChatCompletion) -> List:
67
- """
68
- Retrieve and return a list of strings or a list of Choice.Message from the response.
69
-
70
- NOTE: if a list of Choice.Message is returned, it currently needs to contain the fields of OpenAI's ChatCompletion Message object,
71
- since that is expected for function or tool calling in the rest of the codebase at the moment, unless a custom agent is being used.
72
- """
73
- return [choice.message for choice in response.choices]
74
-
75
- def cost(self, response: ChatCompletion) -> float:
76
- # Note: This field isn't explicitly in `ChatCompletion`, but is injected during chat creation.
77
- return response.cost
78
-
79
- @staticmethod
80
- def get_usage(response: ChatCompletion) -> Dict:
81
- """Return usage summary of the response using RESPONSE_USAGE_KEYS."""
82
- # ... # pragma: no cover
83
- return {
84
- "prompt_tokens": response.usage.prompt_tokens,
85
- "completion_tokens": response.usage.completion_tokens,
86
- "total_tokens": response.usage.total_tokens,
87
- "cost": response.cost,
88
- "model": response.model,
89
- }
90
-
91
- def parse_params(self, params: Dict[str, Any]) -> Dict[str, Any]:
92
- """Loads the parameters for Cerebras API from the passed in parameters and returns a validated set. Checks types, ranges, and sets defaults"""
93
- cerebras_params = {}
94
-
95
- # Check that we have what we need to use Cerebras's API
96
- # We won't enforce the available models as they are likely to change
97
- cerebras_params["model"] = params.get("model", None)
98
- assert cerebras_params[
99
- "model"
100
- ], "Please specify the 'model' in your config list entry to nominate the Cerebras model to use."
101
-
102
- # Validate allowed Cerebras parameters
103
- # https://inference-docs.cerebras.ai/api-reference/chat-completions
104
- cerebras_params["max_tokens"] = validate_parameter(params, "max_tokens", int, True, None, (0, None), None)
105
- cerebras_params["seed"] = validate_parameter(params, "seed", int, True, None, None, None)
106
- cerebras_params["stream"] = validate_parameter(params, "stream", bool, True, False, None, None)
107
- cerebras_params["temperature"] = validate_parameter(
108
- params, "temperature", (int, float), True, 1, (0, 1.5), None
109
- )
110
- cerebras_params["top_p"] = validate_parameter(params, "top_p", (int, float), True, None, None, None)
111
-
112
- return cerebras_params
113
-
114
- def create(self, params: Dict) -> ChatCompletion:
115
-
116
- messages = params.get("messages", [])
117
-
118
- # Convert AutoGen messages to Cerebras messages
119
- cerebras_messages = oai_messages_to_cerebras_messages(messages)
120
-
121
- # Parse parameters to the Cerebras API's parameters
122
- cerebras_params = self.parse_params(params)
123
-
124
- # Add tools to the call if we have them and aren't hiding them
125
- if "tools" in params:
126
- hide_tools = validate_parameter(
127
- params, "hide_tools", str, False, "never", None, ["if_all_run", "if_any_run", "never"]
128
- )
129
- if not should_hide_tools(cerebras_messages, params["tools"], hide_tools):
130
- cerebras_params["tools"] = params["tools"]
131
-
132
- cerebras_params["messages"] = cerebras_messages
133
-
134
- # We use chat model by default, and set max_retries to 5 (in line with typical retries loop)
135
- client = Cerebras(api_key=self.api_key, max_retries=5)
136
-
137
- # Token counts will be returned
138
- prompt_tokens = 0
139
- completion_tokens = 0
140
- total_tokens = 0
141
-
142
- # Streaming tool call recommendations
143
- streaming_tool_calls = []
144
-
145
- ans = None
146
- response = client.chat.completions.create(**cerebras_params)
147
-
148
- if cerebras_params["stream"]:
149
- # Read in the chunks as they stream, taking in tool_calls which may be across
150
- # multiple chunks if more than one suggested
151
- ans = ""
152
- for chunk in response:
153
- # Grab first choice, which _should_ always be generated.
154
- ans = ans + (getattr(chunk.choices[0].delta, "content", None) or "")
155
-
156
- if "tool_calls" in chunk.choices[0].delta:
157
- # We have a tool call recommendation
158
- for tool_call in chunk.choices[0].delta["tool_calls"]:
159
- streaming_tool_calls.append(
160
- ChatCompletionMessageToolCall(
161
- id=tool_call["id"],
162
- function={
163
- "name": tool_call["function"]["name"],
164
- "arguments": tool_call["function"]["arguments"],
165
- },
166
- type="function",
167
- )
168
- )
169
-
170
- if chunk.choices[0].finish_reason:
171
- prompt_tokens = chunk.usage.prompt_tokens
172
- completion_tokens = chunk.usage.completion_tokens
173
- total_tokens = chunk.usage.total_tokens
174
- else:
175
- # Non-streaming finished
176
- ans: str = response.choices[0].message.content
177
-
178
- prompt_tokens = response.usage.prompt_tokens
179
- completion_tokens = response.usage.completion_tokens
180
- total_tokens = response.usage.total_tokens
181
-
182
- if response is not None:
183
- if isinstance(response, Stream):
184
- # Streaming response
185
- if chunk.choices[0].finish_reason == "tool_calls":
186
- cerebras_finish = "tool_calls"
187
- tool_calls = streaming_tool_calls
188
- else:
189
- cerebras_finish = "stop"
190
- tool_calls = None
191
-
192
- response_content = ans
193
- response_id = chunk.id
194
- else:
195
- # Non-streaming response
196
- # If we have tool calls as the response, populate completed tool calls for our return OAI response
197
- if response.choices[0].finish_reason == "tool_calls":
198
- cerebras_finish = "tool_calls"
199
- tool_calls = []
200
- for tool_call in response.choices[0].message.tool_calls:
201
- tool_calls.append(
202
- ChatCompletionMessageToolCall(
203
- id=tool_call.id,
204
- function={"name": tool_call.function.name, "arguments": tool_call.function.arguments},
205
- type="function",
206
- )
207
- )
208
- else:
209
- cerebras_finish = "stop"
210
- tool_calls = None
211
-
212
- response_content = response.choices[0].message.content
213
- response_id = response.id
214
-
215
- # 3. convert output
216
- message = ChatCompletionMessage(
217
- role="assistant",
218
- content=response_content,
219
- function_call=None,
220
- tool_calls=tool_calls,
221
- )
222
- choices = [Choice(finish_reason=cerebras_finish, index=0, message=message)]
223
-
224
- response_oai = ChatCompletion(
225
- id=response_id,
226
- model=cerebras_params["model"],
227
- created=int(time.time()),
228
- object="chat.completion",
229
- choices=choices,
230
- usage=CompletionUsage(
231
- prompt_tokens=prompt_tokens,
232
- completion_tokens=completion_tokens,
233
- total_tokens=total_tokens,
234
- ),
235
- # Note: This seems to be a field that isn't in the schema of `ChatCompletion`, so Pydantic
236
- # just adds it dynamically.
237
- cost=calculate_cerebras_cost(prompt_tokens, completion_tokens, cerebras_params["model"]),
238
- )
239
-
240
- return response_oai
241
-
242
-
243
- def oai_messages_to_cerebras_messages(messages: list[Dict[str, Any]]) -> list[dict[str, Any]]:
244
- """Convert messages from OAI format to Cerebras's format.
245
- We correct for any specific role orders and types.
246
- """
247
-
248
- cerebras_messages = copy.deepcopy(messages)
249
-
250
- # Remove the name field
251
- for message in cerebras_messages:
252
- if "name" in message:
253
- message.pop("name", None)
254
-
255
- return cerebras_messages
256
-
257
-
258
- def calculate_cerebras_cost(input_tokens: int, output_tokens: int, model: str) -> float:
259
- """Calculate the cost of the completion using the Cerebras pricing."""
260
- total = 0.0
261
-
262
- if model in CEREBRAS_PRICING_1K:
263
- input_cost_per_k, output_cost_per_k = CEREBRAS_PRICING_1K[model]
264
- input_cost = (input_tokens / 1000) * input_cost_per_k
265
- output_cost = (output_tokens / 1000) * output_cost_per_k
266
- total = input_cost + output_cost
267
- else:
268
- warnings.warn(f"Cost calculation not available for model {model}", UserWarning)
269
-
270
- return total