Online Processing

This guide demonstrates how to use Curator for online processing by generating diverse topics for poems and composing poems based on these topics. We'll focus on key parameters to manage rate limits effectively, ensuring smooth operation with LLMs.

Prerequisites

  • Python 3.10+

  • Curator: Install via pip install bespokelabs-curator

  • Access to an LLM provider (e.g., OpenAI or an equivalent API)

Steps

1. Define the Response Formats

Code Example:

from typing import List
from pydantic import BaseModel, Field

class Topics(BaseModel):
    """A list of topics."""
    topics_list: List[str] = Field(description="A list of topics.")

class Poems(BaseModel):
    """A list of poems."""
    poems_list: List[str] = Field(description="A list of poems.")

2. Create a Muse

Define a subclass of curator.LLM to generate a list of topics for our poems.

Code Example:


3. Create a Poet

Define another subclass of curator.LLM to create poems based on the generated topics.

Code Example:


Example Output


Online Processing Configuration

Curator provides several configuration parameters to better control your API usage policies and improve efficiency.

1. max_requests_per_minute

Definition: The maximum number of API requests allowed per minute.

  • Use Case: Controls the frequency of requests to prevent exceeding API quotas.

  • Example: Setting this to 60 ensures only 60 requests are sent per minute.

Example:

Note: Retries will also count under the limit set.

2. max_tokens_per_minute

Definition: The maximum number of tokens allowed to be processed per minute.

  • Use Case: Defines contraint on maximum usable tokens in a minute.

  • Example: Setting this to 30,000 ensures token limits are respected for responses.

Example:

Note: Token limit will be counted including input and output tokens.

3. seconds_to_pause_on_rate_limit

Definition: The duration (in seconds) to pause when a rate limit is hit.

  • Use Case: Automatically waits before retrying, ensuring compliance with API limits.

  • Example: Setting this to 60 pauses the processing for one minute if a rate limit error occurs.

Example:

Last updated