CREATE EXTENSION IF NOT EXISTS google_ml_integration; ALTER SYSTEM SET google_ml_integration.request_timeout_in_seconds = 600; SELECT pg_reload_conf(); CREATE OR REPLACE FUNCTION google_ml.ollama_llm_input_transform( model_id character varying, prompt text, generation_config json, system_instructions json ) RETURNS json AS $$ SELECT json_build_object( ‘model’, CASE model_id WHEN ‘gemma4_llm’ THEN ‘gemma4:12b’ WHEN ‘qwen3_8_llm’ THEN ‘qwen3.8’ END, ‘messages’, json_build_array( json_build_object(‘role’, ‘system’, ‘content’, COALESCE(system_instructions->’systemInstruction’->’parts’->0->>’text’, ‘You are a helpful assistant.’)), json_build_object(‘role’, ‘user’, ‘content’, prompt) ) ); $$ LANGUAGE sql; CREATE OR REPLACE FUNCTION google_ml.ollama_llm_output_transform( model_id character varying, response json ) RETURNS text AS $$ SELECT trim(regexp_replace( response->’choices’->0->’message’->>’content’, ‘.*?’, ”, ‘s’)); $$ LANGUAGE sql; CALL google_ml.create_model( model_id => ‘gemma4_llm’, — and/or ‘qwen3_8_llm’, model_request_url => ‘http://ollama-service.ai-demo.svc.cluster.local:11434/v1/chat/completions’, model_provider => ‘custom’, model_type => ‘llm’, model_in_transform_fn => ‘google_ml.ollama_llm_input_transform’, model_out_transform_fn => ‘google_ml.ollama_llm_output_transform’ );






