xpark.dataset.TextGenerate#
- class xpark.dataset.TextGenerate(*, base_url: str, model: str, api_key: str = 'NOT_SET', max_qps: int | None = None, max_concurrency: int | None = None, max_retries: int = 0, fallback_response: str | None = None, fallback_on_request_error: bool = True, hint: str | list[str] | None = None, **kwargs: dict[str, Any])#
TextGenerate processor generates content based on the input parameters. generate by llm model.
- Parameters:
base_url – The base URL of the LLM server.
model – The request model name.
api_key – The request API key.
max_qps – The maximum query-per-second rate for remote LLM requests.
max_concurrency – The maximum number of in-flight remote LLM requests allowed concurrently.
max_retries – The maximum number of retries per request in the event of failures. We retry with exponential backoff upto this specific maximum retries.
fallback_response – The response value to return when the LLM returns an empty response. If set to None, a
ValueErrorwill be raised instead.fallback_on_request_error – If
Trueandfallback_responseis set, request-time errors (e.g. content-safety rejection, single-record 4xx) raised by the underlying LLM client are also translated intofallback_responseinstead of aborting the whole batch. Defaults toTrue; set it toFalseto let infrastructure failures surface to the caller instead.hint – Optional extra instructions or constraints to guide the model (e.g. target length, tone, audience, style). Accepts either a single string or a list of strings, where each item is one hint written in plain text. Passing a list is recommended — use one string per hint.
**kwargs – Keyword arguments to pass to the openai.AsyncClient.chat.completions.create API.
Examples
from xpark.dataset.expressions import col from xpark.dataset import TextGenerate, from_items ds = from_items([""]) ds = ds.with_column( "generated_text", TextGenerate( model="deepseek-v3-0324", base_url=os.getenv("LLM_ENDPOINT"), api_key=os.getenv("LLM_API_KEY"), ) .options(num_workers={"IO": 1}, batch_size=1) .with_column(col("item")), ) print(ds.take_all())
Methods
__call__(texts)Call self as a function.
options(**kwargs)with_column(texts)- __call__(texts: pa.ChunkedArray) pa.Array#
Call self as a function.
- options(**kwargs: Unpack[ExprUDFOptions]) Self#
- with_column(texts: pa.ChunkedArray) pa.Array#