prompttrail.models package

Submodules

prompttrail.models.anthropic module

pydantic model prompttrail.models.anthropic.AnthropicConfig

Bases: Config

Integration configuration class for Anthropic Claude API.

Manages authentication credentials and model parameters in a centralized way.

Fields:
Validators:

field api_key: str [Required]

API key for Anthropic API.

Validated by:
  • validate_providers

field max_tokens: int | None = 1024

Maximum number of tokens to generate.

Validated by:
  • validate_providers

field model_name: str = 'claude-3-opus-latest'

Name of the model to use.

Validated by:
  • validate_providers

field temperature: float | None = 1.0

Temperature for sampling.

Validated by:
  • validate_providers

field top_k: int | None = None

Top-k value for sampling.

Validated by:
  • validate_providers

field top_p: float | None = None

Top-p value for sampling.

Validated by:
  • validate_providers

class prompttrail.models.anthropic.AnthropicMessageDict

Bases: TypedDict

content: str
role: Literal['user', 'assistant', 'system']
pydantic model prompttrail.models.anthropic.AnthropicModel

Bases: Model

Model class for Anthropic Claude API.

Fields:
field client: Anthropic | None = None
field configuration: AnthropicConfig [Required]
format_tool(tool: Tool) Dict[str, Any]

Convert tool to Anthropic format

format_tool_result(result: ToolResult) Dict[str, Any]

Format result for Anthropic API

list_models() List[str]

Return a list of available models.

validate_tools(tools: List[Tool]) None

Validate tools according to Anthropic API requirements

prompttrail.models.google module

pydantic model prompttrail.models.google.GoogleChatExample

Bases: BaseModel

Example for few-shot learning in Google API.

Fields:
field prompt: str [Required]

Example prompt.

field response: str [Required]

Example response.

pydantic model prompttrail.models.google.GoogleConfig

Bases: Config

Integration configuration class for Google API.

Manages authentication credentials and model parameters in a centralized way.

Fields:
Validators:

field api_key: str [Required]

API key for Google API.

Validated by:
  • validate_providers

field candidate_count: int | None = None

Number of candidate responses.

Validated by:
  • validate_providers

field context: str | None = None

Optional context for the model.

Validated by:
  • validate_providers

field examples: List[GoogleChatExample] | None = None

Optional few-shot learning examples.

Validated by:
  • validate_providers

field max_tokens: int | None = 1024

Maximum output tokens.

Validated by:
  • validate_providers

field model_name: str = 'models/gemini-1.5-flash'

Model name. Use list_models() to see available models.

Validated by:
  • validate_providers

field temperature: float | None = 1.0

Sampling temperature.

Validated by:
  • validate_providers

field top_k: int | None = None

Top-k sampling threshold.

Validated by:
  • validate_providers

field top_p: float | None = None

Nucleus sampling threshold.

Validated by:
  • validate_providers

pydantic model prompttrail.models.google.GoogleModel

Bases: Model

Google API model implementation.

Fields:
field configuration: GoogleConfig [Required]
list_models() List[str]

Get list of available model names.

Returns:

List of model names

validate_session(session: Session, is_async: bool = False) None

Validate session for Google API requirements.

Parameters:
  • session – Session to validate

  • is_async – Whether validation is for async operation

Raises:

ParameterValidationError – If session is invalid

prompttrail.models.openai module

pydantic model prompttrail.models.openai.OpenAIConfig

Bases: Config

Integration configuration class for OpenAI Chat API.

Manages authentication credentials and model parameters in a centralized way.

Fields:
Validators:

field api_base: str | None = None

Base URL for OpenAI API.

Validated by:
  • validate_providers

field api_key: str [Required]

API key for OpenAI API.

Validated by:
  • validate_providers

field api_version: str | None = None

API version for OpenAI API.

Validated by:
  • validate_providers

field max_tokens: int | None = 100

Maximum number of tokens to generate.

Validated by:
  • validate_providers

field model_name: str = 'gpt-4o-mini'

Name of the model to use.

Validated by:
  • validate_providers

field organization_id: str | None = None

Organization ID for OpenAI API.

Validated by:
  • validate_providers

field temperature: float | None = 1.0

Temperature for sampling.

Validated by:
  • validate_providers

pydantic model prompttrail.models.openai.OpenAIModel

Bases: Model

Model class for OpenAI Chat API.

Fields:
field configuration: OpenAIConfig [Required]
format_tool(tool: Tool) Dict[str, Any]

Convert tool to OpenAI format.

list_models() List[str]

Return a list of available models.

prompttrail.models.transformers module

pydantic model prompttrail.models.transformers.TransformersConfig

Bases: Config

Integration configuration class for Transformers models.

Manages authentication credentials and model parameters in a centralized way.

Fields:
Validators:

field device: str | None = None

Device to run model on (e.g. ‘cpu’, ‘cuda’).

Validated by:
  • validate_providers

field max_tokens: int | None = 1024

Maximum number of tokens to generate.

Validated by:
  • validate_providers

field model_name: str [Required]

Name of the model to use.

Validated by:
  • validate_providers

field repetition_penalty: float | None = 1.0

Higher values penalize repeated tokens more strongly.

Validated by:
  • validate_providers

field temperature: float | None = 1.0

Sampling temperature between 0 and 1.

Validated by:
  • validate_providers

field top_k: int | None = None

Top-k sampling.

Validated by:
  • validate_providers

field top_p: float | None = 1.0

Nucleus sampling probability.

Validated by:
  • validate_providers

pydantic model prompttrail.models.transformers.TransformersModel

Bases: Model

Model class for running transformer models locally.

Parameters:
  • configuration – Model configuration.

  • model – Pre-trained transformer model.

  • tokenizer – Tokenizer for the model.

Fields:
field model: AutoModelForCausalLM | None = None
field tokenizer: AutoTokenizer | None = None
__init__(configuration: TransformersConfig, model: AutoModelForCausalLM, tokenizer: AutoTokenizer)

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

before_send(session: Session | None, is_async: bool) Session | None

Perform pre-send processing.

validate_session(session: Session, is_async: bool = False) None

Validate session for transformer models.

Module contents

Module for various LLM models and providers.

This module contains model abstractions for using different LLM providers: - OpenAI GPT models - Anthropic Claude - Google PaLM - Local models via Transformers

Each provider has its own submodule with Configuration, Model and Parameter classes.