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

Genai: Integrate JSON Mode for Gemini 1.5 (flash) #625

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

vishah02
Copy link

@vishah02 vishah02 commented Nov 28, 2024

PR Description

Updated ChatGoogleGenerativeAI to allow for outputs to be formatted into JSON mode. Added an optional parameter response_mime_type into ChatGoogleGenerativeAI that formats outputs into JSON mode when set to “application/json”, along with the ability to (optionally) provide schemas for the response to follow. Added support for enums in response_mime_type and response_schema, which ensures that the API’s response is from on of the values in the enum provided in response_schema

Relevant issues

#24184

Type

🆕 New Feature

Changes(optional)

All changes were made to libs\genai\langchain_google_genai\chat_models.py
Changes to validate_environment():

  • If response_mime_type and response_schema exist, ensure they are valid, else return an error

  • Valid response_mime_types include "text/plain", "application/json", "text/x.enum"

  • Response_schemas is only a valid field when used with response_mime_types "application/json" or "text/x.enum"

Changes to _prepare_params():

  • Add response_mime_type and response_schema to gen_config

  • If a response schema is provided, normalise/convert the schema to a protos_schema for the google API request

Testing(optional)

Manual Testing with Inputs
Passed all langchain-google-genai-us integration tests.

Note(optional)

Dependencies: imported generation_types from google.generativeai.types
Documentation: Added docstrings for JSON Output and Schema Support in class ChatGoogleGenerativeAI and for parameters response_mime_type and response_schema.

@vishah02 vishah02 changed the title added support for JSON mode Genai: Integrate JSON Mode for Gemini 1.5 (flash) Nov 29, 2024
@vishah02 vishah02 marked this pull request as ready for review November 29, 2024 16:55
@lkuligin
Copy link
Collaborator

lkuligin commented Dec 1, 2024

@vishah02 thanks a lot for your contribution!

could you fix linting errors and add an integration test, please?

@vishah02 vishah02 marked this pull request as draft December 11, 2024 01:03
@vishah02 vishah02 marked this pull request as ready for review December 11, 2024 18:56
@vishah02
Copy link
Author

@lkuligin Hey, sorry it took a while to get to it. We added tests and fixed the linting errrors now! Let me know if there's anything else I can do!

@lkuligin
Copy link
Collaborator

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