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/oai/together.py DELETED
@@ -1,343 +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 Together.AI's API.
8
-
9
- Example:
10
- llm_config={
11
- "config_list": [{
12
- "api_type": "together",
13
- "model": "mistralai/Mixtral-8x7B-Instruct-v0.1",
14
- "api_key": os.environ.get("TOGETHER_API_KEY")
15
- }
16
- ]}
17
-
18
- agent = autogen.AssistantAgent("my_agent", llm_config=llm_config)
19
-
20
- Install Together.AI python library using: pip install --upgrade together
21
-
22
- Resources:
23
- - https://docs.together.ai/docs/inference-python
24
- """
25
-
26
- from __future__ import annotations
27
-
28
- import base64
29
- import copy
30
- import os
31
- import random
32
- import re
33
- import time
34
- import warnings
35
- from io import BytesIO
36
- from typing import Any, Dict, List, Mapping, Tuple, Union
37
-
38
- import requests
39
- from openai.types.chat import ChatCompletion, ChatCompletionMessageToolCall
40
- from openai.types.chat.chat_completion import ChatCompletionMessage, Choice
41
- from openai.types.completion_usage import CompletionUsage
42
- from PIL import Image
43
- from together import Together, error
44
-
45
- from autogen.oai.client_utils import should_hide_tools, validate_parameter
46
-
47
-
48
- class TogetherClient:
49
- """Client for Together.AI's API."""
50
-
51
- def __init__(self, **kwargs):
52
- """Requires api_key or environment variable to be set
53
-
54
- Args:
55
- api_key (str): The API key for using Together.AI (or environment variable TOGETHER_API_KEY needs to be set)
56
- """
57
- # Ensure we have the api_key upon instantiation
58
- self.api_key = kwargs.get("api_key", None)
59
- if not self.api_key:
60
- self.api_key = os.getenv("TOGETHER_API_KEY")
61
-
62
- assert (
63
- self.api_key
64
- ), "Please include the api_key in your config list entry for Together.AI or set the TOGETHER_API_KEY env variable."
65
-
66
- def message_retrieval(self, response) -> 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) -> float:
76
- return response.cost
77
-
78
- @staticmethod
79
- def get_usage(response) -> Dict:
80
- """Return usage summary of the response using RESPONSE_USAGE_KEYS."""
81
- # ... # pragma: no cover
82
- return {
83
- "prompt_tokens": response.usage.prompt_tokens,
84
- "completion_tokens": response.usage.completion_tokens,
85
- "total_tokens": response.usage.total_tokens,
86
- "cost": response.cost,
87
- "model": response.model,
88
- }
89
-
90
- def parse_params(self, params: Dict[str, Any]) -> Dict[str, Any]:
91
- """Loads the parameters for Together.AI API from the passed in parameters and returns a validated set. Checks types, ranges, and sets defaults"""
92
- together_params = {}
93
-
94
- # Check that we have what we need to use Together.AI's API
95
- together_params["model"] = params.get("model", None)
96
- assert together_params[
97
- "model"
98
- ], "Please specify the 'model' in your config list entry to nominate the Together.AI model to use."
99
-
100
- # Validate allowed Together.AI parameters
101
- # https://github.com/togethercomputer/together-python/blob/94ffb30daf0ac3e078be986af7228f85f79bde99/src/together/resources/completions.py#L44
102
- together_params["max_tokens"] = validate_parameter(params, "max_tokens", int, True, 512, (0, None), None)
103
- together_params["stream"] = validate_parameter(params, "stream", bool, False, False, None, None)
104
- together_params["temperature"] = validate_parameter(params, "temperature", (int, float), True, None, None, None)
105
- together_params["top_p"] = validate_parameter(params, "top_p", (int, float), True, None, None, None)
106
- together_params["top_k"] = validate_parameter(params, "top_k", int, True, None, None, None)
107
- together_params["repetition_penalty"] = validate_parameter(
108
- params, "repetition_penalty", float, True, None, None, None
109
- )
110
- together_params["presence_penalty"] = validate_parameter(
111
- params, "presence_penalty", (int, float), True, None, (-2, 2), None
112
- )
113
- together_params["frequency_penalty"] = validate_parameter(
114
- params, "frequency_penalty", (int, float), True, None, (-2, 2), None
115
- )
116
- together_params["min_p"] = validate_parameter(params, "min_p", (int, float), True, None, (0, 1), None)
117
- together_params["safety_model"] = validate_parameter(
118
- params, "safety_model", str, True, None, None, None
119
- ) # We won't enforce the available models as they are likely to change
120
-
121
- # Check if they want to stream and use tools, which isn't currently supported (TODO)
122
- if together_params["stream"] and "tools" in params:
123
- warnings.warn(
124
- "Streaming is not supported when using tools, streaming will be disabled.",
125
- UserWarning,
126
- )
127
-
128
- together_params["stream"] = False
129
-
130
- return together_params
131
-
132
- def create(self, params: Dict) -> ChatCompletion:
133
-
134
- messages = params.get("messages", [])
135
-
136
- # Convert AutoGen messages to Together.AI messages
137
- together_messages = oai_messages_to_together_messages(messages)
138
-
139
- # Parse parameters to Together.AI API's parameters
140
- together_params = self.parse_params(params)
141
-
142
- # Add tools to the call if we have them and aren't hiding them
143
- if "tools" in params:
144
- hide_tools = validate_parameter(
145
- params, "hide_tools", str, False, "never", None, ["if_all_run", "if_any_run", "never"]
146
- )
147
- if not should_hide_tools(together_messages, params["tools"], hide_tools):
148
- together_params["tools"] = params["tools"]
149
-
150
- together_params["messages"] = together_messages
151
-
152
- # We use chat model by default
153
- client = Together(api_key=self.api_key)
154
-
155
- # Token counts will be returned
156
- prompt_tokens = 0
157
- completion_tokens = 0
158
- total_tokens = 0
159
-
160
- response = client.chat.completions.create(**together_params)
161
- if together_params["stream"]:
162
- # Read in the chunks as they stream
163
- ans = ""
164
- for chunk in response:
165
- ans = ans + (chunk.choices[0].delta.content or "")
166
-
167
- prompt_tokens = chunk.usage.prompt_tokens
168
- completion_tokens = chunk.usage.completion_tokens
169
- total_tokens = chunk.usage.total_tokens
170
- else:
171
- ans: str = response.choices[0].message.content
172
-
173
- prompt_tokens = response.usage.prompt_tokens
174
- completion_tokens = response.usage.completion_tokens
175
- total_tokens = response.usage.total_tokens
176
-
177
- if response.choices[0].finish_reason == "tool_calls":
178
- together_finish = "tool_calls"
179
- tool_calls = []
180
- for tool_call in response.choices[0].message.tool_calls:
181
- tool_calls.append(
182
- ChatCompletionMessageToolCall(
183
- id=tool_call.id,
184
- function={"name": tool_call.function.name, "arguments": tool_call.function.arguments},
185
- type="function",
186
- )
187
- )
188
- else:
189
- together_finish = "stop"
190
- tool_calls = None
191
-
192
- # 3. convert output
193
- message = ChatCompletionMessage(
194
- role="assistant",
195
- content=response.choices[0].message.content,
196
- function_call=None,
197
- tool_calls=tool_calls,
198
- )
199
- choices = [Choice(finish_reason=together_finish, index=0, message=message)]
200
-
201
- response_oai = ChatCompletion(
202
- id=response.id,
203
- model=together_params["model"],
204
- created=int(time.time()),
205
- object="chat.completion",
206
- choices=choices,
207
- usage=CompletionUsage(
208
- prompt_tokens=prompt_tokens,
209
- completion_tokens=completion_tokens,
210
- total_tokens=total_tokens,
211
- ),
212
- cost=calculate_together_cost(prompt_tokens, completion_tokens, together_params["model"]),
213
- )
214
-
215
- return response_oai
216
-
217
-
218
- def oai_messages_to_together_messages(messages: list[Dict[str, Any]]) -> list[dict[str, Any]]:
219
- """Convert messages from OAI format to Together.AI format.
220
- We correct for any specific role orders and types.
221
- """
222
-
223
- together_messages = copy.deepcopy(messages)
224
-
225
- # If we have a message with role='tool', which occurs when a function is executed, change it to 'user'
226
- for msg in together_messages:
227
- if "role" in msg and msg["role"] == "tool":
228
- msg["role"] = "user"
229
-
230
- return together_messages
231
-
232
-
233
- # MODELS AND COSTS
234
- chat_lang_code_model_sizes = {
235
- "zero-one-ai/Yi-34B-Chat": 34,
236
- "allenai/OLMo-7B-Instruct": 7,
237
- "allenai/OLMo-7B-Twin-2T": 7,
238
- "allenai/OLMo-7B": 7,
239
- "Austism/chronos-hermes-13b": 13,
240
- "deepseek-ai/deepseek-coder-33b-instruct": 33,
241
- "deepseek-ai/deepseek-llm-67b-chat": 67,
242
- "garage-bAInd/Platypus2-70B-instruct": 70,
243
- "google/gemma-2b-it": 2,
244
- "google/gemma-7b-it": 7,
245
- "Gryphe/MythoMax-L2-13b": 13,
246
- "lmsys/vicuna-13b-v1.5": 13,
247
- "lmsys/vicuna-7b-v1.5": 7,
248
- "codellama/CodeLlama-13b-Instruct-hf": 13,
249
- "codellama/CodeLlama-34b-Instruct-hf": 34,
250
- "codellama/CodeLlama-70b-Instruct-hf": 70,
251
- "codellama/CodeLlama-7b-Instruct-hf": 7,
252
- "meta-llama/Llama-2-70b-chat-hf": 70,
253
- "meta-llama/Llama-2-13b-chat-hf": 13,
254
- "meta-llama/Llama-2-7b-chat-hf": 7,
255
- "meta-llama/Llama-3-8b-chat-hf": 8,
256
- "meta-llama/Llama-3-70b-chat-hf": 70,
257
- "mistralai/Mistral-7B-Instruct-v0.1": 7,
258
- "mistralai/Mistral-7B-Instruct-v0.2": 7,
259
- "mistralai/Mistral-7B-Instruct-v0.3": 7,
260
- "NousResearch/Nous-Capybara-7B-V1p9": 7,
261
- "NousResearch/Nous-Hermes-llama-2-7b": 7,
262
- "NousResearch/Nous-Hermes-Llama2-13b": 13,
263
- "NousResearch/Nous-Hermes-2-Yi-34B": 34,
264
- "openchat/openchat-3.5-1210": 7,
265
- "Open-Orca/Mistral-7B-OpenOrca": 7,
266
- "Qwen/Qwen1.5-0.5B-Chat": 0.5,
267
- "Qwen/Qwen1.5-1.8B-Chat": 1.8,
268
- "Qwen/Qwen1.5-4B-Chat": 4,
269
- "Qwen/Qwen1.5-7B-Chat": 7,
270
- "Qwen/Qwen1.5-14B-Chat": 14,
271
- "Qwen/Qwen1.5-32B-Chat": 32,
272
- "Qwen/Qwen1.5-72B-Chat": 72,
273
- "Qwen/Qwen1.5-110B-Chat": 110,
274
- "Qwen/Qwen2-72B-Instruct": 72,
275
- "snorkelai/Snorkel-Mistral-PairRM-DPO": 7,
276
- "togethercomputer/alpaca-7b": 7,
277
- "teknium/OpenHermes-2-Mistral-7B": 7,
278
- "teknium/OpenHermes-2p5-Mistral-7B": 7,
279
- "togethercomputer/Llama-2-7B-32K-Instruct": 7,
280
- "togethercomputer/RedPajama-INCITE-Chat-3B-v1": 3,
281
- "togethercomputer/RedPajama-INCITE-7B-Chat": 7,
282
- "togethercomputer/StripedHyena-Nous-7B": 7,
283
- "Undi95/ReMM-SLERP-L2-13B": 13,
284
- "Undi95/Toppy-M-7B": 7,
285
- "WizardLM/WizardLM-13B-V1.2": 13,
286
- "upstage/SOLAR-10.7B-Instruct-v1.0": 11,
287
- }
288
-
289
- # Cost per million tokens based on up to X Billion parameters, e.g. up 4B is $0.1/million
290
- chat_lang_code_model_costs = {4: 0.1, 8: 0.2, 21: 0.3, 41: 0.8, 80: 0.9, 110: 1.8}
291
-
292
- mixture_model_sizes = {
293
- "cognitivecomputations/dolphin-2.5-mixtral-8x7b": 56,
294
- "databricks/dbrx-instruct": 132,
295
- "mistralai/Mixtral-8x7B-Instruct-v0.1": 47,
296
- "mistralai/Mixtral-8x22B-Instruct-v0.1": 141,
297
- "NousResearch/Nous-Hermes-2-Mistral-7B-DPO": 7,
298
- "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO": 47,
299
- "NousResearch/Nous-Hermes-2-Mixtral-8x7B-SFT": 47,
300
- "Snowflake/snowflake-arctic-instruct": 480,
301
- }
302
-
303
- # Cost per million tokens based on up to X Billion parameters, e.g. up 56B is $0.6/million
304
- mixture_costs = {56: 0.6, 176: 1.2, 480: 2.4}
305
-
306
-
307
- def calculate_together_cost(input_tokens: int, output_tokens: int, model_name: str) -> float:
308
- """Cost calculation for inference"""
309
-
310
- if model_name in chat_lang_code_model_sizes or model_name in mixture_model_sizes:
311
- cost_per_mil = 0
312
-
313
- # Chat, Language, Code models
314
- if model_name in chat_lang_code_model_sizes:
315
- size_in_b = chat_lang_code_model_sizes[model_name]
316
-
317
- for top_size in chat_lang_code_model_costs.keys():
318
- if size_in_b <= top_size:
319
- cost_per_mil = chat_lang_code_model_costs[top_size]
320
- break
321
-
322
- else:
323
- # Mixture-of-experts
324
- size_in_b = mixture_model_sizes[model_name]
325
-
326
- for top_size in mixture_costs.keys():
327
- if size_in_b <= top_size:
328
- cost_per_mil = mixture_costs[top_size]
329
- break
330
-
331
- if cost_per_mil == 0:
332
- warnings.warn("Model size doesn't align with cost structure.", UserWarning)
333
-
334
- return cost_per_mil * ((input_tokens + output_tokens) / 1e6)
335
-
336
- else:
337
- # Model is not in our list of models, can't determine the cost
338
- warnings.warn(
339
- "The model isn't catered for costing, to apply costs you can use the 'price' key on your config_list.",
340
- UserWarning,
341
- )
342
-
343
- return 0