[ 
https://issues.apache.org/jira/browse/FLINK-40572?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Xiqian Yu resolved FLINK-40572.
-------------------------------
    Fix Version/s: cdc-3.7.0
         Assignee: Mao Jiayi
       Resolution: Fixed

> Support dynamic model selection for AI functions
> ------------------------------------------------
>
>                 Key: FLINK-40572
>                 URL: https://issues.apache.org/jira/browse/FLINK-40572
>             Project: Flink
>          Issue Type: Improvement
>          Components: Flink CDC
>            Reporter: Mao Jiayi
>            Assignee: Mao Jiayi
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: cdc-3.7.0
>
>
> AI functions currently require the model argument to be a compile-time string 
> literal:
> {code:sql}
> AI_COMPLETE('default_model', content, prompt)
> {code}
> During expression compilation, {{TransformParser}} resolves and validates the 
> model name, while {{JaninoCompiler}} rewrites the string literal into an 
> injected {{AiModelClient}} parameter.
> This introduces AI-specific handling in the expression compiler and prevents 
> dynamic model selection, for example:
> {code:sql}
> AI_COMPLETE(
>     IF(priority = 'high', 'powerful_model', 'cheap_model'),
>     content,
>     prompt
> )
> {code}
> The model argument should instead be evaluated as a regular string 
> expression. The corresponding {{AiModelClient}} should be resolved at 
> evaluation time, with model existence and capability checks performed by 
> {{impl.AiFunctions}}.
> The change should apply to the complete AI function family introduced by PR 
> #4512 and PR #4520, including text generation, text embedding, image 
> completion, and image embedding functions.
> h3. Expected changes
> * Allow the model argument to be any valid string expression.
> * Resolve the evaluated model name when processing a {{DataChangeEvent}}.
> * Move model existence and capability validation to {{AiFunctions}}.
> * Remove the compile-time literal restriction and model-argument rewriting 
> from {{JaninoCompiler}}.
> * Avoid injecting every model client as a separately named Janino parameter.
> * Preserve support for literal model names.
> * Preserve the existing {{NULL}} input short-circuit behavior.
> * Preserve precedence for user-defined functions with the same names.
> * Provide clear runtime errors for unknown models and incompatible model 
> capabilities.
> After the change, both static and dynamic model selection should be supported:
> {code:sql}
> AI_COMPLETE('default_model', content, prompt)
> {code}
> {code:sql}
> AI_COMPLETE(
>     IF(priority = 'high', 'powerful_model', 'cheap_model'),
>     content,
>     prompt
> )
> {code}
> This is a follow-up to the review discussion in PR #4520.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to