Transformers documentation
Sohbet mesajı kalıpları
Sohbet mesajı kalıpları
Sohbet modelleri, konuşmaları sözlük listesi olarak bekler. Her sözlük role ve content anahtarlarını kullanır. content anahtarı, modele iletilen kullanıcı mesajını içerir. Büyük dil modelleri metin ve araçları kabul ederken, çok modlu modeller metni görüntüler, videolar ve sesle birleştirir.
Transformers, her modül tipinin açıkça belirtildiği birleşik bir biçim kullanır; bu da tek bir mesajda girdileri karıştırıp eşleştirmeyi kolaylaştırır.
Bu kılavuz, her modallite için mesaj biçimlendirme kalıplarını, araçları, toplu çıkarımı ve çok turlu sohbetleri kapsar.
Metin
Metin, en temel içerik türüdür. Diğer tüm kalıpların temelini oluşturur. Mesajınızı bir dize olarak "content" parametresine iletin.
message = [
{
"role": "user",
"content": "Explain the French Bread Law."
}
]Daha sonra görsel, video veya ses eklediğinizde kodunuzun tutarlı kalmasını sağlamak için açık "type": "text" biçimini de kullanabilirsiniz.
message = [
{
"role": "user",
"content": [{"type": "text", "text": "Explain the French Bread Law."}]
}
]Araçlar
Araçlar, bir sohbet modelinin kendi üretmek yerine çağırabileceği işlevlerdir; örneğin gerçek zamanlı hava durumu verisi almak gibi.
assistant rolü, araç isteğini işler. "tool_calls" anahtarında "type": "function" değerini ayarlayın ve aracınızı "function" anahtarına iletin. Asistanın araç isteğini mesajınıza ekleyin.
weather = {"name": "get_current_temperature", "arguments": {"location": "Paris, France", "unit": "celsius"}}
message.append(
{
"role": "assistant",
"tool_calls": [{"type": "function", "function": weather}]
}
)tool rolü sonucu işler. Bu değeri "content" alanına ekleyin. Bu değer her zaman bir dize olmalıdır.
message.append({"role": "tool", "content": "22"})Çok Modallı
Çok modlu modeller bu biçimi görüntüler, videolar ve sesleri işlemek üzere genişletir. Her girdi "type" ile türünü belirtir ve medyayı "url" veya "path" ile sağlar.
Görsel
"type": "image" değerini ayarlayın ve bağlantılar için "url", yerel dosyalar için "path" kullanın.
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
"type": "video" değerini ayarlayın ve bağlantılar için "url", yerel dosyalar için "path" kullanın.
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?"}
]
}
]Ses
"type": "audio" değerini ayarlayın ve bağlantılar için "url", yerel dosyalar için "path" kullanın.
message = [
{
"role": "user",
"content": [
{"type": "audio", "url": "https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/mlk.flac"},
{"type": "text", "text": "Transcribe the speech."}
]
}
]Karışık çoklu
content listesi, türlerin herhangi bir kombinasyonunu kabul eder. Model, tüm girdileri birlikte işleyerek karşılaştırmalara veya çapraz modlu akıl yürütmeye olanak tanır.
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?"},
],
}
]Toplu
Batched inference, bir ileri geçişte birden fazla sohbeti işleyerek verimliliği ve throughput'u artırır. Her sohbeti kendi listesi içinde sarın, ardından bunları listelerin listesi olarak birlikte iletin.
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?"}
]
},
],
]Çok turlu
Konuşmalar, "user" ve "assistant" rolleri arasında dönüşümlü olarak ilerleyen birden fazla etkileşimi kapsar. Her tur, modele tam konuşma geçmişine erişim imkânı veren yeni bir mesajı listeye ekler. Bu bağlam, modelin daha uygun yanıtlar üretmesine yardımcı olur.
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."}
]
}
]