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

async gemini support #719

Merged
merged 4 commits into from
May 31, 2024
Merged

async gemini support #719

merged 4 commits into from
May 31, 2024

Conversation

Cruppelt
Copy link
Contributor

@Cruppelt Cruppelt commented May 31, 2024

🚀 This description was created by Ellipsis for commit b1602cb

Summary:

This PR introduces asynchronous support to the from_gemini function in the instructor/client_gemini.py, allowing it to handle both synchronous and asynchronous operations.

Key points:

  • Added async support in from_gemini function in instructor/client_gemini.py
  • Overloads added for from_gemini to handle sync and async modes
  • Conditional logic based on use_async to return appropriate instructor type
  • Uses generate_content_async for async and generate_content for sync

Generated with ❤️ by ellipsis.dev

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 b1602cb in 1 minute and 44 seconds

More details
  • Looked at 78 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. instructor/client_gemini.py:31
  • Draft comment:
    The function no longer enforces that the mode must be instructor.Mode.GEMINI_JSON as it did in the previous version. If this is intentional, ensure that all calling code is aware of this change. If not, consider adding an assertion to enforce this.
    assert mode == instructor.Mode.GEMINI_JSON, "Mode must be instructor.Mode.GEMINI_JSON"

This suggestion applies to the entire function definition.

  • Reason this comment was not posted:
    Confidence of 0% on close inspection, compared to threshold of 85%.

Workflow ID: wflow_Q3xAfLc2GXsIwv1e


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

@Cruppelt
Copy link
Contributor Author

lmk thoughts on the use_async - The other clients have different Async clients that we can check the instance of but in this case Google/Gemini has the same client.

@jxnl
Copy link
Owner

jxnl commented May 31, 2024

Honestly, this looks good. Have you tested it locally yet?

@Cruppelt
Copy link
Contributor Author

Honestly, this looks good. Have you tested it locally yet?

Yes, typehead working too.

image

@ssonal
Copy link
Contributor

ssonal commented May 31, 2024

retry.py retry_async logic needs to also be updated to handle ValidationErrors. Gemini uses a different messages format.

@Cruppelt
Copy link
Contributor Author

retry.py retry_async logic needs to also be updated to handle ValidationErrors. Gemini uses a different messages format.

Have an example that will break? Happy to add

@ssonal
Copy link
Contributor

ssonal commented May 31, 2024

retry.py retry_async logic needs to also be updated to handle ValidationErrors. Gemini uses a different messages format.

Have an example that will break? Happy to add

Just saying that

except (ValidationError, JSONDecodeError) as e:
logger.debug(f"Error response: {response}")
if mode in {Mode.GEMINI_JSON}:
kwargs["contents"].extend(reask_messages(response, mode, e))
else:
kwargs["messages"].extend(reask_messages(response, mode, e))
if mode in {Mode.ANTHROPIC_TOOLS, Mode.ANTHROPIC_JSON}:
kwargs["messages"] = merge_consecutive_messages(
kwargs["messages"]
)
raise e
and
except (ValidationError, JSONDecodeError) as e:
logger.debug(f"Error response: {response}", e)
kwargs["messages"].extend(reask_messages(response, mode, e))
if mode in {Mode.ANTHROPIC_TOOLS, Mode.ANTHROPIC_JSON}:
kwargs["messages"] = merge_consecutive_messages(
kwargs["messages"]
)
raise e
should match.

GEMINI_JSON mode requires different handling of args for retries.

@jxnl jxnl merged commit 081418d into jxnl:main May 31, 2024
8 of 12 checks passed
@Cruppelt Cruppelt deleted the freature/async-gemini branch June 3, 2024 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants