Skip to content

v2.7.0 - Provider-Specific Environment Variables for OpenAI-Compatible Endpoints

Choose a tag to compare

@lfnovo lfnovo released this 19 Oct 02:06
9ec9295

What's New

Provider-Specific Environment Variables for OpenAI-Compatible Endpoints

This release adds support for provider-specific environment variables for all OpenAI-compatible providers, allowing you to configure different endpoints for different AI capabilities (LLM, Embedding, STT, TTS) without code changes.

New Environment Variables

You can now use provider-specific environment variables that take precedence over the generic ones:

Language Models:

  • OPENAI_COMPATIBLE_BASE_URL_LLM
  • OPENAI_COMPATIBLE_API_KEY_LLM

Embeddings:

  • OPENAI_COMPATIBLE_BASE_URL_EMBEDDING
  • OPENAI_COMPATIBLE_API_KEY_EMBEDDING

Speech-to-Text:

  • OPENAI_COMPATIBLE_BASE_URL_STT
  • OPENAI_COMPATIBLE_API_KEY_STT

Text-to-Speech:

  • OPENAI_COMPATIBLE_BASE_URL_TTS
  • OPENAI_COMPATIBLE_API_KEY_TTS

Configuration Precedence

The configuration precedence order is now:

  1. Direct parameters (base_url=, api_key=)
  2. Config dictionary (config={"base_url": ...})
  3. Provider-specific environment variables ← NEW
  4. Generic environment variables
  5. Default values

Example Usage

from esperanto import AIFactory

# Use different endpoints for different capabilities
# Set environment variables:
# OPENAI_COMPATIBLE_BASE_URL_LLM=http://localhost:1234/v1
# OPENAI_COMPATIBLE_BASE_URL_EMBEDDING=http://localhost:8080/v1

# Language model uses localhost:1234
llm = AIFactory.create_language("openai-compatible", "llama-3-8b")

# Embedding model uses localhost:8080
embedder = AIFactory.create_embedding("openai-compatible", "nomic-embed-text")

Backward Compatibility

✅ This is a non-breaking change. All existing configurations using generic environment variables (OPENAI_COMPATIBLE_BASE_URL, OPENAI_COMPATIBLE_API_KEY) continue to work exactly as before.

Bug Fixes

  • Improved consistency in error messages across all OpenAI-compatible providers
  • Removed unnecessary warning logs for cleaner output

Documentation

  • Updated README with comprehensive environment variable configuration guide
  • Added examples to .env.example
  • Added 20 new tests to validate provider-specific environment variable behavior

Full Changelog: Improved flexibility for users with diverse AI infrastructure setups.