LLM Client

LLM client wrapper for unified access to various language models.

This module provides a unified interface for interacting with different LLM providers (OpenAI, Anthropic, Ollama, etc.) via the LiteLLM library.

class spacylize.llm.LLMClient(model, api_key=None, api_base=None, max_tokens=1024)[source]

Bases: object

Client for interacting with various LLM providers via LiteLLM.

Supports OpenAI, Anthropic, Ollama, and other LiteLLM-compatible providers.

Parameters:
  • model (str)

  • api_key (str | None)

  • api_base (str | None)

  • max_tokens (int)

model

The model identifier (e.g., ‘gpt-4o-mini’, ‘anthropic/claude-opus-4-5’).

api_key

API key for authentication.

api_base

Optional custom API base URL for local or custom deployments.

max_tokens

Maximum number of tokens to generate.

__init__(model, api_key=None, api_base=None, max_tokens=1024)[source]

Initialize the LLM client.

Parameters:
  • model (str) – Model identifier for LiteLLM (e.g., ‘gpt-4o-mini’).

  • api_key (str | None) – API key for the LLM provider. Defaults to None.

  • api_base (str | None) – Custom API base URL for local or custom deployments.

  • max_tokens (int) – Maximum number of tokens to generate. Defaults to 1024.

generate(prompt, system_prompt=None)[source]

Generate text using the configured LLM.

Parameters:
  • prompt (str) – The user prompt to send to the LLM.

  • system_prompt (str | None) – Optional system prompt to set context or instructions.

Returns:

The generated text response from the LLM.

Return type:

str