API Reference

This page contains the complete API reference for LLMize.

Core Module

no-index:

LLMize is a Python package that uses Large Language Models (LLMs) for multipurpose, numerical optimization tasks.

class llmize.OPRO(problem_text=None, obj_func=None, llm_model=None, api_key=None)[source]

Bases: Optimizer

No-index:

OPRO optimizer for optimizing tasks using a specified LLM model.

This class inherits from the Optimizer class and allows configuration of various parameters related to the optimization process.

Parameters:
  • llm_model (str) – The name of the LLM model to use (default from config).

  • api_key (str) – The API key for accessing the model (default: None).

  • num_steps (int) – The number of optimization steps (default: 50).

  • batch_size (int) – The batch size used for optimization (default: 5).

__init__(problem_text=None, obj_func=None, llm_model=None, api_key=None)[source]

Initialize the OPRO optimizer with the provided configuration. Inherits from Optimizer.

Parameters:
  • llm_model (str) – The name of the LLM model to use.

  • api_key (str) – The API key for accessing the model.

  • num_steps (int) – The number of optimization steps.

  • batch_size (int) – The batch size used for optimization.

meta_prompt(batch_size, example_pairs, optimization_type='maximize')[source]

Generate a prompt for the LLM model to generate new solutions. Parameters: - batch_size (int): Number of new solutions to generate. - example_pairs (str): Example solutions and scores. - optimization_type (str): “maximize” or “minimize” (default: “maximize”).

Returns: - text: A formatted prompt structure.

optimize(init_samples=None, init_scores=None, num_steps=None, batch_size=None, temperature=None, callbacks=None, verbose=1, optimization_type='maximize', parallel_n_jobs=None)[source]

Run the OPRO optimization algorithm.

Parameters: - init_samples (list): A list of initial solutions. - init_scores (list): A list of initial scores corresponding to init_samples. - num_steps (int): The number of optimization steps (default from config). - batch_size (int): The number of new solutions to generate at each step (default from config). - temperature (float): The temperature for the LLM model (default from config). - callbacks (list): A list of callback functions to be triggered at the end of each step. - optimization_type (str): “maximize” or “minimize” (default: “maximize”). - parallel_n_jobs (int): Number of parallel jobs for evaluation (default from config).

Returns: - results (OptimizationResult): An object containing the optimization results.

class llmize.ADOPRO(problem_text=None, obj_func=None, llm_model=None, api_key=None)[source]

Bases: Optimizer

No-index:

ADOPRO optimizer for optimizing tasks using a specified LLM model.

This class inherits from the Optimizer class and allows configuration of various parameters related to the optimization process.

Parameters:
  • llm_model (str) – The name of the LLM model to use (default from config).

  • api_key (str) – The API key for accessing the model (default: None).

  • num_steps (int) – The number of optimization steps (default: 50).

  • batch_size (int) – The batch size used for optimization (default: 5).

__init__(problem_text=None, obj_func=None, llm_model=None, api_key=None)[source]

Initialize the ADOPRO optimizer with the provided configuration. Inherits from Optimizer.

Parameters:
  • llm_model (str) – The name of the LLM model to use.

  • api_key (str) – The API key for accessing the model.

  • num_steps (int) – The number of optimization steps.

  • batch_size (int) – The batch size used for optimization.

meta_prompt(batch_size, example_pairs, optimization_type='maximize')[source]

Generate a prompt for the LLM model to generate new solutions. Parameters: - batch_size (int): Number of new solutions to generate. - example_pairs (str): Example solutions and scores. - optimization_type (str): “maximize” or “minimize” (default: “maximize”).

Returns: - text: A formatted prompt structure.

optimize(init_samples=None, init_scores=None, num_steps=None, batch_size=None, temperature=None, callbacks=None, verbose=1, optimization_type='maximize', parallel_n_jobs=None)[source]

Run the ADOPRO optimization algorithm.

Parameters: - init_samples (list): A list of initial solutions. - init_scores (list): A list of initial scores corresponding to init_samples. - num_steps (int): The number of optimization steps (default: 50). - batch_size (int): The number of new solutions to generate at each step (default: 5). - temperature (float): The temperature for the LLM model (default: 1.0). - callbacks (list): A list of callback functions to be triggered at the end of each step. - optimization_type (str): “maximize” or “minimize” (default: “maximize”).

Returns: - results (OptimizationResult): An object containing the optimization results.

class llmize.HLMEA(problem_text=None, obj_func=None, llm_model=None, api_key=None)[source]

Bases: Optimizer

No-index:

HLMEA optimizer for optimizing tasks using a specified LLM model.

This class inherits from the Optimizer class and allows configuration of various parameters related to the optimization process.

Parameters:
  • llm_model (str) – The name of the LLM model to use (default from config).

  • api_key (str) – The API key for accessing the model (default: None).

  • num_steps (int) – The number of optimization steps (default: 50).

  • batch_size (int) – The batch size used for optimization (default: 5).

__init__(problem_text=None, obj_func=None, llm_model=None, api_key=None)[source]

Initialize the HLMEA optimizer with the provided configuration. Inherits from Optimizer.

Parameters:
  • llm_model (str) – The name of the LLM model to use.

  • api_key (str) – The API key for accessing the model.

  • num_steps (int) – The number of optimization steps.

  • batch_size (int) – The batch size used for optimization.

meta_prompt(batch_size, example_pairs, optimization_type='maximize', hp_text='The solutions below are generated randomly.')[source]

Generate a prompt for the LLM model to generate new solutions. Parameters: - batch_size (int): Number of new solutions to generate. - example_pairs (str): Example solutions and scores. - optimization_type (str): “maximize” or “minimize” (default: “maximize”).

Returns: - text: A formatted prompt structure.

optimize(init_samples=None, init_scores=None, num_steps=None, batch_size=None, temperature=None, callbacks=None, verbose=1, optimization_type='maximize', parallel_n_jobs=None)[source]

Run the HLMEA optimization algorithm.

Parameters: - init_samples (list): A list of initial solutions. - init_scores (list): A list of initial scores corresponding to init_samples. - num_steps (int): The number of optimization steps (default: 50). - batch_size (int): The number of new solutions to generate at each step (default: 5). - temperature (float): The temperature for the LLM model (default: 1.0). - callbacks (list): A list of callback functions to be triggered at the end of each step. - optimization_type (str): “maximize” or “minimize” (default: “maximize”).

Returns: - results (OptimizationResult): An object containing the optimization results.

class llmize.HLMSA(problem_text=None, obj_func=None, llm_model=None, api_key=None)[source]

Bases: Optimizer

No-index:

HLMSA: Hyper-heuristic LLM-driven Simulated Annealing HLMSA optimizer for optimizing tasks using a specified LLM model.

This class inherits from the Optimizer class and allows configuration of various parameters related to the optimization process.

Parameters:
  • llm_model (str) – The name of the LLM model to use (default from config).

  • api_key (str) – The API key for accessing the model (default: None).

  • num_steps (int) – The number of optimization steps (default: 50).

  • batch_size (int) – The batch size used for optimization (default: 5).

__init__(problem_text=None, obj_func=None, llm_model=None, api_key=None)[source]

Initialize the HLMSA optimizer with the provided configuration. Inherits from Optimizer.

Parameters:
  • llm_model (str) – The name of the LLM model to use.

  • api_key (str) – The API key for accessing the model.

  • num_steps (int) – The number of optimization steps.

  • batch_size (int) – The batch size used for optimization.

meta_prompt(batch_size, example_pairs, optimization_type='maximize', hp_text='The solutions below are generated randomly.')[source]

Generate a prompt for the LLM model to generate new solutions using Simulated Annealing. Parameters: - batch_size (int): Number of new solutions to generate. - example_pairs (str): Example solutions and scores. - optimization_type (str): “maximize” or “minimize” (default: “maximize”).

Returns: - text: A formatted prompt structure.

optimize(init_samples=None, init_scores=None, num_steps=None, batch_size=None, temperature=None, callbacks=None, verbose=1, optimization_type='maximize', parallel_n_jobs=None)[source]

Run the HLMSA optimization algorithm.

Parameters: - init_samples (list): A list of initial solutions. - init_scores (list): A list of initial scores corresponding to init_samples. - num_steps (int): The number of optimization steps (default: 50). - batch_size (int): The number of new solutions to generate at each step (default: 5). - temperature (float): The temperature for the LLM model (default: 1.0). - callbacks (list): A list of callback functions to be triggered at the end of each step. - optimization_type (str): “maximize” or “minimize” (default: “maximize”).

Returns: - results (OptimizationResult): An object containing the optimization results.

Optimizers

Utils

Submodules