>>> ######################################################################################
>>> ## Define the models to use
>>> ##
>>> import localllm
>>> from localllm import localllm_download_model, textmodel_gepa_classify
>>> ######################################################################################
>>> ## GEPA requires a reflection model and a model which for which the module is tuned.
>>> ## Make sure the reflection models is defined first as the module
>>> ## will use the default lm which is set lastly to tune the instructions
>>> ## Example below: reflection model running in LMStudio
>>> opts = dict(api_base = "http://localhost:1234/v1", api_key = "none", model_type = "chat", provider = "openai", cache = True, response_format = dict(type = "text"))
>>> reflection_lm = localllm.connect("openai/gemma-4-E4b-it-GGUF", opts)
>>> ##
>>> ## Example connecting to a local LLM running on LMStudio or an API running e.g. on your computer
>>> ##
>>> opts = dict(api_base = "http://localhost:1234/v1", api_key = "none", model_type = "chat", provider = "openai", cache = True, response_format = dict(type = "text"))
>>> lm = localllm.connect("openai/gemma-4-E2B-it-GGUF", opts)
>>> ##
>>> ## Example to connect to a local llm directly in Python
>>> ##
>>> lm = localllm.connect("localllm/Qwen3-4B-Instruct-Q4_K_M")
>>> opts = dict(n_ctx = 512, n_gpu_layers = 0, n_threads = 1, flash_attn = False, swa_full = False, verbose = False)
>>> lm = localllm.connect("localllm/gemma-3-270m-it-Q8_0", opts)
...
>>>
>>> ######################################################################################
>>> ## Get data, define target to predict
>>> ##
>>> import pandas as pd
>>> from localllm.data import data_be_parliament
>>> from localllm.utilities.converters import tif
>>> be = data_be_parliament()
>>> be = pd.DataFrame.from_records(be)
>>> be = be[be["question_theme_main"].isin(["VERVOERBELEID", "OPENBARE VEILIGHEID"])]
>>> be = tif(be, docid_field = "doc_id", text_field = "question", target_field = "question_theme_main")
>>> list(be.columns)
['doc_id', 'text', 'target']
>>> dataset = be.sample(100)
>>>
>>> ######################################################################################
>>> ## Auto-tune the prompt using GEPA
>>> ##
>>> from s3generics import summary, predict
>>> model = textmodel_gepa_classify(x = dataset["text"], y = dataset["target"], auto = None, max_metric_calls = 1, reflection_minibatch_size = 3, test_size = 0, trace = True)
...
>>> score = predict(model, ["We gaan met de trein op reis naar Blankenberge", "De politie is met man en macht op straat"])
>>> ## A more realistic example
>>> model = textmodel_gepa_classify(x = dataset["text"], y = dataset["target"], auto = "light", test_size = 10)
>>> score = predict(model, ["We gaan met de trein op reis naar Blankenberge", "De politie is met man en macht op straat"])
>>> score
['VERVOERBELEID', 'OPENBARE VEILIGHEID']
>>> summary(model)
Method : Classification (DSPy GEPA): predict
GEPA auto : None
Classes : ['OPENBARE VEILIGHEID', 'VERVOERBELEID']
...