Is it the knime limitation, that the "python script" can not call LLM api ?

I am again got stucked with “Knime Setback” of the Capability. May be it is my own problem, the fact is I placed a LLM api call within a pyhton script, found that the “Knime python script” is not capable to call any LLM api call like from open AI or Gemini. Like I needed to categorise to some text column to reduce the vaiablity some text column using Gemini api call. I was able to do that in my Jupyter, but not able to do that in python script.

For your kind inof I am a heavy user of knime python script to work on text column, I often use nltk to categorise column, But I found that LLM api call are best effective for realistic output. I think emmersive/embedded LLM technology is better thorugh any node (Not Chat style), is there any option there, I am not sure ?

Here is portion of the code :


GEMINI AI SETUP

#=============================================
def setup_gemini():
genai.configure(api_key=GEMINI_API_KEY)
return genai.GenerativeModel(‘gemini-pro’)

#=============================================

TEXT ANALYSIS FUNCTIONS

#=============================================
def create_categorization_prompt(column_name, unique_values):
return f"“”
Analyze these unique values from the column ‘{column_name}’ and create 3-5 meaningful categories:

Values: {unique_values}

Rules:
1. Create broad, meaningful categories
2. Each category should be clear and distinct
3. Use simple, consistent naming
4. Categories should be relevant to healthcare/medical research

Return only the category mapping in this format:
value1|category1
value2|category1
value3|category2
etc.
"""

def get_categories_from_gemini(model, column_name, unique_values):
try:
prompt = create_categorization_prompt(column_name, unique_values)
response = model.generate_content(prompt)

    categories = {}
    for line in response.text.strip().split('\n'):
        if '|' in line:
            value, category = line.split('|', 1)
            categories[value.strip()] = category.strip()

    return categories
except Exception as e:
    print(f"Error getting categories for {column_name}: {str(e)}")
    return None

@knime200087 is there an option to use REST-API (like with ollama).

Also maybe you could format the python code in a more readable way.