Skip to content
Open
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 @@ -11,6 +11,7 @@ export type CacheControlEphemeral = {
* - `1h`: 1 hour
*
* Defaults to `5m`. See [prompt caching
* pricing](https://docs.claude.com/en/docs/build-with-claude/prompt-caching) for details.
* pricing](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) for
* details.
*/
ttl: Ttl | null, type: CacheControlEphemeralType, };
3 changes: 2 additions & 1 deletion bindings/typescript/src/generated/anthropic/Ttl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* - `1h`: 1 hour
*
* Defaults to `5m`. See [prompt caching
* pricing](https://docs.claude.com/en/docs/build-with-claude/prompt-caching) for details.
* pricing](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) for
* details.
*/
export type Ttl = "1h" | "5m";
14 changes: 14 additions & 0 deletions crates/generate-types/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ fn generate_openai_specific_types(openai_spec: &str) {
}
}

fn strip_quicktype_noise(output: &str) -> String {
output
.lines()
.filter(|line| {
let trimmed = line.trim();
!(trimmed.starts_with("===") && trimmed.ends_with("==="))
})
.collect::<Vec<_>>()
.join("\n")
}

fn generate_openai_types_with_quicktype(
openapi_spec: &str,
) -> Result<(), Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -196,6 +207,7 @@ fn generate_openai_types_with_quicktype(
}
Err(e) => return Err(format!("Failed to run quicktype: {}", e).into()),
};
let quicktype_output = strip_quicktype_noise(&quicktype_output);

// Clean up temp file
let _ = std::fs::remove_file(&temp_schema_path);
Expand Down Expand Up @@ -492,6 +504,7 @@ fn generate_anthropic_types_with_quicktype(
}
Err(e) => return Err(format!("Failed to run quicktype: {}", e).into()),
};
let quicktype_output = strip_quicktype_noise(&quicktype_output);

// Clean up temp file
let _ = std::fs::remove_file(&temp_schema_path);
Expand Down Expand Up @@ -1382,6 +1395,7 @@ fn generate_google_types_with_quicktype(spec: &serde_json::Value) {
return;
}
};
let quicktype_output = strip_quicktype_noise(&quicktype_output);

let _ = std::fs::remove_file(&temp_schema_path);

Expand Down
8 changes: 8 additions & 0 deletions crates/lingua/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ fn {test_fn_name}() {{
fs::write(&dest_path, generated_tests).unwrap();
}

// Snapshots whose request.json can no longer deserialize as CreateMessageParams
// after the Tool enum update (tool_search_tool_* variants removed).
const ANTHROPIC_ROUNDTRIP_SKIP_CASES: &[&str] = &["responsesToolSearchInputParam"];

fn generate_anthropic_test_cases(workspace: &Path, generate_snapshot_tests: bool) {
let snapshots_dir = workspace.join("payloads/snapshots");

Expand Down Expand Up @@ -271,6 +275,10 @@ fn generate_anthropic_test_cases(workspace: &Path, generate_snapshot_tests: bool
continue;
}

if ANTHROPIC_ROUNDTRIP_SKIP_CASES.contains(&test_case_name) {
continue;
}

// Check if this test case has anthropic directory
let anthropic_dir = path.join("anthropic");
if !anthropic_dir.exists() {
Expand Down
43 changes: 42 additions & 1 deletion crates/lingua/src/providers/anthropic/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,10 @@ mod tests {
}

#[test]
fn test_try_parse_anthropic_with_tool_search_tool() {
fn test_try_parse_anthropic_with_tool_search_tool_no_longer_in_tool_union() {
// tool_search_tool_* variants were removed from the generated Tool enum.
// Bare tool_search entries (no input_schema) no longer deserialize as
// CreateMessageParams because the CustomTool fallback requires input_schema.
let payload = json!({
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
Expand All @@ -575,6 +578,44 @@ mod tests {
]
});

assert!(try_parse_anthropic(&payload).is_err());
}

#[test]
fn test_try_parse_anthropic_with_web_search_tool() {
let payload = json!({
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Hello"}
],
"tools": [
{
"name": "web_search",
"type": "web_search_20260318"
}
]
});

assert!(try_parse_anthropic(&payload).is_ok());
}

#[test]
fn test_try_parse_anthropic_with_web_fetch_tool() {
let payload = json!({
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 1024,
"messages": [
{"role": "user", "content": "Hello"}
],
"tools": [
{
"name": "web_fetch",
"type": "web_fetch_20260318"
}
]
});

assert!(try_parse_anthropic(&payload).is_ok());
}
}
Loading
Loading