Buckets:
| # Pola pesan chat | |
| Model chat mengharapkan percakapan sebagai daftar kamus. Setiap kamus menggunakan kunci `role` dan `content`. Kunci `content` berisi pesan pengguna yang diteruskan ke model. Model bahasa besar menerima teks dan tools, sedangkan model multimodal menggabungkan teks dengan gambar, video, dan audio. | |
| Transformers menggunakan format terpadu di mana setiap tipe modalitas ditentukan secara eksplisit, sehingga mudah untuk mencampur dan memadukan input dalam satu pesan. | |
| Panduan ini membahas pola format pesan untuk setiap modalitas, alat, inferensi batch, dan percakapan multi-turn. | |
| ## Teks | |
| Teks adalah tipe konten paling dasar. Ini menjadi fondasi untuk semua pola lainnya. Kirim pesan Anda ke `"content"` sebagai string. | |
| ```py | |
| message = [ | |
| { | |
| "role": "user", | |
| "content": "Explain the French Bread Law." | |
| } | |
| ] | |
| ``` | |
| Anda juga dapat menggunakan format eksplisit `"type": "text"` untuk menjaga konsistensi kode Anda saat menambahkan gambar, video, atau audio di kemudian hari. | |
| ```py | |
| message = [ | |
| { | |
| "role": "user", | |
| "content": [{"type": "text", "text": "Explain the French Bread Law."}] | |
| } | |
| ] | |
| ``` | |
| ## Alat | |
| [Tools](./chat_extras) adalah fungsi yang dapat dipanggil oleh model chat, seperti mengambil data cuaca real-time, alih-alih menghasilkannya sendiri. | |
| Peran `assistant` menangani permintaan alat. Atur `"type": "function"` pada kunci `"tool_calls"` dan berikan alat Anda pada kunci `"function"`. Tambahkan permintaan alat dari asisten ke pesan Anda. | |
| ```py | |
| weather = {"name": "get_current_temperature", "arguments": {"location": "Paris, France", "unit": "celsius"}} | |
| message.append( | |
| { | |
| "role": "assistant", | |
| "tool_calls": [{"type": "function", "function": weather}] | |
| } | |
| ) | |
| ``` | |
| Peran `tool` menangani hasilnya. Tambahkan di `"content"`. Nilai ini harus selalu berupa string. | |
| ```py | |
| message.append({"role": "tool", "content": "22"}) | |
| ``` | |
| ## Multimodal | |
| Model multimodal memperluas format ini untuk menangani gambar, video, dan audio. Setiap input menentukan `"type"` dan menyediakan media dengan `"url"` atau `"path"`. | |
| ### Gambar | |
| Set `"type": "image"` dan gunakan `"url"` untuk tautan atau `"path"` untuk file lokal. | |
| ```py | |
| message = [ | |
| { | |
| "role": "user", | |
| "content": [ | |
| {"type": "image", "url": "https://assets.bonappetit.com/photos/57ad4ebc53e63daf11a4ddc7/master/w_1280,c_limit/kouign-amann.jpg"}, | |
| {"type": "text", "text": "What pastry is shown in the image?"} | |
| ] | |
| } | |
| ] | |
| ``` | |
| ### Video | |
| Set `"type": "video"` dan gunakan `"url"` untuk tautan atau `"path"` untuk file lokal. | |
| ```py | |
| message = [ | |
| { | |
| "role": "user", | |
| "content": [ | |
| {"type": "video", "url": "https://static01.nyt.com/images/2019/10/01/dining/01Sourdough-GIF-1/01Sourdough-GIF-1-superJumbo.gif"}, | |
| {"type": "text", "text": "What is shown in this video?"} | |
| ] | |
| } | |
| ] | |
| ``` | |
| ### Audio | |
| Set `"type": "audio"` dan gunakan `"url"` untuk tautan atau `"path"` untuk file lokal. | |
| ```py | |
| message = [ | |
| { | |
| "role": "user", | |
| "content": [ | |
| {"type": "audio", "url": "https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac"}, | |
| {"type": "text", "text": "Transcribe the speech."} | |
| ] | |
| } | |
| ] | |
| ``` | |
| ### Campuran beberapa | |
| Daftar `content` menerima kombinasi tipe apa pun. Model memproses semua input secara bersama, memungkinkan perbandingan atau penalaran lintas-modal. | |
| ```py | |
| message = [ | |
| { | |
| "role": "user", | |
| "content": [ | |
| {"type": "image", "url": "https://assets.bonappetit.com/photos/57ad4ebc53e63daf11a4ddc7/master/w_1280,c_limit/kouign-amann.jpg"}, | |
| {"type": "video", "url": "https://static01.nyt.com/images/2019/10/01/dining/01Sourdough-GIF-1/01Sourdough-GIF-1-superJumbo.gif"}, | |
| {"type": "text", "text": "What does the image and video share in common?"}, | |
| ], | |
| }, | |
| { | |
| "role": "user", | |
| "content": [ | |
| {"type": "image", "url": "https://assets.bonappetit.com/photos/57ad4ebc53e63daf11a4ddc7/master/w_1280,c_limit/kouign-amann.jpg"}, | |
| {"type": "image", "url": "https://assets.bonappetit.com/photos/57e191f49f19b4610e6b7693/master/w_1600%2Cc_limit/undefined"}, | |
| {"type": "text", "text": "What type of pastries are these?"}, | |
| ], | |
| } | |
| ] | |
| ``` | |
| ## Batch | |
| Inferensi ber-batch memproses beberapa percakapan dalam satu langkah maju untuk meningkatkan throughput dan efisiensi. Bungkus setiap percakapan dalam list-nya sendiri, lalu lewati semuanya bersama sebagai list of lists. | |
| ```py | |
| messages = [ | |
| [ | |
| {"role": "user", | |
| "content": [ | |
| {"type": "image", "url": "https://assets.bonappetit.com/photos/57ad4ebc53e63daf11a4ddc7/master/w_1280,c_limit/kouign-amann.jpg"}, | |
| {"type": "text", "text": "What type of pastry is this?"} | |
| ] | |
| }, | |
| ], | |
| [ | |
| {"role": "user", | |
| "content": [ | |
| {"type": "image", "url": "https://assets.bonappetit.com/photos/57e191f49f19b4610e6b7693/master/w_1600%2Cc_limit/undefined"}, | |
| {"type": "text", "text": "What type of pastry is this?"} | |
| ] | |
| }, | |
| ], | |
| ] | |
| ``` | |
| ## Multi-p | |
| Percakapan mencakup beberapa pertukaran, bergantian antara peran `"user"` dan `"assistant"`. Setiap giliran menambahkan pesan baru ke daftar, memberikan model akses ke riwayat percakapan lengkap. Konteks ini membantu model menghasilkan respons yang lebih tepat. | |
| ```py | |
| message = [ | |
| { | |
| "role": "user", | |
| "content": [ | |
| {"type": "image", "url": "https://assets.bonappetit.com/photos/57ad4ebc53e63daf11a4ddc7/master/w_1280,c_limit/kouign-amann.jpg"}, | |
| {"type": "text", "text": "What pastry is shown in the image?"} | |
| ] | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": [{"type": "text", "text": "This is kouign amann, a laminated dough pastry (i.e., dough folded with layers of butter) that also incorporates sugar between layers so that during baking the sugar caramelizes."}] | |
| }, | |
| { | |
| "role": "user", | |
| "content": [ | |
| {"type": "image", "url": "https://static01.nyt.com/images/2023/07/21/multimedia/21baguettesrex-hbkc/21baguettesrex-hbkc-videoSixteenByNineJumbo1600.jpg"}, | |
| {"type": "text", "text": "Compare it to this image now."} | |
| ] | |
| } | |
| ] | |
| ``` | |
Xet Storage Details
- Size:
- 6.36 kB
- Xet hash:
- c55fd3929995dc55bc36f3dac3ed90c05ab5f3e714d24c8a01000de17ced6bf7
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.