Remove unnecessary fields from the tool schemas (#29381)
This PR removes two fields from JSON schemas (`$schema` and `title`), which are not expected by any model provider, but were spuriously included by our JSON schema library, `schemars`. These added noise to requests and cost wasted input tokens. ### Old ```json { "$schema": "http://json-schema.org/draft-07/schema#", "title": "FetchToolInput", "type": "object", "required": [ "url" ], "properties": { "url": { "description": "The URL to fetch.", "type": "string" } } } ``` ### New: ```json { "properties": { "url": { "description": "The URL to fetch.", "type": "string" } }, "required": [ "url" ], "type": "object" } ``` - N/A
This commit is contained in:
parent
17ecf94f6f
commit
57d8397f53
3 changed files with 49 additions and 25 deletions
|
@ -10,6 +10,11 @@ pub fn adapt_schema_to_format(
|
|||
json: &mut Value,
|
||||
format: LanguageModelToolSchemaFormat,
|
||||
) -> Result<()> {
|
||||
if let Value::Object(obj) = json {
|
||||
obj.remove("$schema");
|
||||
obj.remove("title");
|
||||
}
|
||||
|
||||
match format {
|
||||
LanguageModelToolSchemaFormat::JsonSchema => Ok(()),
|
||||
LanguageModelToolSchemaFormat::JsonSchemaSubset => adapt_to_json_schema_subset(json),
|
||||
|
@ -30,10 +35,7 @@ fn adapt_to_json_schema_subset(json: &mut Value) -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
const KEYS_TO_REMOVE: [&str; 2] = ["format", "$schema"];
|
||||
for key in KEYS_TO_REMOVE {
|
||||
obj.remove(key);
|
||||
}
|
||||
obj.remove("format");
|
||||
|
||||
if let Some(default) = obj.get("default") {
|
||||
let is_null = default.is_null();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue