MulaiMulai sekarang secara gratis

Multi-turn conversations

Let's extend the travel chatbot to allow users to respond to the model's initial recommendation. You'll again use the Conversation class, but this time, you'll make repeated calls to the model to see how the model handles previous information.

As a reminder, here are the methods from the Conversation class:

  • __init__(self, llm: Llama, system_prompt='', history=[])
  • create_completion(self, user_prompt='')

Latihan ini adalah bagian dari kursus

Working with Llama 3

Lihat Kursus

Petunjuk latihan

  • Ask for an initial travel recommendation, and provide a follow-up request after the first model response.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

chatbot = Conversation(llm, system_prompt="You are a travel expert that recommends a travel destination based on a prompt. Return the location name only as 'City, Country'.")

# Ask for the initial travel recommendation
first_recommendation = chatbot.____("Recommend a Spanish-speaking city.")
print(first_recommendation)

# Add an additional request to update the recommendation
second_recommendation = chatbot.____("A different city in the same country")
print(second_recommendation)
Edit dan Jalankan Kode