Passthrough Chat

This module contains passthrough views for interacting directly with the LLM.

provider backend API.

class smarter.apps.prompt.api.v1.views.passthrough.PassthroughChatViewSet(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Handle POST requests to the passthrough endpoint for direct LLM provider API access.

path: /api/v1/prompts/passthrough/{provider_name}/

This endpoint allows authenticated users to send arbitrary prompt dicts to the underlying LLM provider (such as OpenAI). The request body should be a JSON object containing any valid parameters accepted by the provider’s prompt completion API.

Parameters:
  • request (rest_framework.request.ASGIRequest) – The HTTP request object, expected to have a JSON body with prompt completion parameters.

  • args – Additional positional arguments (unused).

  • kwargs – Additional keyword arguments. May include ‘provider’ to select the LLM provider.

Returns:

A JSON response containing the provider’s prompt completion result, or an error message.

Return type:

SmarterJournaledJsonResponse | SmarterJournaledJsonErrorResponse | SmarterHttpResponseBadRequest | SmarterHttpResponseForbidden | SmarterHttpResponseNotFound

Signals:
  • chat_started: Sent before the prompt completion request is made.

  • chat_completion_request: Sent with the prompt data before calling the provider.

  • chat_completion_response: Sent after a successful response from the provider.

  • chat_finished: Sent after the prompt completion process is finished.

  • chat_response_failure: Sent if an exception occurs during the provider call.

Raises:

See also

handler: OpenAICompatiblePassthroughProtocol
post(request, *args, **kwargs)[source]

Handle POST requests to the passthrough endpoint for direct LLM.

provider API access.

Return type:

SmarterJournaledJsonResponse | SmarterJournaledJsonErrorResponse | SmarterHttpErrorResponse | SmarterHttpResponseForbidden

provider_name: str
setup(request, *args, **kwargs)[source]

Set the provider_name and handler based on the URL kwargs.

The handler can be any function that implements the OpenAICompatiblePassthroughProtocol interface.

See also

  • OpenAICompatiblePassthroughProtocol

smarter.apps.prompt.api.v1.views.passthrough.should_log(level)[source]

Check if logging should be done based on the waffle switch.