Skip to content

Commit

Permalink
Merge branch 'main' into groupchat_send_introductions
Browse files Browse the repository at this point in the history
  • Loading branch information
sonichi authored Feb 15, 2024
2 parents f8abad2 + 7ceee5d commit 19a8a40
Show file tree
Hide file tree
Showing 39 changed files with 226 additions and 69 deletions.
4 changes: 2 additions & 2 deletions OAI_CONFIG_LIST_sample
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"api_key": "<your Azure OpenAI API key here>",
"base_url": "<your Azure OpenAI API base here>",
"api_type": "azure",
"api_version": "2023-07-01-preview"
"api_version": "2024-02-15-preview"
},
{
"model": "<your Azure OpenAI deployment name>",
"api_key": "<your Azure OpenAI API key here>",
"base_url": "<your Azure OpenAI API base here>",
"api_type": "azure",
"api_version": "2023-07-01-preview"
"api_version": "2024-02-15-preview"
}
]
1 change: 1 addition & 0 deletions autogen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .version import __version__
from .oai import *
from .agentchat import *
from .exception_utils import *
from .code_utils import DEFAULT_MODEL, FAST_MODEL


Expand Down
35 changes: 28 additions & 7 deletions autogen/agentchat/groupchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


from ..code_utils import content_str
from ..exception_utils import AgentNameConflict
from .agent import Agent
from .conversable_agent import ConversableAgent
from ..runtime_logging import logging_enabled, log_new_agent
Expand Down Expand Up @@ -176,9 +177,26 @@ def append(self, message: Dict, speaker: Agent):
message["content"] = content_str(message["content"])
self.messages.append(message)

def agent_by_name(self, name: str) -> Agent:
"""Returns the agent with a given name."""
return self.agents[self.agent_names.index(name)]
def agent_by_name(
self, name: str, recursive: bool = False, raise_on_name_conflict: bool = False
) -> Optional[Agent]:
"""Returns the agent with a given name. If recursive is True, it will search in nested teams."""
agents = self.nested_agents() if recursive else self.agents
filtered_agents = [agent for agent in agents if agent.name == name]

if raise_on_name_conflict and len(filtered_agents) > 1:
raise AgentNameConflict()

return filtered_agents[0] if filtered_agents else None

def nested_agents(self) -> List[Agent]:
"""Returns all agents in the group chat manager."""
agents = self.agents.copy()
for agent in agents:
if isinstance(agent, GroupChatManager):
# Recursive call for nested teams
agents.extend(agent.groupchat.nested_agents())
return agents

def next_agent(self, agent: Agent, agents: Optional[List[Agent]] = None) -> Agent:
"""Return the next agent in the list."""
Expand Down Expand Up @@ -402,10 +420,8 @@ def _finalize_speaker(self, last_speaker: Agent, final: bool, name: str, agents:
)

# Return the result
try:
return self.agent_by_name(name)
except ValueError:
return self.next_agent(last_speaker, agents)
agent = self.agent_by_name(name)
return agent if agent else self.next_agent(last_speaker, agents)

def _participant_roles(self, agents: List[Agent] = None) -> str:
# Default to all agents registered
Expand Down Expand Up @@ -492,6 +508,11 @@ def __init__(
ignore_async_in_sync_chat=True,
)

@property
def groupchat(self) -> GroupChat:
"""Returns the group chat managed by the group chat manager."""
return self._groupchat

def chat_messages_for_summary(self, agent: Agent) -> List[Dict]:
"""The list of messages in the group chat as a conversation to summarize.
The agent is ignored.
Expand Down
3 changes: 3 additions & 0 deletions autogen/exception_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class AgentNameConflict(Exception):
def __init__(self, msg="Found multiple agents with the same name.", *args, **kwargs):
super().__init__(msg, *args, **kwargs)
4 changes: 2 additions & 2 deletions autogen/oai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def __init__(self, *, config_list: Optional[List[Dict[str, Any]]] = None, **base
"api_key": os.environ.get("AZURE_OPENAI_API_KEY"),
"api_type": "azure",
"base_url": os.environ.get("AZURE_OPENAI_API_BASE"),
"api_version": "2023-03-15-preview",
"api_version": "2024-02-15-preview",
},
{
"model": "gpt-3.5-turbo",
Expand Down Expand Up @@ -534,7 +534,7 @@ def yes_or_no_filter(context, response):
```
- allow_format_str_template (bool | None): Whether to allow format string template in the config. Default to false.
- api_version (str | None): The api version. Default to None. E.g., "2023-08-01-preview".
- api_version (str | None): The api version. Default to None. E.g., "2024-02-15-preview".
Raises:
- RuntimeError: If all declared custom model clients are not registered
- APIError: If any model client create call raises an APIError
Expand Down
2 changes: 1 addition & 1 deletion autogen/oai/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def create(
"api_key": os.environ.get("AZURE_OPENAI_API_KEY"),
"api_type": "azure",
"base_url": os.environ.get("AZURE_OPENAI_API_BASE"),
"api_version": "2023-03-15-preview",
"api_version": "2024-02-15-preview",
},
{
"model": "gpt-3.5-turbo",
Expand Down
4 changes: 2 additions & 2 deletions autogen/oai/openai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Assistant = object

NON_CACHE_KEY = ["api_key", "base_url", "api_type", "api_version"]
DEFAULT_AZURE_API_VERSION = "2023-12-01-preview"
DEFAULT_AZURE_API_VERSION = "2024-02-15-preview"
OAI_PRICE1K = {
"text-ada-001": 0.0004,
"text-babbage-001": 0.0005,
Expand Down Expand Up @@ -112,7 +112,7 @@ def get_config_list(
# Optionally, define the API type and version if they are common for all keys
api_type = 'azure'
api_version = '2023-12-01-preview'
api_version = '2024-02-15-preview'
# Call the get_config_list function to get a list of configuration dictionaries
config_list = get_config_list(api_keys, base_urls, api_type, api_version)
Expand Down
4 changes: 2 additions & 2 deletions notebook/agentchat_MathChat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-06-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
" {\n",
" 'model': 'gpt-3.5-turbo',\n",
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-06-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
"]\n",
"```\n",
Expand Down
2 changes: 1 addition & 1 deletion notebook/agentchat_agentoptimizer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@
"EPOCH = 10\n",
"OAI_config = {\n",
" \"AZURE_OPENAI_API_KEY\": \"gpt-4-1106-preview\",\n",
" \"api_version\": \"2023-12-01-preview\",\n",
" \"api_version\": \"2024-02-15-preview\",\n",
" \"azure_endpoint\": \"your_azure_endpoint\",\n",
" \"model\": \"your_model\",\n",
"}\n",
Expand Down
4 changes: 2 additions & 2 deletions notebook/agentchat_chess.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-06-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
" {\n",
" 'model': 'gpt-4-32k',\n",
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-06-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
"]\n",
"```\n",
Expand Down
4 changes: 2 additions & 2 deletions notebook/agentchat_compression.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-06-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
" {\n",
" 'model': 'gpt-4-32k',\n",
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-06-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
"]\n",
"```\n",
Expand Down
2 changes: 1 addition & 1 deletion notebook/agentchat_cost_token_tracking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
" \"model\": \"gpt-35-turbo-0613\", # 0613 or newer is needed to use functions\n",
" \"base_url\": \"<your Azure OpenAI API base>\", \n",
" \"api_type\": \"azure\", \n",
" \"api_version\": \"2023-08-01-preview\", # 2023-07-01-preview or newer is needed to use functions\n",
" \"api_version\": \"2024-02-15-preview\", # 2023-07-01-preview or newer is needed to use functions\n",
" \"api_key\": \"<your Azure OpenAI API key>\"\n",
" }\n",
"]\n",
Expand Down
4 changes: 2 additions & 2 deletions notebook/agentchat_custom_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@
" \"api_key\": \"<your Azure OpenAI API key here>\",\n",
" \"base_url\": \"<your Azure OpenAI API base here>\",\n",
" \"api_type\": \"azure\",\n",
" \"api_version\": \"2023-08-01-preview\"\n",
" \"api_version\": \"2024-02-15-preview\"\n",
" },\n",
" {\n",
" \"model\": \"gpt-4-32k\",\n",
" \"api_key\": \"<your Azure OpenAI API key here>\",\n",
" \"base_url\": \"<your Azure OpenAI API base here>\",\n",
" \"api_type\": \"azure\",\n",
" \"api_version\": \"2023-08-01-preview\"\n",
" \"api_version\": \"2024-02-15-preview\"\n",
" }\n",
"]\n",
"```\n",
Expand Down
2 changes: 1 addition & 1 deletion notebook/agentchat_dalle_and_gpt4v.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
" {\n",
" 'model': 'dalle',\n",
" 'api_key': 'Your API Key here',\n",
" 'api_version': '2023-06-01-preview'\n",
" 'api_version': '2024-02-15-preview'\n",
" }\n",
"]\n",
" ```"
Expand Down
4 changes: 2 additions & 2 deletions notebook/agentchat_function_call.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-08-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
" {\n",
" 'model': 'gpt-3.5-turbo-16k',\n",
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-08-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
"]\n",
"```\n",
Expand Down
4 changes: 2 additions & 2 deletions notebook/agentchat_function_call_currency_calculator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-08-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
" {\n",
" 'model': 'gpt-3.5-turbo-16k',\n",
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-08-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
"]\n",
"```\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-06-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
" {\n",
" 'model': 'gpt-4-32k',\n",
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-06-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
"]\n",
"```\n",
Expand Down
4 changes: 2 additions & 2 deletions notebook/agentchat_groupchat_research.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-06-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
" {\n",
" 'model': 'gpt-4-32k-0314',\n",
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-06-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
"]\n",
"```\n",
Expand Down
4 changes: 2 additions & 2 deletions notebook/agentchat_groupchat_vis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-08-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
" {\n",
" 'model': 'gpt-4-32k',\n",
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-08-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
"]\n",
"```\n",
Expand Down
4 changes: 2 additions & 2 deletions notebook/agentchat_human_feedback.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-08-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
" {\n",
" 'model': 'gpt-3.5-turbo-16k',\n",
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-08-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
"]\n",
"```\n",
Expand Down
4 changes: 2 additions & 2 deletions notebook/agentchat_langchain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-08-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
" {\n",
" 'model': 'gpt-3.5-turbo-16k',\n",
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-08-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
"]\n",
"```\n",
Expand Down
2 changes: 1 addition & 1 deletion notebook/agentchat_microsoft_fabric.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@
" \"api_key\": access_token,\n",
" \"base_url\": prebuilt_AI_base_url,\n",
" \"api_type\": \"azure\",\n",
" \"api_version\": \"2023-08-01-preview\",\n",
" \"api_version\": \"2024-02-15-preview\",\n",
" },\n",
"]"
]
Expand Down
4 changes: 2 additions & 2 deletions notebook/agentchat_planning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-08-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" }, # Azure OpenAI API endpoint for gpt-4\n",
" {\n",
" 'model': 'gpt-4-32k',\n",
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-08-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" }, # Azure OpenAI API endpoint for gpt-4-32k\n",
"]\n",
"```\n",
Expand Down
4 changes: 2 additions & 2 deletions notebook/agentchat_qdrant_RetrieveChat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,14 @@
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-06-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
" {\n",
" 'model': 'gpt-3.5-turbo',\n",
" 'api_key': '<your Azure OpenAI API key here>',\n",
" 'base_url': '<your Azure OpenAI API base here>',\n",
" 'api_type': 'azure',\n",
" 'api_version': '2023-06-01-preview',\n",
" 'api_version': '2024-02-15-preview',\n",
" },\n",
"]\n",
"```\n",
Expand Down
Loading

0 comments on commit 19a8a40

Please sign in to comment.