Skip to content

AIProvider Class API Reference

The AIProvider class is an abstract base class that defines the interface for all AI provider implementations in ClientAI. It ensures consistency across different providers.

Class Definition

Bases: ABC

Abstract base class for AI providers.

Source code in clientai/ai_provider.py
class AIProvider(ABC):
    """
    Abstract base class for AI providers.
    """

    @abstractmethod
    def generate_text(
        self,
        prompt: str,
        model: str,
        return_full_response: bool = False,
        stream: bool = False,
        **kwargs: Any,
    ) -> GenericResponse:
        """
        Generate text based on a given prompt.

        Args:
            prompt: The input prompt for text generation.
            model: The name or identifier of the AI model to use.
            return_full_response: If True, return the full response object
                                  instead of just the generated text.
            stream: If True, return an iterator for streaming responses.
            **kwargs: Additional keyword arguments specific to
                      the provider's API.

        Returns:
            GenericResponse:
                The generated text response, full response object,
                or an iterator for streaming responses.
        """
        pass

    @abstractmethod
    def chat(
        self,
        messages: List[Message],
        model: str,
        return_full_response: bool = False,
        stream: bool = False,
        **kwargs: Any,
    ) -> GenericResponse:
        """
        Engage in a chat conversation.

        Args:
            messages: A list of message dictionaries, each containing
                      'role' and 'content'.
            model: The name or identifier of the AI model to use.
            return_full_response: If True, return the full response object
                                  instead of just the chat content.
            stream: If True, return an iterator for streaming responses.
            **kwargs: Additional keyword arguments specific to
                      the provider's API.

        Returns:
            GenericResponse:
                The chat response, either as a string, a dictionary,
                or an iterator for streaming responses.
        """
        pass

chat(messages, model, return_full_response=False, stream=False, **kwargs) abstractmethod

Engage in a chat conversation.

Parameters:

Name Type Description Default
messages List[Message]

A list of message dictionaries, each containing 'role' and 'content'.

required
model str

The name or identifier of the AI model to use.

required
return_full_response bool

If True, return the full response object instead of just the chat content.

False
stream bool

If True, return an iterator for streaming responses.

False
**kwargs Any

Additional keyword arguments specific to the provider's API.

{}

Returns:

Name Type Description
GenericResponse GenericResponse

The chat response, either as a string, a dictionary, or an iterator for streaming responses.

Source code in clientai/ai_provider.py
@abstractmethod
def chat(
    self,
    messages: List[Message],
    model: str,
    return_full_response: bool = False,
    stream: bool = False,
    **kwargs: Any,
) -> GenericResponse:
    """
    Engage in a chat conversation.

    Args:
        messages: A list of message dictionaries, each containing
                  'role' and 'content'.
        model: The name or identifier of the AI model to use.
        return_full_response: If True, return the full response object
                              instead of just the chat content.
        stream: If True, return an iterator for streaming responses.
        **kwargs: Additional keyword arguments specific to
                  the provider's API.

    Returns:
        GenericResponse:
            The chat response, either as a string, a dictionary,
            or an iterator for streaming responses.
    """
    pass

generate_text(prompt, model, return_full_response=False, stream=False, **kwargs) abstractmethod

Generate text based on a given prompt.

Parameters:

Name Type Description Default
prompt str

The input prompt for text generation.

required
model str

The name or identifier of the AI model to use.

required
return_full_response bool

If True, return the full response object instead of just the generated text.

False
stream bool

If True, return an iterator for streaming responses.

False
**kwargs Any

Additional keyword arguments specific to the provider's API.

{}

Returns:

Name Type Description
GenericResponse GenericResponse

The generated text response, full response object, or an iterator for streaming responses.

Source code in clientai/ai_provider.py
@abstractmethod
def generate_text(
    self,
    prompt: str,
    model: str,
    return_full_response: bool = False,
    stream: bool = False,
    **kwargs: Any,
) -> GenericResponse:
    """
    Generate text based on a given prompt.

    Args:
        prompt: The input prompt for text generation.
        model: The name or identifier of the AI model to use.
        return_full_response: If True, return the full response object
                              instead of just the generated text.
        stream: If True, return an iterator for streaming responses.
        **kwargs: Additional keyword arguments specific to
                  the provider's API.

    Returns:
        GenericResponse:
            The generated text response, full response object,
            or an iterator for streaming responses.
    """
    pass