ExLLM.Gemini.Tuning (ex_llm v0.5.0)

View Source

Google Gemini Fine-tuning API implementation.

This module provides functionality for creating and managing tuned models using the Gemini API.

Summary

Functions

Deletes a tuned model.

Generates content using a tuned model.

Gets information about a specific tuned model.

Lists tuned models.

Streams content generation using a tuned model.

Waits for a tuning operation to complete.

Types

options()

@type options() :: [
  api_key: String.t(),
  config_provider: module(),
  page_size: integer(),
  page_token: String.t(),
  filter: String.t(),
  tuned_model_id: String.t(),
  update_mask: String.t(),
  timeout: integer()
]

Functions

create_tuned_model(request, opts \\ [])

@spec create_tuned_model(map(), options()) :: {:ok, map()} | {:error, term()}

Creates a tuned model.

Parameters

  • request - The tuned model creation request containing:
    • :base_model - The base model to tune (required)
    • :tuning_task - The tuning task configuration (required)
    • :display_name - Optional display name
    • :description - Optional description
    • :temperature - Optional temperature setting
    • :top_p - Optional nucleus sampling parameter
    • :top_k - Optional top-k sampling parameter
  • opts - Options including:
    • :api_key - Google API key
    • :tuned_model_id - Optional custom ID for the tuned model

Returns

  • {:ok, operation} - The long-running operation for tracking tuning progress
  • {:error, reason} - Error details

delete_tuned_model(name, opts \\ [])

@spec delete_tuned_model(String.t(), options()) :: {:ok, map()} | {:error, term()}

Deletes a tuned model.

Parameters

  • name - The resource name of the model
  • opts - Options including :api_key

Returns

  • {:ok, %{}} - Empty response on success
  • {:error, reason} - Error details

generate_content(model, request, opts \\ [])

@spec generate_content(String.t(), map(), options()) ::
  {:ok, map()} | {:error, term()}

Generates content using a tuned model.

Parameters

  • model - The tuned model name (e.g., "tunedModels/my-model")
  • request - The generation request
  • opts - Options including :api_key

Returns

  • {:ok, response} - The generation response
  • {:error, reason} - Error details

get_tuned_model(name, opts \\ [])

@spec get_tuned_model(String.t(), options()) ::
  {:ok, ExLLM.Gemini.Tuning.TunedModel.t()} | {:error, term()}

Gets information about a specific tuned model.

Parameters

  • name - The resource name of the model (e.g., "tunedModels/my-model-id")
  • opts - Options including :api_key

Returns

  • {:ok, model} - The tuned model details
  • {:error, reason} - Error details

list_tuned_models(opts \\ [])

@spec list_tuned_models(options()) ::
  {:ok, ExLLM.Gemini.Tuning.ListTunedModelsResponse.t()} | {:error, term()}

Lists tuned models.

Parameters

  • opts - Options including:
    • :api_key - Google API key
    • :page_size - Maximum number of models to return
    • :page_token - Token for pagination
    • :filter - Filter expression

Returns

  • {:ok, response} - List of tuned models
  • {:error, reason} - Error details

stream_generate_content(model, request, opts \\ [])

@spec stream_generate_content(String.t(), map(), options()) ::
  {:ok, Enumerable.t()} | {:error, term()}

Streams content generation using a tuned model.

Parameters

  • model - The tuned model name
  • request - The generation request
  • opts - Options including :api_key

Returns

  • {:ok, stream} - Stream of response chunks
  • {:error, reason} - Error details

update_tuned_model(name, update, opts \\ [])

@spec update_tuned_model(String.t(), map(), options()) ::
  {:ok, ExLLM.Gemini.Tuning.TunedModel.t()} | {:error, term()}

Updates a tuned model.

Parameters

  • name - The resource name of the model
  • update - Map of fields to update
  • opts - Options including:
    • :api_key - Google API key
    • :update_mask - Field mask specifying which fields to update

Returns

  • {:ok, model} - The updated model
  • {:error, reason} - Error details

wait_for_tuning(operation_name, opts \\ [])

@spec wait_for_tuning(String.t(), options()) ::
  {:ok, ExLLM.Gemini.Tuning.TunedModel.t()} | {:error, term()}

Waits for a tuning operation to complete.

Parameters

  • operation_name - The operation name from create_tuned_model
  • opts - Options including:
    • :api_key - Google API key
    • :timeout - Maximum time to wait in milliseconds (default: 300_000)

Returns

  • {:ok, model} - The completed tuned model
  • {:error, reason} - Error details