MulaiMulai sekarang secara gratis

Creating a conversational class

One of the most popular applications for LLMs like Llama is conversational chatbots, which allow users to send messages, get a response, and ask follow-up questions using a message history.

In this exercise, you'll create a class called Conversation that will allow you to create conversation with minimal code.

Latihan ini adalah bagian dari kursus

Working with Llama 3

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

class Conversation:
    # Complete the __init__ method of the Conversation class
    def __init__(self, llm: Llama, system_prompt='', history=[]):
        self.llm = ____
        self.system_prompt = ____
        self.history = [{"role": "system", "content": ____}] + history
Edit dan Jalankan Kode