Protocols

Prompt Provider Handler Protocols

This module defines protocols for prompt provider handler functions, ensuring a consistent interface across all implementations.

Overview

These protocols use typing.Protocol to specify the expected function signatures for prompt provider handlers. This approach enforces structural typing, allowing maximum flexibility in implementation while guaranteeing that all handlers conform to the required interface.

Key Points:

  • All handler functions must have the same signature as defined by the protocols

    in this module.

  • typing.Protocol is used to define these structural types, without

    enforcing a specific class hierarchy.

  • This ensures interoperability and consistency across different prompt provider integrations.

smarter.apps.provider.services.text_completion.lib.protocols.OpenAICompatibleChatCompletionResponseType

OpenAICompatibleChatCompletionResponseType is a type alias that defines the expected.

return type for OpenAI-compatible prompt provider handler functions. It can be either a ChatCompletion object (representing a successful response) or one of several specific error response types, including HTTP 403 Forbidden, HTTP 404 Not Found, HTTP 400 Bad Request, or journaled JSON error/response types. This allows for consistent handling of both successful and error responses across all prompt provider handlers that implement the OpenAICompatiblePassthroughProtocol.

alias of ChatCompletion | SmarterHttpResponseForbidden | SmarterHttpResponseNotFound | SmarterHttpResponseBadRequest | SmarterJournaledJsonErrorResponse | SmarterJournaledJsonResponse

class smarter.apps.provider.services.text_completion.lib.protocols.OpenAICompatiblePassthroughProtocol(*args, **kwargs)[source]

Bases: Protocol

A Protocol for OpenAI compatible passthrough functions.

Ensures that passthrough function call signature conforms to this exact standard.

Parameters:
  • request (Request) – The DRF request object.

  • user_profile (UserProfile) – The user profile making the request.

  • data (dict[str, Any]) – The OpenAI-compatible prompt completion request data.

Returns:

The response data.

Return type:

OpenAICompatibleChatCompletionResponseType

__init__(*args, **kwargs)
smarter.apps.provider.services.text_completion.lib.protocols.SmarterChatCompletionResponseType

SmarterChatCompletionResponseType is a type alias that defines the expected.

return type for Smarter prompt provider handler functions. It can be either a dictionary (representing a successful response) or one of several specific error response types, including HTTP 403 Forbidden, HTTP 404 Not Found, HTTP 400 Bad Request, or journaled JSON error/response types. This allows for consistent handling of both successful and error responses across all prompt provider handlers that implement the SmarterChatHandlerProtocol.

alias of dict[str, Any] | SmarterHttpResponseForbidden | SmarterHttpResponseNotFound | SmarterHttpResponseBadRequest | SmarterJournaledJsonErrorResponse | SmarterJournaledJsonResponse

class smarter.apps.provider.services.text_completion.lib.protocols.SmarterChatHandlerProtocol(*args, **kwargs)[source]

Bases: Protocol

A fixed Protocol for all Smarter prompt provider handler functions.

Ensures that handler function call signature conforms to this exact standard.

Parameters:
  • user_profile (UserProfile) – The user profile making the request.

  • prompt (Prompt) – The prompt object.

  • data (Union[dict[str, Any], list]) – The Smarter prompt API request data.

  • plugins (Optional[List[PluginBase]]) – Optional list of plugins to use.

  • functions (Optional[list[str]]) – Optional list of function names to use.

Returns:

The response data.

Return type:

Union[dict[str, Any], list]

__init__(*args, **kwargs)