55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
from abc import ABC, abstractmethod
|
|
from typing import Iterator
|
|
from devchat.prompt import Prompt
|
|
|
|
|
|
class Chat(ABC):
|
|
"""
|
|
Chat interface for managing chat-related interactions.
|
|
|
|
This interface defines methods for prompting a chat system with
|
|
a list of Message objects and retrieving responses, either as a
|
|
complete response or as a streaming response.
|
|
"""
|
|
|
|
@abstractmethod
|
|
def init_prompt(self, request: str) -> Prompt:
|
|
"""
|
|
Initialize a prompt for the chat system.
|
|
|
|
Args:
|
|
request (str): The basic request of the prompt.
|
|
The returned prompt can be combined with more instructions and context.
|
|
"""
|
|
|
|
@abstractmethod
|
|
def load_prompt(self, data: dict) -> Prompt:
|
|
"""
|
|
Load a prompt from a dictionary.
|
|
|
|
Args:
|
|
data (dict): The dictionary containing the prompt data.
|
|
"""
|
|
|
|
@abstractmethod
|
|
def complete_response(self, prompt: Prompt) -> str:
|
|
"""
|
|
Retrieve a complete response JSON string from the chat system.
|
|
|
|
Args:
|
|
prompt (Prompt): A prompt of messages representing the conversation.
|
|
Returns:
|
|
str: A JSON string representing the complete response.
|
|
"""
|
|
|
|
@abstractmethod
|
|
def stream_response(self, prompt: Prompt) -> Iterator:
|
|
"""
|
|
Retrieve a streaming response as an iterator of JSON strings from the chat system.
|
|
|
|
Args:
|
|
prompt (Prompt): A prompt of messages representing the conversation.
|
|
Returns:
|
|
Iterator: An iterator over JSON strings (to be converted to) representing the response.
|
|
"""
|