这是indexloc提供的服务,不要输入任何密码
Skip to content

Added "JSON_mode" notebook for javascript #854

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

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

Conversation

andycandy
Copy link
Collaborator

No description provided.

@github-actions github-actions bot added the status:awaiting review PR awaiting review from a maintainer label Jul 14, 2025


## Setup
### Install SDK and set-up the client
Copy link
Collaborator

Choose a reason for hiding this comment

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

Two level 3 titles without anything in between

// [CODE ENDS]

/* Markdown (render)
## Set your constrained output in the prompt
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should first explain what Json mode is.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Check how we do it in the documentation, but µI think we should explain why you would need to use json mode (like an example), and then how it works.

// [CODE ENDS]

/* Markdown (render)
Now select the model you want to use in this guide, either by selecting one in the list or writing it down. Keep in mind that some models, like the 2.5 ones are thinking models and thus take slightly more time to respond (cf. [thinking notebook](./Get_started_thinking.ipynb) for more details and in particular learn how to switch the thiking off).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wrong link (point to the python cookbook for now as it will be easier to find them all and fix them)

prompt = `
List a few popular cookie recipes using this JSON schema:

Recipe = {'recipe_name': str}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should also explain where the format comes from since it's a python thing if I'm not mistaken.

/* Markdown (render)
## Supply the schema to the model directly

The newest models (1.5 and beyond) allow you to pass a schema object (or a python type equivalent) directly and the output will strictly follow that schema.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can drop the "newest models" as the older ones are not available anymore.

```
[
{
"recipe_name": "Chocolate Chip Cookies"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there's an encoding error here.


### Continue your discovery of the Gemini API

JSON is not the only way to constrain the output of the model, you can also use an [Enum](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Enum.ipynb). [Function calling](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Function_calling.ipynb) and [Code execution](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Code_Execution.ipynb) are other ways to enhance your model by either using your own functions or by letting the model write and run them.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add a link to the quickstart as that's the only one we have at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:awaiting review PR awaiting review from a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants