From 6fb2ffcdd20a5044ae8aac2fe09e39690e18813f Mon Sep 17 00:00:00 2001 From: Ivan Leo Date: Tue, 24 Dec 2024 10:46:21 +0800 Subject: [PATCH 1/3] feat: fixed gemini bug with response issues --- instructor/reask.py | 9 +++++++++ tests/llm/test_gemini/util.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/instructor/reask.py b/instructor/reask.py index 1684d48b4..42da71a6d 100644 --- a/instructor/reask.py +++ b/instructor/reask.py @@ -107,6 +107,15 @@ def reask_gemini_tools( from google.ai import generativelanguage as glm # type: ignore reask_msgs = [ + { + "role": "model", + "parts": [ + glm.FunctionCall( + name=response.parts[0].function_call.name, + args=response.parts[0].function_call.args, + ) + ], + }, { "role": "function", "parts": [ diff --git a/tests/llm/test_gemini/util.py b/tests/llm/test_gemini/util.py index c19ea9f7f..0c4757151 100644 --- a/tests/llm/test_gemini/util.py +++ b/tests/llm/test_gemini/util.py @@ -1,4 +1,4 @@ import instructor -models: list[str] = ["models/gemini-1.5-flash-latest"] +models: list[str] = ["models/gemini-1.5-flash-8b"] modes = [instructor.Mode.GEMINI_TOOLS, instructor.Mode.GEMINI_JSON] From b0dc1032d26ed7ace088e2980d5a928305f9e4a5 Mon Sep 17 00:00:00 2001 From: Ivan Leo Date: Tue, 24 Dec 2024 10:47:35 +0800 Subject: [PATCH 2/3] fix: added test.yml for gemini tests --- .github/workflows/test.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8dcdab16f..91f8ff3db 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,6 +43,12 @@ jobs: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }} + - name: Run Gemini Tests + if: matrix.python-version == '3.11' + run: poetry run pytest tests/llm/test_gemini + env: + GEMINI_API_KEY: ${{ secrets.GOOGLE_API_KEY }} + - name: Generate coverage report if: matrix.python-version == '3.11' run: | From 93fccf22bf4aaa082101b55919e213a088ec0f57 Mon Sep 17 00:00:00 2001 From: Ivan Leo Date: Tue, 24 Dec 2024 10:52:24 +0800 Subject: [PATCH 3/3] fix: adding gemini api key --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 91f8ff3db..f325a570f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,10 +44,9 @@ jobs: COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }} - name: Run Gemini Tests - if: matrix.python-version == '3.11' run: poetry run pytest tests/llm/test_gemini env: - GEMINI_API_KEY: ${{ secrets.GOOGLE_API_KEY }} + GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} - name: Generate coverage report if: matrix.python-version == '3.11'