guidance.models.OpenAI
- class guidance.models.OpenAI(model: str, sampling_params: SamplingParams | None = None, echo: bool = True, *, api_key: str | None = None, reasoning_effort: str | None = None, **kwargs)
- __init__(model: str, sampling_params: SamplingParams | None = None, echo: bool = True, *, api_key: str | None = None, reasoning_effort: str | None = None, **kwargs)
Build a new OpenAI model object that represents a model in a given state.
- Parameters:
- modelstr
The name of the OpenAI model to use (e.g. gpt-4o-mini).
- echobool
If true the final result of creating this model state will be displayed (as HTML in a notebook).
- api_keyNone or str
The OpenAI API key to use for remote requests, passed directly to the openai.OpenAI constructor.
- **kwargs
All extra keyword arguments are passed directly to the openai.OpenAI constructor. Commonly used argument names include base_url and organization
Methods
__init__(model[, sampling_params, echo, ...])Build a new OpenAI model object that represents a model in a given state.
copy()get(key[, default])Return the value of a variable, or a default value if the variable is not present.
log_prob(key[, default])Return the log probability of a variable, or a default value if the variable is not present.
remove(key)Return a new model with the given variable deleted.
set(key, value)Return a new model with the given variable value set.
stream()Return a new model stream object that delays execution until it is iterated over.
with_sampling_params(sampling_params)Return a new model with the given sampling parameters set.
with_step_config(step_config)Return a new model with step interjection configured (engine-backed models only).
- get(key: str, default: D | None = None) str | list[str] | None | D
Return the value of a variable, or a default value if the variable is not present.
- Parameters:
- keystr
The name of the variable.
- defaultAny
The value to return if the variable is not current set.
- log_prob(key: str, default: D | None = None) float | list[float | None] | None | D
Return the log probability of a variable, or a default value if the variable is not present.
- Parameters:
- keystr
The name of the variable.
- defaultAny
The value to return if the variable is not current set.
- remove(key: str) Self
Return a new model with the given variable deleted.
- Parameters:
- keystr
The variable name to remove.
- set(key: str, value: str | list[str]) Self
Return a new model with the given variable value set.
- Parameters:
- keystr
The name of the variable to be set.
- valuestr
The value to set the variable to.
- stream() ModelStream
Return a new model stream object that delays execution until it is iterated over.
- with_sampling_params(sampling_params: SamplingParams) Self
Return a new model with the given sampling parameters set.
- with_step_config(step_config: StepConfig) Self
Return a new model with step interjection configured (engine-backed models only).