Skip to content

Add response_schema parameter #302

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 15 commits into from
May 3, 2024
Merged
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions google/generativeai/types/generation_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import collections
import contextlib
import sys
from collections.abc import Iterable, AsyncIterable
from collections.abc import Iterable, AsyncIterable, Mapping
import dataclasses
import itertools
import textwrap
from typing import Union
from typing import Union, Any
from typing_extensions import TypedDict

import google.protobuf.json_format
Expand Down Expand Up @@ -80,6 +80,7 @@ class GenerationConfigDict(TypedDict, total=False):
max_output_tokens: int
temperature: float
response_mime_type: str
response_schema: glm.Schema | Mapping[str, str] # fmt: off


@dataclasses.dataclass
Expand Down Expand Up @@ -146,6 +147,10 @@ class GenerationConfig:
Supported mimetype:
`text/plain`: (default) Text output.
`application/json`: JSON response in the candidates.

response_schema:
Optional. Specifies the format of the JSON requested if response_mime_type is
`application/json`.
"""

candidate_count: int | None = None
Expand All @@ -155,6 +160,7 @@ class GenerationConfig:
top_p: float | None = None
top_k: int | None = None
response_mime_type: str | None = None
response_schema: glm.Schema | Mapping[str, Any] | None = None


GenerationConfigType = Union[glm.GenerationConfig, GenerationConfigDict, GenerationConfig]
Expand Down