|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from abc import ABC, abstractmethod |
|
from typing import Dict, List, NewType |
|
|
|
import cohere |
|
|
|
Interaction = NewType("Interaction", Dict[str, str]) |
|
|
|
|
|
class Chatbot(ABC): |
|
"""Defines bots that reply to users in a 1:1 text conversation""" |
|
|
|
def __init__(self, client: cohere.Client): |
|
"""A Chatbot should be passed a Cohere Client for API calls. |
|
|
|
Args: |
|
client (cohere.Client): Provides access to Cohere API via the Python SDK |
|
""" |
|
|
|
self.co = client |
|
|
|
|
|
|
|
|
|
|
|
self.chat_history: List[Interaction] = [] |
|
|
|
@abstractmethod |
|
def reply(self, query: str) -> Interaction: |
|
"""Replies to a user given some input and context. |
|
|
|
Args: |
|
query (str): Most recent message from the user. |
|
|
|
Returns: |
|
Interaction: A dictionary consisting of the interaction, including the |
|
query and response. |
|
""" |
|
|