LoslegenKostenlos loslegen

Creating a ChatBot

Large language models, or LLM's are generative AI tools that can perform tasks such as text summarization and sentence completion with a simple call to an API. In this exercise, you'll design a ChatBot class that leverages a factory method to "hot-swap" LLM's in order to perform sentence completion. Below is the LLM "product" interface that has been created for you. Good luck!

class LLM(ABC):
  @abstractmethod
  def complete_sentence(self, prompt):
    pass

Diese Übung ist Teil des Kurses

Intermediate Object-Oriented Programming in Python

Kurs anzeigen

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Finish defining OpenAI and Anthropic classes
class OpenAI(LLM):
  def ____(self, ____):
    return prompt + " ... OpenAI end of sentence."
  
class Anthropic(____):
  def ____(____, ____):
    return ____ + " ... Anthropic end of sentence."
Code bearbeiten und ausführen