-
Notifications
You must be signed in to change notification settings - Fork 159
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
base: main
Are you sure you want to change the base?
Conversation
@vishah02 thanks a lot for your contribution! could you fix linting errors and add an integration test, please? |
@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! |
@vishah02 you can check linter locally if you'd like to: |
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.