BaşlayınÜcretsiz Başlayın

Örnek konuşmalarla bağlam sağlama

Çeşitli ürünler için çok geniş teslimat seçenekleri sunan MyPersonalDelivery adlı bir teslimat hizmeti olduğunu varsayalım. Müşterilerin ihtiyaç duyduğu her konuda destek veren bir müşteri hizmetleri sohbet botu oluşturmak istiyorsun. Bunu başarmak için, önceki konuşmalardan şirketin teslim ettiği ürünlerle ilgili bir context_question ve context_answer sağlayacak ve ardından modelin bu bağlamı yeni bir kullanıcı istemi üzerinden tanıyıp tanımadığını test edeceksin.

OpenAI paketi ile context_question ve context_answer dizeleri senin için önceden yüklendi.

Bu egzersiz

OpenAI API ile Prompt Engineering

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Sohbet botunun amacını tanımlayan ve soruları nazik bir şekilde yanıtlamasını yönlendiren bir system_prompt tanımla.
  • Yeni kullanıcı sorgusuna yanıt verebilmesi için sohbet botunun bağlam olarak kullanabileceği bir konuşma oluştururken system_prompt, context_question ve context_answer öğelerini kullan.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

client = OpenAI(api_key="")

# Define the system prompt
system_prompt = "____"

context_question = "What types of items can be delivered using MyPersonalDelivery?"
context_answer = "We deliver everything from everyday essentials such as groceries, medications, and documents to larger items like electronics, clothing, and furniture. However, please note that we currently do not offer delivery for hazardous materials or extremely fragile items requiring special handling."

# Add the context to the model
response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "____", "content": ____},
            {"role": "____", "content": ____},
            {"role": "____", "content": ____ },
            {"role": "user", "content": "Do you deliver furniture?"}])
response = response.choices[0].message.content
print(response)
Kodu Düzenle ve Çalıştır