feat: support parametersJsonSchema on function declarations #2
@@ -45,7 +45,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
function_declarations: Some(vec![FunctionDeclaration {
|
||||
name: "take_snapshot".to_string(),
|
||||
description: "Takes a snapshot of the camera and returns it as an image.".to_string(),
|
||||
parameters: json!({"type": "object", "properties": {}}),
|
||||
parameters: Some(json!({"type": "object", "properties": {}})),
|
||||
parameters_json_schema: None,
|
||||
}]),
|
||||
..Default::default()
|
||||
}];
|
||||
|
||||
@@ -328,7 +328,14 @@ pub struct UsageMetadata {
|
||||
pub struct FunctionDeclaration {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub parameters: Value,
|
||||
/// Parameters in Vertex's OpenAPI schema subset. Don't set both this and
|
||||
/// `parameters_json_schema`: Vertex rejects the request.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub parameters: Option<Value>,
|
||||
/// Parameters as a JSON Schema, which accepts keywords the OpenAPI subset doesn't
|
||||
/// (`$schema`, `$ref`/`$defs`, `const`, type arrays, ...).
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub parameters_json_schema: Option<Value>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@@ -370,7 +377,34 @@ impl GenerateContentResponse {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{GenerateContentResponse, GenerateContentResponseResult};
|
||||
use serde_json::json;
|
||||
|
||||
use super::{FunctionDeclaration, GenerateContentResponse, GenerateContentResponseResult};
|
||||
|
||||
#[test]
|
||||
fn serializes_function_declaration_with_only_the_set_schema_field() {
|
||||
let schema = json!({"type": "object", "properties": {"q": {"type": "string"}}});
|
||||
let json_schema = FunctionDeclaration {
|
||||
name: "probe".to_string(),
|
||||
description: "Probe".to_string(),
|
||||
parameters: None,
|
||||
parameters_json_schema: Some(schema.clone()),
|
||||
};
|
||||
assert_eq!(
|
||||
serde_json::to_value(&json_schema).unwrap(),
|
||||
json!({"name": "probe", "description": "Probe", "parametersJsonSchema": schema})
|
||||
);
|
||||
|
||||
let openapi = FunctionDeclaration {
|
||||
parameters: Some(schema.clone()),
|
||||
parameters_json_schema: None,
|
||||
..json_schema
|
||||
};
|
||||
assert_eq!(
|
||||
serde_json::to_value(&openapi).unwrap(),
|
||||
json!({"name": "probe", "description": "Probe", "parameters": schema})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn parses_empty_metadata_response() {
|
||||
|
||||
Reference in New Issue
Block a user