cuery.task ========== .. py:module:: cuery.task .. autoapi-nested-parse:: Task and Chain classes encapsulating the execution of prompts over contexts. Attributes ---------- .. autoapisummary:: cuery.task.AnyCfg Classes ------- .. autoapisummary:: cuery.task.ErrorLogger cuery.task.QueryLogger cuery.task.Task cuery.task.Chain Functions --------- .. autoapisummary:: cuery.task.check_model_name Module Contents --------------- .. py:data:: AnyCfg .. py:function:: check_model_name(model) Check if the model name is valid (provider/model format). .. py:class:: ErrorLogger Bases: :py:obj:`list` A simple logger to count parsing errors. .. py:method:: log(error) .. py:class:: QueryLogger Bases: :py:obj:`list` A simple logger to store query parameters. .. py:method:: log(*args, **kwargs) Log a query to the internal list. .. py:class:: Task(prompt, response, name = None, model = None, log_prompt = False, log_response = False) A task that can be executed with a prompt and a response model. Tasks can be registered by name and can be called with a context to get a response. The output is always ResponseSet that contains one Reponse for each item in the iterable context. .. py:attribute:: registry :type: dict[str, Task] .. py:attribute:: name :value: None .. py:attribute:: response .. py:attribute:: prompt .. py:attribute:: log_prompt :value: False .. py:attribute:: log_response :value: False .. py:attribute:: errors .. py:attribute:: queries .. py:method:: _select_client(model = None) .. py:method:: reset_loggers(client) Reset the error and query loggers. .. py:method:: call(context = None, model = None, **kwds) :async: Call the task with a single context item (no iteration). .. py:method:: iter(context = None, model = None, callback = None, progress_callback = None, **kwds) :async: Iterate the prompt over items in the context. This is useful when subsequent calls depend on the previous response, and you thus cannot parallelize the calls. The callback can be used to process each response as it is generated and to perform any additional actions, such as logging or updating the prompt for the next call. .. py:method:: gather(context = None, model = None, n_concurrent = 1, progress_callback = None, **kwds) :async: Gather multiple calls to the task in parallel. This is useful when the calls are independent and can be parallelized. The `n_concurrent` parameter controls how many calls can be made in parallel. .. py:method:: __call__(context = None, model = None, n_concurrent = 1, **kwds) :async: Dispatch to appropriate method (call/iter/gather) based on context and concurrency. .. py:method:: from_config(prompt, response) :classmethod: Create a Task from configuration. .. py:method:: __rich_console__(console, options) Render the task as a rich panel. .. py:class:: Chain(*tasks) Chain multiple tasks together. The output of each task is auto-converted to a DataFrame and passed to the next task as input context. The return value of the chain is the result of successively joining each task's output DataFrame with the previous one, using the corresponding prompt's variables as join keys. .. py:attribute:: tasks :value: () .. py:method:: __call__(context = None, **kwds) :async: Run the chain of tasks sequentially.