-
Notifications
You must be signed in to change notification settings - Fork 5.6k
[FEATURE] Google Gemini - Add support for structure JSON output #14896
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
components/google_gemini/actions/common/generate-content.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import app from "../../google_gemini.app.mjs"; | ||
| import constants from "../../common/constants.mjs"; | ||
|
|
||
| export default { | ||
| props: { | ||
| app, | ||
| model: { | ||
| propDefinition: [ | ||
| app, | ||
| "model", | ||
| () => ({ | ||
| filter: ({ | ||
| description, | ||
| supportedGenerationMethods, | ||
| }) => ![ | ||
| "discontinued", | ||
| "deprecated", | ||
| ].some((keyword) => description.includes(keyword)) | ||
| && supportedGenerationMethods?.includes(constants.MODEL_METHODS.GENERATE_CONTENT), | ||
| }), | ||
| ], | ||
| }, | ||
| }, | ||
| async additionalProps() { | ||
| const { | ||
| model, | ||
| responseFormat, | ||
| } = this; | ||
|
|
||
| const { | ||
| outputTokenLimit, | ||
| temperature, | ||
| topP, | ||
| topK, | ||
| maxTemperature, | ||
| } = await this.app.getModel({ | ||
| model, | ||
| }); | ||
|
|
||
| return { | ||
| ...(responseFormat && { | ||
| responseSchema: { | ||
| type: "string", | ||
| label: "Response Schema", | ||
| description: "Define the structure of the JSON response. Must be a valid JSON schema object. Leave empty to let Gemini determine the structure.", | ||
| optional: true, | ||
| }, | ||
| }), | ||
| ...(outputTokenLimit && { | ||
| maxOutputTokens: { | ||
| type: "integer", | ||
| label: "Max Output Tokens", | ||
| description: `The maximum number of tokens to generate in the response. Eg. \`${outputTokenLimit}\`.`, | ||
| optional: true, | ||
| max: outputTokenLimit, | ||
| }, | ||
| }), | ||
| ...(temperature && { | ||
| temperature: { | ||
| type: "string", | ||
| label: "Temperature", | ||
| description: `Controls the randomness of the generated text. Lower values make the text more deterministic, while higher values make it more random. Eg. \`${temperature}\`.${maxTemperature | ||
| ? ` Where max temperature is \`${maxTemperature}\`.` | ||
| : ""}`, | ||
| optional: true, | ||
| }, | ||
| }), | ||
| ...(topP && { | ||
| topP: { | ||
| type: "string", | ||
| label: "Top P", | ||
| description: `Controls the diversity of the generated text. Lower values make the text more deterministic, while higher values make it more random. Eg. \`${topP}\`.`, | ||
| optional: true, | ||
| }, | ||
| }), | ||
| ...(topK && { | ||
| topK: { | ||
| type: "integer", | ||
| label: "Top K", | ||
| description: `Controls the diversity of the generated text. Lower values make the text more deterministic, while higher values make it more random. Eg. \`${topK}\`.`, | ||
| optional: true, | ||
| }, | ||
| }), | ||
| stopSequences: { | ||
| type: "string[]", | ||
| label: "Stop Sequences", | ||
| description: "The set of character sequences (up to 5) that will stop output generation. If specified, the API will stop at the first appearance of a `stop_sequence`. The stop sequence will not be included as part of the response.", | ||
| optional: true, | ||
| }, | ||
| }; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| const BASE_URL = "https://generativelanguage.googleapis.com"; | ||
| const VERSION_PATH = "/v1"; | ||
| const VERSION_PATH = "/v1beta"; | ||
|
|
||
| const MODEL_METHODS = { | ||
| GENERATE_CONTENT: "generateContent", | ||
| }; | ||
|
|
||
| export default { | ||
| BASE_URL, | ||
| VERSION_PATH, | ||
| MODEL_METHODS, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
|
|
||
| function emptyStrToUndefined(value) { | ||
| const trimmed = typeof(value) === "string" && value.trim(); | ||
| return trimmed === "" | ||
| ? undefined | ||
| : value; | ||
| } | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| function parse(value) { | ||
| const valueToParse = emptyStrToUndefined(value); | ||
| if (typeof(valueToParse) === "object" || valueToParse === undefined) { | ||
| return valueToParse; | ||
| } | ||
| try { | ||
| return JSON.parse(valueToParse); | ||
| } catch (e) { | ||
| throw new ConfigurationError("Make sure the custom expression contains a valid object"); | ||
| } | ||
| } | ||
|
|
||
| export default { | ||
| parse, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.