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

Adding support for Gemini-8b and 2.0 #1274

Merged
merged 3 commits into from
Dec 25, 2024
Merged

Adding support for Gemini-8b and 2.0 #1274

merged 3 commits into from
Dec 25, 2024

Conversation

ivanleomk
Copy link
Collaborator

@ivanleomk ivanleomk commented Dec 24, 2024

Important

Add support for Gemini-8b with updated tests and response handling in reask_gemini_tools.

  • Testing:
    • Add Gemini tests in .github/workflows/test.yml for Python 3.11.
    • Update models in tests/llm/test_gemini/util.py to include gemini-1.5-flash-8b.
  • Functionality:
    • Modify reask_gemini_tools in instructor/reask.py to handle new glm.FunctionCall response parts.

This description was created by Ellipsis for 93fccf2. It will automatically update as commits are pushed.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to b0dc103 in 29 seconds

More details
  • Looked at 49 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 6 drafted comments based on config settings.
1. tests/llm/test_gemini/util.py:3
  • Draft comment:
    Ensure that the model version 'gemini-1.5-flash-8b' is correctly supported in the codebase. If there are any specific configurations or dependencies for this model, they should be updated accordingly.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR adds a new model version 'gemini-1.5-flash-8b' in the test utility file. This change seems intentional and aligns with the PR title, which mentions adding support for Gemini-8b.
2. .github/workflows/test.yml:46
  • Draft comment:
    Ensure that the GEMINI_API_KEY is correctly set in the repository secrets as GOOGLE_API_KEY. If not, this will cause the tests to fail.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR adds a new test step for Gemini in the GitHub Actions workflow. This step is conditioned to run only for Python 3.11, which is consistent with the existing pattern for other tests.
3. instructor/reask.py:109
  • Draft comment:
    Ensure that response.parts[0].function_call is always valid and contains the expected attributes (name and args). Consider adding error handling if there's a possibility of these attributes being absent or malformed.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR adds a new block of code to handle Gemini function calls in the reask_gemini_tools function. This is consistent with the PR's intent to add support for Gemini-8b and 2.0.
4. tests/llm/test_gemini/util.py:3
  • Draft comment:
    Use descriptive variable names. For example, rename models to gemini_models for clarity. This applies to other similar instances if any.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The variable name 'models' is not descriptive enough. It should indicate what kind of models it is referring to.
5. instructor/reask.py:107
  • Draft comment:
    Add comments to explain the logic in reask_gemini_tools function as it is complex. This will help in understanding the code better.
  • Reason this comment was not posted:
    Comment was on unchanged code.
6. .github/workflows/test.yml:46
  • Draft comment:
    Ensure that if the Gemini tests affect library code, the documentation is updated accordingly. This applies to other similar instances if any.
  • Reason this comment was not posted:
    Confidence changes required: 70%
    The new test for Gemini in the GitHub Actions workflow should have corresponding documentation updates if it affects library code.

Workflow ID: wflow_UbvwvQ72QiD1angP


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@github-actions github-actions bot added enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files. labels Dec 24, 2024
Copy link

cloudflare-workers-and-pages bot commented Dec 24, 2024

Deploying instructor-py with  Cloudflare Pages  Cloudflare Pages

Latest commit: 93fccf2
Status: ✅  Deploy successful!
Preview URL: https://1811c34d.instructor-py.pages.dev
Branch Preview URL: https://gemini-2-0.instructor-py.pages.dev

View logs

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Incremental review on 93fccf2 in 32 seconds

More details
  • Looked at 16 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. .github/workflows/test.yml:46
  • Draft comment:
    Add a condition to run Gemini tests only for Python 3.11 to match the PR description intent.
      if: matrix.python-version == '3.11'
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment suggests adding back a condition that was deliberately removed in the PR. Without additional context about why it was removed, I should assume the author had a valid reason to want Gemini tests to run on all Python versions. The PR rules state not to assume anything about PR description intent. The comment is making assumptions about intent that we can't verify.
    Maybe running Gemini tests on all Python versions could cause issues with CI resources or test stability that the commenter is aware of?
    Even if there are concerns, they should be explicitly stated rather than assuming intent. The removal of the condition was a deliberate change in the PR.
    The comment should be deleted as it assumes PR intent and suggests reverting a deliberate change without clear justification.
2. .github/workflows/test.yml:49
  • Draft comment:
    Ensure the environment variable GOOGLE_API_KEY is correct and consistent with the secret key name. If it was intended to be GEMINI_API_KEY, update it accordingly.
  • Reason this comment was not posted:
    Confidence changes required: 80%
    The environment variable name was changed from GEMINI_API_KEY to GOOGLE_API_KEY in the Run Gemini Tests step, but the key in the secrets is still GOOGLE_API_KEY. This might be intentional, but it should be checked for consistency.

Workflow ID: wflow_jXr1fRt9tc8hW4Vw


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@ivanleomk
Copy link
Collaborator Author

import instructor
import google.generativeai as genai
from pydantic import BaseModel, field_validator
from rich import print

class UserDetail(BaseModel):
    name: str
    age: int

    @field_validator("name")
    def validate_name(cls, v: str) -> str:
        if v.islower():
            raise ValueError("Name must be ALL CAPS")
        return v


client = instructor.from_gemini(genai.GenerativeModel("models/gemini-2.0-flash-exp"))
response = client.chat.completions.create(
    response_model=UserDetail,
    messages=[
        {"role": "user", "content": "Extract `jason is 12`"},
    ],
    max_retries=3,
)
print(response)

This allows for supporting the flash-2.0 models

@ivanleomk ivanleomk requested a review from jxnl December 24, 2024 02:57
@ivanleomk ivanleomk merged commit b0c968b into main Dec 25, 2024
14 of 15 checks passed
@ivanleomk ivanleomk deleted the gemini-2.0 branch December 25, 2024 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants