OpenAI backend
actantial.backends.openai.OpenAIBackend
Bases: LLMBackend
Backend for OpenAI API models.
Wraps the OpenAI Responses API to provide text generation compatible with the actantial pipeline.
__init__(model_name='gpt-4o-mini', system_prompt='You are a helpful assistant.', temperature=0, api_key=None)
Initialise the OpenAI backend, validate the model, and run a validation call.
A lightweight validation call (max_output_tokens=16) is made at construction
time to verify connectivity and model availability. When temperature is a float,
the call also checks whether the model accepts that parameter; if not, a warning is
issued and temperature is omitted from all subsequent calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
OpenAI model identifier (e.g., |
'gpt-4o-mini'
|
system_prompt
|
str
|
System-level instruction passed to the model on every request. |
'You are a helpful assistant.'
|
temperature
|
Optional[float]
|
Sampling temperature in [0, 2]; higher values increase randomness.
Defaults to 0 for deterministic output. Pass |
0
|
api_key
|
Optional[str]
|
OpenAI API key. If |
None
|
generate(prompt, max_new_tokens=2048, **kwargs)
Generate text from a prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
The input prompt string. |
required |
max_new_tokens
|
int
|
Maximum number of tokens to generate. |
2048
|
**kwargs
|
Any
|
Additional parameters passed to the OpenAI Responses API. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The generated text string, excluding the input prompt. |