pyflink.dataframe.ai.llm.LLMAccessor.ai_translate#
- LLMAccessor.ai_translate(input_col: Union[str, Expression], source_lang: str, target_lang: str, *, provider: Optional[str] = None, model: Optional[str] = None, cache_table: Optional[str] = None, cache_key: Optional[Union[str, List[str]]] = None, config: Optional[Dict[str, str]] = None, **kwargs) DataFrame[source]#
Translate text from one language to another.
- Parameters
input_col – Column name (str) or Expression for the input text.
source_lang – Source language code (e.g.
"zh","en","auto"for auto-detection). Supported:auto,zh,en,ja,ko,fr,de,es,ru,ar,pt.target_lang – Target language code (cannot be
"auto").provider – Registered model provider lookup name. Uses default if not specified. If no provider is configured,
modelis treated as a catalog model name.model – Model name.
cache_table – Optional cache table identifier.
cache_key – Optional cache key column name or list of column names.
config – Optional dict of runtime prediction options.
**kwargs –
Per-call overrides for the selected DataFrame model provider’s constructor parameters. Overrides are applied only when the call uses a configured provider.
Note: This function uses its own task-specific prompt. Provider configurations for the system prompt, such as
system_promptonOpenAICompatProviderandDashScopeProvider, do not take effect for this call.
- Returns
A new DataFrame with columns appended –
translated_text(STRING): the translated text.detected_language(STRING): detected source language code.
Examples
Simple invocation:
- ::
>>> import pyflink.dataframe as pf >>> pf.set_model_provider(pf.OpenAICompatProvider( ... task="chat/completions")) >>> df = pf.from_dict({"text": ["你好"]}) >>> df.llm.ai_translate("text", "zh", "en", model="qwen3.6-plus")
With cache:
- ::
>>> df.llm.ai_translate( ... "text", "zh", "en", model="qwen3.6-plus", ... cache_table="`fluss-catalog`.default_database.translate_cache", ... cache_key="text")
Using runtime config supported by
pyflink.dataframe.OpenAICompatProvider:- ::
>>> df.llm.ai_translate( ... "text", "zh", "en", model="qwen3.6-plus", ... config={"max-concurrent-operations": "20"})