Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
dnnsdunca authored Apr 18, 2024
2 parents a841e03 + ded2d61 commit bdb40d7
Show file tree
Hide file tree
Showing 96 changed files with 12,444 additions and 4,194 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ jobs:
- name: Test with pytest skipping openai tests
if: matrix.python-version != '3.10' && matrix.os == 'ubuntu-latest'
run: |
pytest test --skip-openai --durations=10 --durations-min=1.0
pytest test --ignore=test/agentchat/contrib --skip-openai --durations=10 --durations-min=1.0
- name: Test with pytest skipping openai and docker tests
if: matrix.python-version != '3.10' && matrix.os != 'ubuntu-latest'
run: |
pytest test --skip-openai --skip-docker --durations=10 --durations-min=1.0
pytest test --ignore=test/agentchat/contrib --skip-openai --skip-docker --durations=10 --durations-min=1.0
- name: Coverage
if: matrix.python-version == '3.10'
run: |
Expand Down
49 changes: 46 additions & 3 deletions .github/workflows/contrib-openai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,23 @@ jobs:
pip install -e .
python -c "import autogen"
pip install coverage pytest-asyncio
- name: Install PostgreSQL
run: |
sudo apt install postgresql -y
- name: Start PostgreSQL service
run: sudo service postgresql start
- name: Install packages for test when needed
run: |
pip install docker
pip install qdrant_client[fastembed]
pip install -e .[retrievechat]
pip install -e .[retrievechat-qdrant,retrievechat-pgvector]
- name: Coverage
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }}
OAI_CONFIG_LIST: ${{ secrets.OAI_CONFIG_LIST }}
run: |
coverage run -a -m pytest test/agentchat/contrib/test_retrievechat.py::test_retrievechat test/agentchat/contrib/test_qdrant_retrievechat.py::test_retrievechat
coverage run -a -m pytest test/agentchat/contrib/test_retrievechat.py::test_retrievechat test/agentchat/contrib/test_qdrant_retrievechat.py::test_retrievechat test/agentchat/contrib/test_pgvector_retrievechat.py::test_retrievechat
coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down Expand Up @@ -334,3 +338,42 @@ jobs:
with:
file: ./coverage.xml
flags: unittests

AgentOptimizer:
strategy:
matrix:
os: [ ubuntu-latest ]
python-version: [ "3.11" ]
runs-on: ${{ matrix.os }}
environment: openai1
steps:
# checkout to pr branch
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install packages and dependencies
run: |
docker --version
python -m pip install --upgrade pip wheel
pip install -e .
python -c "import autogen"
pip install coverage pytest
- name: Coverage
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }}
OAI_CONFIG_LIST: ${{ secrets.OAI_CONFIG_LIST }}
run: |
coverage run -a -m pytest test/agentchat/contrib/test_agent_optimizer.py
coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
50 changes: 46 additions & 4 deletions .github/workflows/contrib-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ jobs:
- name: Install qdrant_client when python-version is 3.10
if: matrix.python-version == '3.10'
run: |
pip install qdrant_client[fastembed]
pip install .[retrievechat-qdrant]
- name: Install unstructured when python-version is 3.9 and on linux
if: matrix.python-version == '3.9' && matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y tesseract-ocr poppler-utils
pip install unstructured[all-docs]==0.13.0
- name: Install packages and dependencies for RetrieveChat
- name: Install and Start PostgreSQL
runs-on: ubuntu-latest
run: |
pip install -e .[retrievechat]
sudo apt install postgresql -y
sudo service postgresql start
- name: Install packages and dependencies for PGVector
run: |
pip install -e .[retrievechat-pgvector]
- name: Set AUTOGEN_USE_DOCKER based on OS
shell: bash
run: |
Expand Down Expand Up @@ -256,6 +260,44 @@ jobs:
file: ./coverage.xml
flags: unittests

GeminiTest:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
with:
lfs: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install packages and dependencies for all tests
run: |
python -m pip install --upgrade pip wheel
pip install pytest
- name: Install packages and dependencies for Gemini
run: |
pip install -e .[gemini,test]
- name: Set AUTOGEN_USE_DOCKER based on OS
shell: bash
run: |
if [[ ${{ matrix.os }} != ubuntu-latest ]]; then
echo "AUTOGEN_USE_DOCKER=False" >> $GITHUB_ENV
fi
- name: Coverage
run: |
coverage run -a -m pytest test/oai/test_gemini.py --skip-openai
coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests

ContextHandling:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/lfs-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Git LFS Check"

on: pull_request
permissions: {}
jobs:
lfs-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
lfs: true
- name: Check Git LFS files for consistency
run: |
git lfs fsck
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,21 @@ test/my_tmp/*
# Storage for the AgentEval output
test/test_files/agenteval-in-out/out/

# local cache or coding foler
local_cache/
coding/

# Files created by tests
*tmp_code_*
test/agentchat/test_agent_scripts/*

# test cache
.cache_test
.db
local_cache


notebook/result.png
samples/apps/autogen-studio/autogenstudio/models/test/

notebook/coding
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ repos:
website/static/img/ag.svg |
website/yarn.lock |
website/docs/tutorial/code-executors.ipynb |
website/docs/topics/code-execution/custom-executor.ipynb |
website/docs/topics/non-openai-models/cloud-gemini.ipynb |
notebook/.*
)$
# See https://jaredkhan.com/blog/mypy-pre-commit
Expand Down
3 changes: 2 additions & 1 deletion OAI_CONFIG_LIST_sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[
{
"model": "gpt-4",
"api_key": "<your OpenAI API key here>"
"api_key": "<your OpenAI API key here>",
"tags": ["gpt-4", "tool"]
},
{
"model": "<your Azure OpenAI deployment name>",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<img src="https://github.com/microsoft/autogen/blob/main/website/static/img/flaml.svg" width=200>
<br>
</p> -->
:fire: Mar 26, 2024: Andrew Ng gave a shoutout to AutoGen in [What's next for AI agentic workflows](https://youtu.be/sal78ACtGTc?si=JduUzN_1kDnMq0vF) at Sequoia Capital's AI Ascent.
:fire: Apr 17, 2024: Andrew Ng cited AutoGen in [The Batch newsletter](https://www.deeplearning.ai/the-batch/issue-245/) and [What's next for AI agentic workflows](https://youtu.be/sal78ACtGTc?si=JduUzN_1kDnMq0vF) at Sequoia Capital's AI Ascent (Mar 26).

:fire: Mar 3, 2024: What's new in AutoGen? 📰[Blog](https://microsoft.github.io/autogen/blog/2024/03/03/AutoGen-Update); 📺[Youtube](https://www.youtube.com/watch?v=j_mtwQiaLGU).

Expand Down
22 changes: 17 additions & 5 deletions autogen/agentchat/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class ChatResult:
"""The chat history."""
summary: str = None
"""A summary obtained from the chat."""
cost: tuple = None # (dict, dict) - (total_cost, actual_cost_with_cache)
"""The cost of the chat. a tuple of (total_cost, total_actual_cost), where total_cost is a
dictionary of cost information, and total_actual_cost is a dictionary of information on
the actual incurred cost with cache."""
cost: Dict[str, dict] = None # keys: "usage_including_cached_inference", "usage_excluding_cached_inference"
"""The cost of the chat.
The value for each usage type is a dictionary containing cost information for that specific type.
- "usage_including_cached_inference": Cost information on the total usage, including the tokens in cached inference.
- "usage_excluding_cached_inference": Cost information on the usage of tokens, excluding the tokens in cache. No larger than "usage_including_cached_inference".
"""
human_input: List[str] = None
"""A list of human input solicited during the chat."""

Expand Down Expand Up @@ -169,6 +171,9 @@ def initiate_chats(chat_queue: List[Dict[str, Any]]) -> List[ChatResult]:
- `"carryover"` - It can be used to specify the carryover information to be passed
to this chat. If provided, we will combine this carryover with the "message" content when
generating the initial chat message in `generate_init_message`.
- `"finished_chat_indexes_to_exclude_from_carryover"` - It can be used by specifying a list of indexes of the finished_chats list,
from which to exclude the summaries for carryover. If 'finished_chat_indexes_to_exclude_from_carryover' is not provided or an empty list,
then summary from all the finished chats will be taken.
Returns:
(list): a list of ChatResult objects corresponding to the finished chats in the chat_queue.
"""
Expand All @@ -180,9 +185,16 @@ def initiate_chats(chat_queue: List[Dict[str, Any]]) -> List[ChatResult]:
while current_chat_queue:
chat_info = current_chat_queue.pop(0)
_chat_carryover = chat_info.get("carryover", [])
finished_chat_indexes_to_exclude_from_carryover = chat_info.get(
"finished_chat_indexes_to_exclude_from_carryover", []
)

if isinstance(_chat_carryover, str):
_chat_carryover = [_chat_carryover]
chat_info["carryover"] = _chat_carryover + [r.summary for r in finished_chats]
chat_info["carryover"] = _chat_carryover + [
r.summary for i, r in enumerate(finished_chats) if i not in finished_chat_indexes_to_exclude_from_carryover
]

__post_carryover_processing(chat_info)
sender = chat_info["sender"]
chat_res = sender.initiate_chat(**chat_info)
Expand Down
14 changes: 8 additions & 6 deletions autogen/agentchat/contrib/agent_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ def _create_agent(
Returns:
agent: a set-up agent.
"""
from huggingface_hub import HfApi
from huggingface_hub.utils import GatedRepoError, RepositoryNotFoundError

config_list = autogen.config_list_from_json(
self.config_file_or_env,
file_location=self.config_file_location,
Expand All @@ -218,10 +215,15 @@ def _create_agent(
f"If you load configs from json, make sure the model in agent_configs is in the {self.config_file_or_env}."
)
try:
from huggingface_hub import HfApi
from huggingface_hub.utils import GatedRepoError, RepositoryNotFoundError

hf_api = HfApi()
hf_api.model_info(model_name_or_hf_repo)
model_name = model_name_or_hf_repo.split("/")[-1]
server_id = f"{model_name}_{self.host}"
except ImportError:
server_id = self.online_server_name
except GatedRepoError as e:
raise e
except RepositoryNotFoundError:
Expand Down Expand Up @@ -495,9 +497,6 @@ def build_from_library(
agent_list: a list of agents.
cached_configs: cached configs.
"""
import chromadb
from chromadb.utils import embedding_functions

if code_execution_config is None:
code_execution_config = {
"last_n_messages": 2,
Expand Down Expand Up @@ -528,6 +527,9 @@ def build_from_library(

print("==> Looking for suitable agents in library...")
if embedding_model is not None:
import chromadb
from chromadb.utils import embedding_functions

chroma_client = chromadb.Client()
collection = chroma_client.create_collection(
name="agent_list",
Expand Down
Loading

0 comments on commit bdb40d7

Please sign in to comment.