cancel
Showing results for 
Search instead for 
Did you mean: 
Generative AI
Explore discussions on generative artificial intelligence techniques and applications within the Databricks Community. Share ideas, challenges, and breakthroughs in this cutting-edge field.
cancel
Showing results for 
Search instead for 
Did you mean: 

Custom LLM Function similar to Databricks built in AI functions

neha89
New Contributor II

Hi Team,

I am new to Databricks and working on Gen AI requirements.

Task - Build custom prompt with set of instructions to classify incident e.g. False Positive or True Positive. Input will be columns in Delta Table

Can I build custom LLM function with custom prompt and invoke it similar to built in AI function as SQL query. Or I should register function as model serving endpoint and then use this endpoint to apply on each record in Delta Table. Kindly provide suggestions

1 ACCEPTED SOLUTION

Accepted Solutions

Alberto_Umana
Databricks Employee
Databricks Employee

Hi @neha89 -

You can use below approach:

Databricks provides AI Functions that allow invoking large language models directly within SQL queries. Here’s how this approach works:

  • Define a Custom AI Function: You can define a SQL function using ai_query or similar built-in AI capabilities, which directly interact with a generative AI model (e.g., Databricks Foundation Models or OpenAI models).
  • Prompt Engineering: Build your classification prompt that receives Delta Table columns as input and generates the required classification (False Positive/True Positive).
  • Integrating with Delta Table: Use this SQL function to compute the classification and update the Delta Table
    1. Create an AI Function using ai_query.
    2. Apply the function in an UPDATE or SELECT statement for your Delta Table.
    3. Execute through standard SQL pipelines.

View solution in original post

3 REPLIES 3

Alberto_Umana
Databricks Employee
Databricks Employee

Hi @neha89 -

You can use below approach:

Databricks provides AI Functions that allow invoking large language models directly within SQL queries. Here’s how this approach works:

  • Define a Custom AI Function: You can define a SQL function using ai_query or similar built-in AI capabilities, which directly interact with a generative AI model (e.g., Databricks Foundation Models or OpenAI models).
  • Prompt Engineering: Build your classification prompt that receives Delta Table columns as input and generates the required classification (False Positive/True Positive).
  • Integrating with Delta Table: Use this SQL function to compute the classification and update the Delta Table
    1. Create an AI Function using ai_query.
    2. Apply the function in an UPDATE or SELECT statement for your Delta Table.
    3. Execute through standard SQL pipelines.

neha89
New Contributor II

Thank you @Alberto_Umana for explanation. This is really helpful!

Alberto_Umana
Databricks Employee
Databricks Employee

No problem, if you have any other question, let me know!