generator
Encapsulate a model and an output type into a reusable object.
AsyncBlackBoxGenerator
Asynchronous generator for which we don't control constrained generation.
The output type provided is not compiled into a logits processor, but is instead directly passed on to the model.
Source code in outlines/generator.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
__call__(prompt, **inference_kwargs)
async
Generate a response from the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
Any
|
The prompt to use to generate a response. |
required |
**inference_kwargs
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The response generated by the model. |
Source code in outlines/generator.py
__init__(model, output_type)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
AsyncBlackBoxModel
|
An instance of an Outlines model. |
required |
output_type
|
Optional[Any]
|
The output type that will be used to constrain the generation. |
required |
Source code in outlines/generator.py
batch(prompts, **inference_kwargs)
async
Generate a batch of responses from the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
List[Any]
|
The list of prompts to use to generate a batch of responses. |
required |
**inference_kwargs
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
Type | Description |
---|---|
List[Any]
|
The list of responses generated by the model. |
Source code in outlines/generator.py
stream(prompt, **inference_kwargs)
async
Generate a stream of responses from the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
Any
|
The prompt to use to generate a response. |
required |
**inference_kwargs
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The response generated by the model. |
Source code in outlines/generator.py
BlackBoxGenerator
Synchronous generator for which we don't control constrained generation.
The output type provided is not compiled into a logits processor, but is instead directly passed on to the model.
Source code in outlines/generator.py
__call__(prompt, **inference_kwargs)
Generate a response from the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
Any
|
The prompt to use to generate a response. |
required |
**inference_kwargs
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The response generated by the model. |
Source code in outlines/generator.py
__init__(model, output_type)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
BlackBoxModel
|
An instance of an Outlines model. |
required |
output_type
|
Optional[Any]
|
The output type that will be used to constrain the generation. |
required |
Source code in outlines/generator.py
batch(prompts, **inference_kwargs)
Generate a batch of responses from the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
List[Any]
|
The list of prompts to use to generate a batch of responses. |
required |
**inference_kwargs
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
Type | Description |
---|---|
List[Any]
|
The list of responses generated by the model. |
Source code in outlines/generator.py
stream(prompt, **inference_kwargs)
Generate a stream of responses from the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
Any
|
The prompt to use to generate a response. |
required |
**inference_kwargs
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The response generated by the model. |
Source code in outlines/generator.py
SteerableGenerator
Represents a generator for which we control constrained generation.
The generator is responsible for building and storing the logits processor (which can be quite expensive to build), and then passing it to the model when the generator is called.
The argument defining constrained generation can be of 2 types associated
to different methods to create an instance of the generator:
- output_type
(through __init__
): an output type as defined in the
outlines.types
module
- processor
(through from_processor
): an already built logits processor
as defined in the outlines.processors
module
The 2 parameters are mutually exclusive.
Source code in outlines/generator.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
__call__(prompt, **inference_kwargs)
Generate a response from the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
Any
|
The prompt to use to generate a response. |
required |
**inference_kwargs
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The response generated by the model. |
Source code in outlines/generator.py
__init__(model, output_type)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
SteerableModel
|
An instance of an Outlines model. |
required |
output_type
|
Optional[Any]
|
The output type expressed as a Python type |
required |
Source code in outlines/generator.py
batch(prompts, **inference_kwargs)
Generate a batch of responses from the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
List[Any]
|
The list of prompts to use to generate a batch of responses. |
required |
**inference_kwargs
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
Type | Description |
---|---|
List[Any]
|
The list of responses generated by the model. |
Source code in outlines/generator.py
from_processor(model, processor)
classmethod
Create a generator from a logits processor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
SteerableModel
|
An instance of an Outlines model. |
required |
processor
|
OutlinesLogitsProcessor
|
An instance of an OutlinesLogitsProcessor. |
required |
Source code in outlines/generator.py
stream(prompt, **inference_kwargs)
Generate a stream of responses from the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
Any
|
The prompt to use to generate a response. |
required |
**inference_kwargs
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
Type | Description |
---|---|
Any
|
The response generated by the model. |
Source code in outlines/generator.py
Generator(model, output_type=None, *, processor=None)
Create a generator for the given model and output parameters.
The 2 parameters output_type and processor are mutually exclusive. The parameters processor is only supported for SteerableModel instances (typically local models) and is intended to be only used by advanced users.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Union[Model, AsyncModel]
|
An instance of an Outlines model. |
required |
output_type
|
Optional[Any]
|
The output type expressed as a Python type or a type defined in the outlines.types.dsl module. |
None
|
processor
|
Optional[OutlinesLogitsProcessor]
|
An instance of an OutlinesLogitsProcessor. |
None
|
Returns:
Type | Description |
---|---|
Union[SteerableGenerator, BlackBoxGenerator, AsyncBlackBoxGenerator]
|
A generator instance. |