Gemini API รองรับการอัปโหลดไฟล์สื่อแยกต่างหากจากอินพุตพรอมต์ คุณจึงนำสื่อของคุณมาใช้ซ้ำได้ในคำขอหลายรายการและพรอมต์หลายรายการ โปรดดูรายละเอียดเพิ่มเติมในคู่มือการส่งข้อความแจ้งด้วยสื่อ
เมธอด: media.upload
สร้าง File
ปลายทาง
- อัปโหลด URI สำหรับคำขออัปโหลดสื่อ:
https://generativelanguage.googleapis.com/upload/v1beta/files
- URI ข้อมูลเมตา สำหรับคำขอที่มีข้อมูลเมตาเท่านั้น:
https://generativelanguage.googleapis.com/v1beta/files
เนื้อหาของคำขอ
เนื้อหาของคำขอมีข้อมูลที่มีโครงสร้างต่อไปนี้
file
object (File
)
ไม่บังคับ ข้อมูลเมตาสำหรับสร้างไฟล์
ตัวอย่างคำขอ
รูปภาพ
Python
Node.js
Go
เปลือกหอย
เสียง
Python
Node.js
Go
เปลือกหอย
ข้อความ
Python
Node.js
Go
เปลือกหอย
วิดีโอ
Python
Node.js
Go
เปลือกหอย
Python
เมธอด: files.get
รับข้อมูลเมตาสำหรับ File
ที่ระบุ
ปลายทาง
ซื้อ
https://generativelanguage.googleapis.com/v1beta/{name=files/*}
พารามิเตอร์เส้นทาง
name
string
ต้องระบุ ชื่อของ File
ที่จะรับ ตัวอย่างเช่น files/abc-123
อยู่ในรูปแบบ files/{file}
เนื้อหาของคำขอ
เนื้อหาของคำขอต้องว่างเปล่า
ตัวอย่างคำขอ
Python
Node.js
Go
เปลือกหอย
เนื้อหาการตอบกลับ
หากทำสำเร็จ เนื้อหาการตอบกลับจะมีอินสแตนซ์ File
เมธอด: files.list
แสดงรายการข้อมูลเมตาสำหรับ File
ที่เป็นของโปรเจ็กต์ที่ส่งคำขอ
ปลายทาง
ซื้อ
https://generativelanguage.googleapis.com/v1beta/files
พารามิเตอร์การค้นหา
pageSize
integer
ไม่บังคับ จำนวนสูงสุด File
วินาทีที่จะแสดงผลต่อ 1 หน้า หากไม่ระบุ ค่าเริ่มต้นจะเป็น 10 สูงสุด pageSize
คือ 100
pageToken
string
ไม่บังคับ โทเค็นของหน้าเว็บจากการเรียก files.list
ก่อนหน้า
เนื้อหาของคำขอ
เนื้อหาของคำขอต้องว่างเปล่า
ตัวอย่างคำขอ
Python
Node.js
Go
เปลือกหอย
เนื้อหาการตอบกลับ
การตอบกลับสำหรับ files.list
หากทำสำเร็จ เนื้อหาการตอบกลับจะมีข้อมูลซึ่งมีโครงสร้างดังต่อไปนี้
files[]
object (File
)
รายการ File
nextPageToken
string
โทเค็นที่ส่งเป็น pageToken
ในการเรียกใช้ files.list
ครั้งถัดไปได้
การแสดง JSON |
---|
{
"files": [
{
object ( |
เมธอด: files.delete
ลบ File
ปลายทาง
ลบ
https://generativelanguage.googleapis.com/v1beta/{name=files/*}
พารามิเตอร์เส้นทาง
name
string
ต้องระบุ ชื่อของ File
ที่จะลบ ตัวอย่างเช่น files/abc-123
อยู่ในรูปแบบ files/{file}
เนื้อหาของคำขอ
เนื้อหาของคำขอต้องว่างเปล่า
ตัวอย่างคำขอ
Python
Node.js
Go
เปลือกหอย
เนื้อหาการตอบกลับ
หากสำเร็จ เนื้อหาการตอบกลับจะว่างเปล่า
ทรัพยากร REST: ไฟล์
ทรัพยากร: ไฟล์
ไฟล์ที่อัปโหลดไปยัง API
name
string
เปลี่ยนแปลงไม่ได้ ตัวระบุ ชื่อทรัพยากร File
รหัส (ชื่อที่ไม่รวมคำนำหน้า "files/") มีอักขระได้สูงสุด 40 ตัวซึ่งเป็นอักขระที่เป็นตัวอักษรพิมพ์เล็กและตัวเลขคละกันหรือขีดกลาง (-) รหัสต้องไม่ขึ้นต้นหรือลงท้ายด้วยขีดกลาง หากไม่มีชื่อปรากฏในการสร้าง ระบบจะสร้างชื่อที่ไม่ซ้ำกันขึ้นมา ตัวอย่าง: files/123-456
displayName
string
ไม่บังคับ ชื่อที่แสดงที่มนุษย์อ่านได้สำหรับ File
ชื่อที่แสดงต้องมีความยาวไม่เกิน 512 อักขระ รวมเว้นวรรค ตัวอย่างเช่น "รูปภาพต้อนรับ"
mimeType
string
เอาต์พุตเท่านั้น ประเภท MIME ของไฟล์
sizeBytes
string (int64 format)
เอาต์พุตเท่านั้น ขนาดของไฟล์ในหน่วยไบต์
createTime
string (Timestamp
format)
เอาต์พุตเท่านั้น การประทับเวลาที่สร้าง File
การประทับเวลาเป็น RFC3339 UTC "Zulu" โดยมีความละเอียดระดับนาโนวินาทีและมีเลขเศษส่วนสูงสุด 9 หลัก ตัวอย่าง: "2014-10-02T15:01:23Z"
และ "2014-10-02T15:01:23.045123456Z"
updateTime
string (Timestamp
format)
เอาต์พุตเท่านั้น การประทับเวลาเมื่อมีการอัปเดต File
ครั้งล่าสุด
การประทับเวลาเป็น RFC3339 UTC "Zulu" โดยมีความละเอียดระดับนาโนวินาทีและมีเลขเศษส่วนสูงสุด 9 หลัก ตัวอย่าง: "2014-10-02T15:01:23Z"
และ "2014-10-02T15:01:23.045123456Z"
expirationTime
string (Timestamp
format)
เอาต์พุตเท่านั้น การประทับเวลาที่ระบบจะลบ File
ตั้งค่าเฉพาะเมื่อ File
กำหนดเวลาหมดอายุเท่านั้น
การประทับเวลาเป็น RFC3339 UTC "Zulu" โดยมีความละเอียดระดับนาโนวินาทีและมีเลขเศษส่วนสูงสุด 9 หลัก ตัวอย่าง: "2014-10-02T15:01:23Z"
และ "2014-10-02T15:01:23.045123456Z"
sha256Hash
string (bytes format)
เอาต์พุตเท่านั้น แฮช SHA-256 ของไบต์ที่อัปโหลด
สตริงที่เข้ารหัสฐาน 64
uri
string
เอาต์พุตเท่านั้น URI ของ File
state
enum (State
)
เอาต์พุตเท่านั้น สถานะการประมวลผลไฟล์
error
object (Status
)
เอาต์พุตเท่านั้น สถานะข้อผิดพลาดหากประมวลผลไฟล์ไม่สำเร็จ
metadata
ข้อมูลเมตาสำหรับไฟล์ metadata
ต้องเป็นค่าใดค่าหนึ่งต่อไปนี้
videoMetadata
object (VideoMetadata
)
เอาต์พุตเท่านั้น ข้อมูลเมตาสำหรับวิดีโอ
การแสดง JSON |
---|
{ "name": string, "displayName": string, "mimeType": string, "sizeBytes": string, "createTime": string, "updateTime": string, "expirationTime": string, "sha256Hash": string, "uri": string, "state": enum ( |
VideoMetadata
ข้อมูลเมตาสำหรับวิดีโอ File
videoDuration
string (Duration
format)
ระยะเวลาของวิดีโอ
ระยะเวลาเป็นวินาทีโดยมีเลขเศษส่วนไม่เกิน 9 หลัก ลงท้ายด้วย "s
" ตัวอย่างเช่น "3.5s"
การแสดง JSON |
---|
{ "videoDuration": string } |
รัฐ
สถานะสำหรับวงจรของไฟล์
Enum | |
---|---|
STATE_UNSPECIFIED |
ค่าเริ่มต้น ระบบจะใช้ค่านี้หากเว้นสถานะไว้ |
PROCESSING |
ระบบกำลังประมวลผลไฟล์และยังใช้สำหรับการอนุมานไม่ได้ |
ACTIVE |
ไฟล์ได้รับการประมวลผลและพร้อมสำหรับการอนุมาน |
FAILED |
ประมวลผลไฟล์ไม่สำเร็จ |
สถานะ
ประเภท Status
กำหนดโมเดลข้อผิดพลาดเชิงตรรกะที่เหมาะกับสภาพแวดล้อมในการเขียนโปรแกรมแบบต่างๆ ซึ่งรวมถึง REST API และ RPC API gRPC ใช้ ข้อความ Status
แต่ละข้อความจะมีข้อมูล 3 ส่วน ได้แก่ รหัสข้อผิดพลาด ข้อความแสดงข้อผิดพลาด และรายละเอียดข้อผิดพลาด
คุณสามารถดูข้อมูลเพิ่มเติมเกี่ยวกับรูปแบบข้อผิดพลาดนี้และวิธีใช้รูปแบบดังกล่าวได้ในคู่มือการออกแบบ API
code
integer
รหัสสถานะ ซึ่งควรเป็นค่า enum ของ google.rpc.Code
message
string
ข้อความแสดงข้อผิดพลาดที่นักพัฒนาแอปเห็น ซึ่งควรเป็นภาษาอังกฤษ ข้อความแสดงข้อผิดพลาดที่แสดงต่อผู้ใช้ควรแปลและส่งในช่อง google.rpc.Status.details
หรือแปลโดยไคลเอ็นต์
details[]
object
รายการข้อความที่มีรายละเอียดข้อผิดพลาด API จะใช้ชุดประเภทข้อความที่พบได้ทั่วไป
ออบเจ็กต์ที่มีช่องประเภทที่กำหนดเอง ช่องเพิ่มเติม "@type"
จะมี URI ที่ระบุประเภท ตัวอย่างเช่น { "id": 1234, "@type": "types.example.com/standard/id" }
การแสดง JSON |
---|
{ "code": integer, "message": string, "details": [ { "@type": string, field1: ..., ... } ] } |