数据集
创建数据集上传 URL
为新的数据集文件创建预签名上传 URL,在 presigned_url 过期前上传文件,再将返回的 dataset_id 传给处理接口。
POST
https://api.fastino.ai
/
v1
/
datasets
/
upload
/
url
创建数据集上传 URL
curl --request POST \
--url https://api.fastino.ai/v1/datasets/upload/url \
--header 'X-API-Key: <api-key>'import requests
url = "https://api.fastino.ai/v1/datasets/upload/url"
headers = {"X-API-Key": "<api-key>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {'X-API-Key': '<api-key>'}};
fetch('https://api.fastino.ai/v1/datasets/upload/url', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.fastino.ai/v1/datasets/upload/url",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.fastino.ai/v1/datasets/upload/url"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("X-API-Key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.fastino.ai/v1/datasets/upload/url")
.header("X-API-Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.fastino.ai/v1/datasets/upload/url")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
response = http.request(request)
puts response.read_bodyPOST /v1/datasets/upload/url
为新的数据集文件创建预签名上传 URL。
将 URL 绑定到文件
可选择发送content_length(精确字节数,最大 5 GiB)和 sha256(64 个字符的十六进制摘要)。
之后,存储服务会拒绝大小或摘要不一致的 PUT 请求,从而在处理之前发现被截断或已损坏的上传。
CONTENT_LENGTH="$(wc -c < training.jsonl | tr -d ' ')"
SHA256="$(shasum -a 256 training.jsonl | awk '{print $1}')"
curl --fail-with-body -sS https://api.fastino.ai/v1/datasets/upload/url \
-H "X-API-Key: $FASTINO_API_KEY" \
-H "Content-Type: application/json" \
-d "$(jq -n \
--argjson content_length "$CONTENT_LENGTH" \
--arg sha256 "$SHA256" \
'{
dataset_name: "docs-example-ner",
filename: "training.jsonl",
dataset_type: "ner",
content_length: $content_length,
sha256: $sha256
}')" > dataset-upload.json
上传文件
请在presigned_url 过期前上传文件的精确字节。请原样复制响应中 upload_headers
对象的每一项。该对象始终包含 Content-Type: application/octet-stream;如果你声明了
content_length 和 sha256,它还会包含已签名的 Content-Length 和
x-amz-checksum-sha256 值。缺少已签名的请求头或其值被更改时会返回 403。
PRESIGNED_URL="$(jq -r '.presigned_url' dataset-upload.json)"
curl --fail-with-body -X PUT \
-H "Content-Type: $(jq -r '.upload_headers["Content-Type"]' dataset-upload.json)" \
-H "Content-Length: $(jq -r '.upload_headers["Content-Length"]' dataset-upload.json)" \
-H "x-amz-checksum-sha256: $(jq -r '.upload_headers["x-amz-checksum-sha256"]' dataset-upload.json)" \
--upload-file training.jsonl "$PRESIGNED_URL"
Content-Length,但它仍必须与已签名的值一致。
上传成功后,将返回的 dataset_id 传给
POST /v1/datasets/upload/process。
授权
需要团队的 Owner、Admin 或 Editor 角色。其他角色会收到403 Forbidden。此页面对您有帮助吗?
⌘I
创建数据集上传 URL
curl --request POST \
--url https://api.fastino.ai/v1/datasets/upload/url \
--header 'X-API-Key: <api-key>'import requests
url = "https://api.fastino.ai/v1/datasets/upload/url"
headers = {"X-API-Key": "<api-key>"}
response = requests.post(url, headers=headers)
print(response.text)const options = {method: 'POST', headers: {'X-API-Key': '<api-key>'}};
fetch('https://api.fastino.ai/v1/datasets/upload/url', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.fastino.ai/v1/datasets/upload/url",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.fastino.ai/v1/datasets/upload/url"
req, _ := http.NewRequest("POST", url, nil)
req.Header.Add("X-API-Key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.fastino.ai/v1/datasets/upload/url")
.header("X-API-Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.fastino.ai/v1/datasets/upload/url")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
response = http.request(request)
puts response.read_body
