Konuşmalar oluşturma

Llama 3 ile Çalışmak

Imtihan Ahmed

Machine Learning Engineer

Bağlamı koruma

Bağlamı koruma iş akışı - adım 1

Llama 3 ile Çalışmak

Bağlamı koruma

Bağlamı koruma iş akışı - adım 2

Llama 3 ile Çalışmak

Bağlamı koruma

Bağlamı koruma iş akışı - adım 3

Llama 3 ile Çalışmak

Bağlamı koruma

Bağlamı koruma iş akışı - adım 4

Llama 3 ile Çalışmak

Bağlamı koruma

Bağlamı koruma iş akışı - adım 5

  • Conversation sınıfıyla sohbet geçmişini izleyin
Llama 3 ile Çalışmak

Conversation sınıfı

  • Önceki iletilerin geçmişini saklayabilir
class Conversation:

def __init__(self, llm: Llama, system_prompt='', history=[]): self.llm = llm self.system_prompt = system_prompt
self.history = [{"role": "system", "content": self.system_prompt}] + history
Llama 3 ile Çalışmak

Conversation sınıfı

  • Önceki iletilerin geçmişini saklayabilir
class Conversation:
    def __init__(self, llm: Llama, system_prompt='', history=[]):
        self.llm = llm
        self.system_prompt = system_prompt
        self.history = [{"role": "system", "content": self.system_prompt}] + history

def create_completion(self, user_prompt=''):
self.history.append({"role": "user", "content": user_prompt}) # Girdiyi ekle
output = self.llm.create_chat_completion(messages=self.history)
conversation_result = output['choices'][0]['message'] self.history.append(conversation_result) # Çıktıyı ekle return conversation_result['content'] # Çıktıyı döndür
Llama 3 ile Çalışmak

Çok turlu bir konuşmayı yürütme

conversation = Conversation(llm, system_prompt="You are a virtual travel assistant 
                                                helping with planning trips.")


response1 = conversation.create_completion("What are some destinations in France for a short weekend break?")
print(f"Response 1: {response1}")
response2 = conversation.create_completion("How about Spain?")
print(f"Response 2: {response2}")
Llama 3 ile Çalışmak

Çok turlu bir konuşmayı yürütme

print(f"Response 1: {response1}")

print(f"Response 2: {response2}")

Çıktı

Llama 3 ile Çalışmak

Çok turlu bir konuşmayı yürütme

print(f"Response 1: {response1}")

print(f"Response 2: {response2}")

Vurgulanan bölümlerle çıktı

Llama 3 ile Çalışmak

Haydi pratik yapalım!

Llama 3 ile Çalışmak

Preparing Video For Download...