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

feat: Support response MIME type in ChatFirebaseVertexAI (#461) #463

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ class ChatFirebaseVertexAI extends BaseChatModel<ChatFirebaseVertexAIOptions> {
temperature: options?.temperature ?? defaultOptions.temperature,
topP: options?.topP ?? defaultOptions.topP,
topK: options?.topK ?? defaultOptions.topK,
responseMimeType:
options?.responseMimeType ?? defaultOptions.responseMimeType,
// responseSchema not supported yet
// responseSchema:
// (options?.responseSchema ?? defaultOptions.responseSchema)
// ?.toSchema(),
),
(options?.tools ?? defaultOptions.tools)?.toToolList(),
(options?.toolChoice ?? defaultOptions.toolChoice)?.toToolConfig(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,17 @@ extension ChatToolListMapper on List<ToolSpec> {
(tool) => f.FunctionDeclaration(
tool.name,
tool.description,
_mapJsonSchemaToSchema(tool.inputJsonSchema),
tool.inputJsonSchema.toSchema(),
),
).toList(growable: false),
),
];
}
}

f.Schema _mapJsonSchemaToSchema(final Map<String, dynamic> jsonSchema) {
extension SchemaMapper on Map<String, dynamic> {
f.Schema toSchema() {
final jsonSchema = this;
final type = jsonSchema['type'] as String;
final description = jsonSchema['description'] as String?;
final nullable = jsonSchema['nullable'] as bool?;
Expand Down Expand Up @@ -247,7 +250,7 @@ extension ChatToolListMapper on List<ToolSpec> {
);
case 'array':
if (items != null) {
final itemsSchema = _mapJsonSchemaToSchema(items);
final itemsSchema = items.toSchema();
return f.Schema.array(
description: description,
nullable: nullable,
Expand All @@ -258,7 +261,10 @@ extension ChatToolListMapper on List<ToolSpec> {
case 'object':
if (properties != null) {
final propertiesSchema = properties.map(
(key, value) => MapEntry(key, _mapJsonSchemaToSchema(value)),
(key, value) => MapEntry(
key,
(value as Map<String, dynamic>).toSchema(),
),
);
return f.Schema.object(
properties: propertiesSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ChatFirebaseVertexAIOptions extends ChatModelOptions {
this.maxOutputTokens,
this.temperature,
this.stopSequences,
this.responseMimeType,
this.safetySettings,
super.tools,
super.toolChoice,
Expand Down Expand Up @@ -69,6 +70,13 @@ class ChatFirebaseVertexAIOptions extends ChatModelOptions {
/// The stop sequence will not be included as part of the response.
final List<String>? stopSequences;

/// Output response mimetype of the generated candidate text.
///
/// Supported mimetype:
/// - `text/plain`: (default) Text output.
/// - `application/json`: JSON response in the candidates.
final String? responseMimeType;

/// A list of unique [ChatFirebaseVertexAISafetySetting] instances for blocking
/// unsafe content.
///
Expand Down
Loading