Create LLMClient Request

Celery tasks for the llmclient app.

This module defines Celery tasks related to llmclient request handling, including the creation of llmclient request records.

Main Tasks

  • create_llmclient_request(llmclient_id, request_data):

    Creates a LLMClientRequests record for a given llmclient and request data. Handles pre- and post-create signals, logging, and error retries.

Signals

  • pre_create_llmclient_request: Sent before a LLMClientRequests record is created.

  • post_create_llmclient_request: Sent after a LLMClientRequests record is created.

Configuration

Celery task behavior (retries, backoff, queue) is controlled by smarter_settings.

Logging

Task execution and request data are logged using the smarter logging library, with waffle switches for task and llmclient logging.

Usage

Import this module and call the Celery task as needed to asynchronously create llmclient request records:

create_llmclient_request.delay(llmclient_id, request_data)

raises LLMClient.DoesNotExist:

If the LLMClient with the given ID does not exist.

raises Exception:

Any exception during task execution will trigger a retry according to Celery settings.

smarter.apps.llmclient.tasks.create_llmclient_request.create_llmclient_request(llmclient_id, request_data)

Create a LLMClient request record in the database as a Celery task.

This task performs the following steps: 1. Sends a pre-create signal for the llmclient request. 2. Logs the incoming request data. 3. Retrieves the LLMClient instance by ID. 4. Extracts the session key from the request data. 5. Creates a LLMClientRequests record with the llmclient, request data, and session key. 6. Sends a post-create signal for the llmclient request.

Parameters:
  • llmclient_id (int) – The primary key of the LLMClient instance for which the request is being created.

  • request_data (dict) – The data associated with the llmclient request. Should include all relevant request fields.

  • Signals

  • -------

  • pre_create_llmclient_request (django.dispatch.Signal) – Sent before the LLMClientRequests record is created.

  • post_create_llmclient_request (django.dispatch.Signal) – Sent after the LLMClientRequests record is created.

Raises:
  • LLMClient.DoesNotExist – If the LLMClient with the given ID does not exist.

  • Exception – Any exception raised during the creation process will trigger a retry according to Celery settings.