Clients
- class AsyncFFLiteLLMClient(model_string, config=None, *, api_key=None, api_base=None, api_version=None, system_instructions=None, temperature=None, max_tokens=None, fallbacks=None, retry_config=None, **kwargs)[source]
Bases:
BaseLiteLLMClient,AsyncFFAIClientBaseAsync LiteLLM-backed AI client implementing AsyncFFAIClientBase.
Key features: - Internal conversation history management - Clone pattern for parallel execution - Model string routing (e.g., “azure/mistral-small-2503”) - Retry and fallback support
- Parameters:
model_string (str) – LiteLLM model identifier.
config (dict[str, Any] | None) – Optional configuration dictionary.
api_key (str | None) – API key (overrides env var).
api_base (str | None) – API base URL (overrides env var).
system_instructions (str) – System prompt.
temperature (float) – Sampling temperature (0-2).
max_tokens (int) – Maximum tokens to generate.
fallbacks (list[str] | None) – List of fallback model strings.
api_version (str | None)
kwargs (Any)
- async generate_response(prompt, model=None, system_instructions=None, temperature=None, max_tokens=None, **kwargs)[source]
Generate a response from the model asynchronously.
Falls back to configured fallback models when the primary call fails.
- Parameters:
prompt (str) – User’s input text.
model (str | None) – Model identifier override (preserves provider prefix if set).
system_instructions (str | None) – System prompt override.
temperature (float | None) – Sampling temperature override.
max_tokens (int | None) – Maximum tokens to generate override.
**kwargs (Any) – Additional parameters forwarded to
litellm.acompletion().
- Returns:
The model’s response text.
- Raises:
ValueError – If the prompt is empty.
RuntimeError – If all models (primary + fallbacks) fail.
- Return type:
- class FFLiteLLMClient(model_string, config=None, *, api_key=None, api_base=None, api_version=None, system_instructions=None, temperature=None, max_tokens=None, fallbacks=None, retry_config=None, **kwargs)[source]
Bases:
BaseLiteLLMClient,FFAIClientBaseLiteLLM-backed AI client implementing FFAIClientBase.
This client wraps LiteLLM’s completion() function while maintaining the FFAIClientBase contract for compatibility with FFAI wrapper.
Key features: - Internal conversation history management - Clone pattern for parallel execution - Model string routing (e.g., “azure/mistral-small-2503”) - Retry and fallback support
- Parameters:
model_string (str) – LiteLLM model identifier (e.g., “openai/gpt-4”, “azure/my-deployment”)
config (dict[str, Any] | None) – Optional configuration dictionary
api_key (str | None) – API key (overrides env var)
api_base (str | None) – API base URL (overrides env var)
system_instructions (str) – System prompt
temperature (float) – Sampling temperature (0-2)
max_tokens (int) – Maximum tokens to generate
fallbacks (list[str] | None) – List of fallback model strings
api_version (str | None)
kwargs (Any)
Example
>>> client = FFLiteLLMClient(model_string="azure/mistral-small-2503") >>> response = client.generate_response("Hello!") >>> >>> # With fallbacks >>> client = FFLiteLLMClient( ... model_string="anthropic/claude-3-opus", ... fallbacks=["openai/gpt-4", "azure/gpt-4"] ... )
- generate_response(prompt, model=None, system_instructions=None, temperature=None, max_tokens=None, **kwargs)[source]
Generate a response from the AI model with retry and fallback logic.
Retries are handled by
retry_utils.get_configured_retry_decoratoron the inner_call_primarymethod. If the primary model (and all its retries) fail, fallback models are tried once each.- Parameters:
prompt (str) – The user prompt
model (str | None) – Override model (appends to provider prefix)
system_instructions (str | None) – Override system instructions
temperature (float | None) – Override temperature
max_tokens (int | None) – Override max tokens
**kwargs (Any) – Additional LiteLLM parameters
- Returns:
The generated response text
- Raises:
ValueError – If prompt is empty
RuntimeError – If all models (including fallbacks) fail
- Return type:
- class FFMistralSmall(config=None, **kwargs)[source]
Bases:
FFAIClientBaseMistral Small client with chat completions, function calling, and tool use.
Wraps the
mistralaiSDK to provide a consistentFFAIClientBaseinterface with built-in retry, conversation tracking, and tool-call handling for the Mistral Small family of models.- Parameters:
config (dict | None) – Optional configuration dictionary.
**kwargs – Keyword overrides for model, temperature, max_tokens, etc.
- generate_response(prompt, model=None, system_instructions=None, temperature=None, max_tokens=None, max_completion_tokens=None, top_p=None, presence_penalty=None, frequency_penalty=None, stop=None, response_format=None, tools=None, tool_choice=None, safe_mode=None, **kwargs)[source]
Generate a response from the model with robust parameter handling.
- Parameters:
prompt (str) – User’s input text
model (str | None) – Model to use (overrides default)
system_instructions (str | None) – System instructions (overrides default)
temperature (float | None) – Controls randomness (0-1)
max_tokens (int | None) – Maximum tokens to generate
max_completion_tokens (int | None) – Alternative name for max_tokens (for compatibility)
top_p (float | None) – Nucleus sampling parameter
presence_penalty (float | None) – Penalizes repeated tokens
frequency_penalty (float | None) – Penalizes frequent tokens
stop (list[str] | None) – List of strings that stop generation when encountered
response_format (str | dict | type | None) – Format of the response (“text” or “json”)
tools (list[dict] | None) – List of tools to make available to the model
tool_choice (str | None) – Tool choice strategy (“auto”, “none”, or specific tool)
safe_mode (bool | None) – Whether to enable Mistral’s safe mode
**kwargs – Any additional parameters that may be passed but aren’t used
- Returns:
The model’s response as a string
- Return type:
Classes
- class AsyncFFLiteLLMClient(model_string, config=None, *, api_key=None, api_base=None, api_version=None, system_instructions=None, temperature=None, max_tokens=None, fallbacks=None, retry_config=None, **kwargs)[source]
Bases:
BaseLiteLLMClient,AsyncFFAIClientBaseAsync LiteLLM-backed AI client implementing AsyncFFAIClientBase.
Key features: - Internal conversation history management - Clone pattern for parallel execution - Model string routing (e.g., “azure/mistral-small-2503”) - Retry and fallback support
- Parameters:
model_string (str) – LiteLLM model identifier.
config (dict[str, Any] | None) – Optional configuration dictionary.
api_key (str | None) – API key (overrides env var).
api_base (str | None) – API base URL (overrides env var).
system_instructions (str) – System prompt.
temperature (float) – Sampling temperature (0-2).
max_tokens (int) – Maximum tokens to generate.
fallbacks (list[str] | None) – List of fallback model strings.
api_version (str | None)
kwargs (Any)
- async generate_response(prompt, model=None, system_instructions=None, temperature=None, max_tokens=None, **kwargs)[source]
Generate a response from the model asynchronously.
Falls back to configured fallback models when the primary call fails.
- Parameters:
prompt (str) – User’s input text.
model (str | None) – Model identifier override (preserves provider prefix if set).
system_instructions (str | None) – System prompt override.
temperature (float | None) – Sampling temperature override.
max_tokens (int | None) – Maximum tokens to generate override.
**kwargs (Any) – Additional parameters forwarded to
litellm.acompletion().
- Returns:
The model’s response text.
- Raises:
ValueError – If the prompt is empty.
RuntimeError – If all models (primary + fallbacks) fail.
- Return type:
- async clone()[source]
Create a deep copy of this client with reset usage and empty history.
- Returns:
A new
AsyncFFLiteLLMClientwith identical configuration.- Return type:
- add_tool_result(tool_call_id, content)
Append a tool result message to the conversation history.
- clear_conversation()
Remove all messages from the conversation history.
- Return type:
None
- configure_retry(retry_config=None)
Configure retry behavior for this client.
- get_conversation_history()
Return a shallow copy of the conversation history.
- static get_default_retry_config()
Get default retry configuration from global config.
- property last_duration_ms: float | None
Wall-clock duration in ms of the most recent generate_response() call.
- property last_usage: TokenUsage | None
Token usage from the most recent generate_response() call.
- set_conversation_history(history)
Replace the conversation history with a new list of messages.
- class FFLiteLLMClient(model_string, config=None, *, api_key=None, api_base=None, api_version=None, system_instructions=None, temperature=None, max_tokens=None, fallbacks=None, retry_config=None, **kwargs)[source]
Bases:
BaseLiteLLMClient,FFAIClientBaseLiteLLM-backed AI client implementing FFAIClientBase.
This client wraps LiteLLM’s completion() function while maintaining the FFAIClientBase contract for compatibility with FFAI wrapper.
Key features: - Internal conversation history management - Clone pattern for parallel execution - Model string routing (e.g., “azure/mistral-small-2503”) - Retry and fallback support
- Parameters:
model_string (str) – LiteLLM model identifier (e.g., “openai/gpt-4”, “azure/my-deployment”)
config (dict[str, Any] | None) – Optional configuration dictionary
api_key (str | None) – API key (overrides env var)
api_base (str | None) – API base URL (overrides env var)
system_instructions (str) – System prompt
temperature (float) – Sampling temperature (0-2)
max_tokens (int) – Maximum tokens to generate
fallbacks (list[str] | None) – List of fallback model strings
api_version (str | None)
kwargs (Any)
Example
>>> client = FFLiteLLMClient(model_string="azure/mistral-small-2503") >>> response = client.generate_response("Hello!") >>> >>> # With fallbacks >>> client = FFLiteLLMClient( ... model_string="anthropic/claude-3-opus", ... fallbacks=["openai/gpt-4", "azure/gpt-4"] ... )
- generate_response(prompt, model=None, system_instructions=None, temperature=None, max_tokens=None, **kwargs)[source]
Generate a response from the AI model with retry and fallback logic.
Retries are handled by
retry_utils.get_configured_retry_decoratoron the inner_call_primarymethod. If the primary model (and all its retries) fail, fallback models are tried once each.- Parameters:
prompt (str) – The user prompt
model (str | None) – Override model (appends to provider prefix)
system_instructions (str | None) – Override system instructions
temperature (float | None) – Override temperature
max_tokens (int | None) – Override max tokens
**kwargs (Any) – Additional LiteLLM parameters
- Returns:
The generated response text
- Raises:
ValueError – If prompt is empty
RuntimeError – If all models (including fallbacks) fail
- Return type:
- clone()[source]
Create a fresh clone of this client with empty history.
Used for thread-safe parallel execution where each thread needs an isolated client instance with the same configuration.
- Returns:
New FFLiteLLMClient with same config, empty history.
- Return type:
- add_tool_result(tool_call_id, content)
Append a tool result message to the conversation history.
- clear_conversation()
Remove all messages from the conversation history.
- Return type:
None
- configure_retry(retry_config=None)
Configure retry behavior for this client.
- get_conversation_history()
Return a shallow copy of the conversation history.
- static get_default_retry_config()
Get default retry configuration from global config.
- property last_duration_ms: float | None
Wall-clock duration in ms of the most recent generate_response() call.
- property last_usage: TokenUsage | None
Token usage from the most recent generate_response() call.
- set_conversation_history(history)
Replace the conversation history with a new list of messages.
- class FFMistralSmall(config=None, **kwargs)[source]
Bases:
FFAIClientBaseMistral Small client with chat completions, function calling, and tool use.
Wraps the
mistralaiSDK to provide a consistentFFAIClientBaseinterface with built-in retry, conversation tracking, and tool-call handling for the Mistral Small family of models.- Parameters:
config (dict | None) – Optional configuration dictionary.
**kwargs – Keyword overrides for model, temperature, max_tokens, etc.
- configure_retry(retry_config=None)
Configure retry behavior for this client.
- static get_default_retry_config()
Get default retry configuration from global config.
- property last_duration_ms: float | None
Wall-clock duration in ms of the most recent generate_response() call.
- property last_usage: TokenUsage | None
Token usage from the most recent generate_response() call.
- generate_response(prompt, model=None, system_instructions=None, temperature=None, max_tokens=None, max_completion_tokens=None, top_p=None, presence_penalty=None, frequency_penalty=None, stop=None, response_format=None, tools=None, tool_choice=None, safe_mode=None, **kwargs)[source]
Generate a response from the model with robust parameter handling.
- Parameters:
prompt (str) – User’s input text
model (str | None) – Model to use (overrides default)
system_instructions (str | None) – System instructions (overrides default)
temperature (float | None) – Controls randomness (0-1)
max_tokens (int | None) – Maximum tokens to generate
max_completion_tokens (int | None) – Alternative name for max_tokens (for compatibility)
top_p (float | None) – Nucleus sampling parameter
presence_penalty (float | None) – Penalizes repeated tokens
frequency_penalty (float | None) – Penalizes frequent tokens
stop (list[str] | None) – List of strings that stop generation when encountered
response_format (str | dict | type | None) – Format of the response (“text” or “json”)
tools (list[dict] | None) – List of tools to make available to the model
tool_choice (str | None) – Tool choice strategy (“auto”, “none”, or specific tool)
safe_mode (bool | None) – Whether to enable Mistral’s safe mode
**kwargs – Any additional parameters that may be passed but aren’t used
- Returns:
The model’s response as a string
- Return type: