Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge "Gemini" feature into the main branch #2360

Merged
merged 70 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
ce5eaf7
Start Gemini integration: works ok with Text now
BeibinLi Dec 14, 2023
1b17426
Gemini notebook lint
BeibinLi Dec 14, 2023
d308fb6
try catch "import" for Gemini
BeibinLi Dec 14, 2023
64f068f
Debug: id issue for chat completion in Gemini
BeibinLi Dec 14, 2023
778301e
Add RAG example
thinkall Dec 14, 2023
1dcb125
Update docs for RAG
thinkall Dec 14, 2023
63762bc
Fix missing pydash
thinkall Dec 14, 2023
6ca8c4b
Remove temp folder
thinkall Dec 14, 2023
0c9e718
Fix test error in runs/7206014032/job/19630042864
thinkall Dec 14, 2023
d50ea48
Fix tqdm warning
thinkall Dec 14, 2023
d081e0e
Fix notebook output
thinkall Dec 14, 2023
319a79f
Merge branch 'main' into gemini
BeibinLi Dec 14, 2023
7675c51
Gemini's vision model is supported now
BeibinLi Dec 14, 2023
1bf1b01
Merge branch 'gemini' of https://github.com/microsoft/autogen into ge…
BeibinLi Dec 14, 2023
514b681
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Dec 19, 2023
7265ef1
Install instructions for the Gemini branch
BeibinLi Dec 19, 2023
3f3db59
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Jan 1, 2024
2ceb7cc
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Jan 3, 2024
d71a53a
Catch and retry when see Interval Server Error 500
BeibinLi Jan 3, 2024
c6792a8
Merge branch 'main' into gemini
BeibinLi Jan 3, 2024
25869bf
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Jan 5, 2024
5ddcf8e
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Jan 8, 2024
20c5e8c
Allow gemini to take more flexible messages
BeibinLi Jan 8, 2024
f2760bf
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Jan 14, 2024
f25bad0
Use int time for Gemini client
BeibinLi Jan 14, 2024
dee52b0
Handle other exceptions in gemini call
BeibinLi Jan 23, 2024
6452dba
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Feb 2, 2024
8b577a9
rename to "create" function for gemini
BeibinLi Feb 2, 2024
43e8f38
GeminiClient compatible with ModelClient now
BeibinLi Feb 2, 2024
5e50def
Lint
BeibinLi Feb 2, 2024
7bc085f
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Mar 4, 2024
5ec4666
Update instructions in Gemini notebook
BeibinLi Mar 4, 2024
47cc1ac
Lint
BeibinLi Mar 5, 2024
f36623a
Remove empty blocks from Gemini notebook
BeibinLi Mar 5, 2024
9bc4d4e
Add gemini into example page
BeibinLi Mar 5, 2024
8f6c2b6
Merge pull request #1857 from BeibinLi/gemini-beibin
BeibinLi Mar 5, 2024
7ff828f
self.create instead of call
BeibinLi Mar 14, 2024
6368b40
Merge pull request #2010 from BeibinLi/gemini
BeibinLi Mar 14, 2024
a0de450
Add py and Py into python execution
BeibinLi Mar 20, 2024
4a71f87
Merge branch 'gemini' of https://github.com/microsoft/autogen into ge…
BeibinLi Mar 20, 2024
25d91ce
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Mar 21, 2024
96ec56e
Remove error code from merging
BeibinLi Mar 21, 2024
50e59f0
Remove pydash dependency for gemini
BeibinLi Mar 22, 2024
94f5298
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Apr 11, 2024
0807041
Add cloud-gemini doc
BeibinLi Apr 11, 2024
25f805b
Remove temp file
BeibinLi Apr 11, 2024
77f9f33
cache import update
BeibinLi Apr 12, 2024
93d44d8
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Apr 12, 2024
c56ca27
Add test case for summary with mm input
BeibinLi Apr 12, 2024
e6bb1e4
Lint: warnings instead of print
BeibinLi Apr 12, 2024
4ca5fdc
Add test cases for gemini
BeibinLi Apr 12, 2024
2ac6dae
Gemini test config
BeibinLi Apr 12, 2024
0bac8f6
Disable default model for gemini
BeibinLi Apr 12, 2024
0b92050
Typo fix in gemini workflow
BeibinLi Apr 12, 2024
2328825
Correct grammar in example notebook
BeibinLi Apr 12, 2024
f45b9e1
Raise if "model" is not provided in create(...)
BeibinLi Apr 12, 2024
6bd891d
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Apr 15, 2024
81f8d97
Move TODOs into a roadmap
BeibinLi Apr 15, 2024
80edbe9
Update .github/workflows/contrib-tests.yml
BeibinLi Apr 15, 2024
6ff7776
Gemini test config update
BeibinLi Apr 15, 2024
e4882e7
Update setup.py
BeibinLi Apr 15, 2024
87c89dd
Update test/oai/test_gemini.py
BeibinLi Apr 15, 2024
32b794f
Merge branch 'main' into gemini
BeibinLi Apr 15, 2024
8490ce8
Update test/oai/test_gemini.py
BeibinLi Apr 15, 2024
5906fc6
Remove python 3.8 from gemini
BeibinLi Apr 15, 2024
df80961
Update import error handling for gemini
BeibinLi Apr 16, 2024
cd5420a
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Apr 16, 2024
a21cbbc
Merge branch 'gemini' of https://github.com/microsoft/autogen into ge…
BeibinLi Apr 16, 2024
ffab04b
Merge branch 'main' of https://github.com/microsoft/autogen into gemini
BeibinLi Apr 16, 2024
4d8e50d
Count tokens and cost for gemini
BeibinLi Apr 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/contrib-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ 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/*
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ repos:
website/static/img/ag.svg |
website/yarn.lock |
website/docs/tutorial/code-executors.ipynb |
website/docs/topics/non-openai-models/cloud-gemini.ipynb |
notebook/.*
)$
# See https://jaredkhan.com/blog/mypy-pre-commit
Expand Down
10 changes: 9 additions & 1 deletion autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,15 @@ def my_summary_method(
def _last_msg_as_summary(sender, recipient, summary_args) -> str:
"""Get a chat summary from the last message of the recipient."""
try:
summary = recipient.last_message(sender)["content"].replace("TERMINATE", "")
content = recipient.last_message(sender)["content"]
if isinstance(content, str):
summary = content.replace("TERMINATE", "")
elif isinstance(content, list):
# Remove the `TERMINATE` word in the content list.
summary = [
{**x, "text": x["text"].replace("TERMINATE", "")} if isinstance(x, dict) and "text" in x else x
for x in content
]
except (IndexError, AttributeError) as e:
warnings.warn(f"Cannot extract summary using last_msg: {e}. Using an empty str as summary.", UserWarning)
summary = ""
Expand Down
11 changes: 11 additions & 0 deletions autogen/oai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
TOOL_ENABLED = True
ERROR = None

try:
from autogen.oai.gemini import GeminiClient

gemini_import_exception: Optional[ImportError] = None
except ImportError as e:
gemini_import_exception = e

logger = logging.getLogger(__name__)
if not logger.handlers:
# Add the console handler.
Expand Down Expand Up @@ -425,6 +432,10 @@ def _register_default_client(self, config: Dict[str, Any], openai_config: Dict[s
self._configure_azure_openai(config, openai_config)
client = AzureOpenAI(**openai_config)
self._clients.append(OpenAIClient(client))
elif api_type is not None and api_type.startswith("google"):
if gemini_import_exception:
raise ImportError("Please install `google-generativeai` to use Google OpenAI API.")
self._clients.append(GeminiClient(**openai_config))
BeibinLi marked this conversation as resolved.
Show resolved Hide resolved
else:
client = OpenAI(**openai_config)
self._clients.append(OpenAIClient(client))
Expand Down
Loading
Loading