Examples · anthropic · 47 of 339
files
The Files API: upload once, then refer to the file by id.
tin run examples/anthropic/files.tin// The Files API: upload once, then refer to the file by id. Needs ANTHROPIC_API_KEY and fs.read.
import "std/anthropic"
fn main() {
let c = anthropic.fromEnv()
let f = match c.uploadPath("report.pdf", "application/pdf") {
Ok(f) => f,
Err(e) => {
print(e.show())
return
}
}
print("uploaded {f.filename} ({f.sizeBytes} bytes) as {f.id}")
print(anthropic.fileDocument(f.id)) // a document block that refers to it
for x in c.files().unwrap() { print("{x.id} {x.filename}") }
print("deleted {c.deleteFile(f.id).unwrap()}")
}