models
Module that contains all the models integrated in outlines.
We group the models in submodules by provider instead of theme (completion, chat completion, diffusers, etc.) and use routing functions everywhere else in the codebase.
Anthropic
Bases: Model
Thin wrapper around the anthropic.Anthropic client.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the anthropic.Anthropic client.
Source code in outlines/models/anthropic.py
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 206 207 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 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Anthropic
|
An |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/anthropic.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using Anthropic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
As structured generation is not supported by Anthropic, the value
of this argument must be |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The response generated by the model. |
Source code in outlines/models/anthropic.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Stream text using Anthropic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
As structured generation is not supported by Anthropic, the value
of this argument must be |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/anthropic.py
AsyncMistral
Bases: AsyncModel
Async thin wrapper around the mistralai.Mistral client.
Converts input and output types to arguments for the mistralai.Mistral
client's async methods (chat.complete_async or chat.stream_async).
Source code in outlines/models/mistral.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Mistral
|
A mistralai.Mistral client instance. |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/mistral.py
generate(model_input, output_type=None, **inference_kwargs)
async
Generate a response from the model asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt or chat messages to generate a response from. |
required |
output_type
|
Optional[Any]
|
The desired format of the response (e.g., JSON schema). |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The response generated by the model as text. |
Source code in outlines/models/mistral.py
generate_stream(model_input, output_type=None, **inference_kwargs)
async
Generate text from the model as an async stream of chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str, list, or chat input to generate from. |
required | |
output_type
|
Optional type for structured output. |
None
|
|
**inference_kwargs
|
Extra kwargs like "model" name. |
{}
|
Yields:
| Type | Description |
|---|---|
str
|
Chunks of text as they are streamed. |
Source code in outlines/models/mistral.py
AsyncOllama
Bases: AsyncModel
Thin wrapper around the ollama.AsyncClient client.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the ollama.AsyncClient client.
Source code in outlines/models/ollama.py
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 349 350 351 352 353 354 355 356 357 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
AsyncClient
|
The |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/ollama.py
generate(model_input, output_type=None, **kwargs)
async
Generate text using Ollama.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Chat | str | list
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The text generated by the model. |
Source code in outlines/models/ollama.py
generate_stream(model_input, output_type=None, **kwargs)
async
Stream text using Ollama.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Chat | str | list
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/ollama.py
AsyncOpenAI
Bases: AsyncModel
Thin wrapper around the openai.AsyncOpenAI client.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the openai.AsyncOpenAI client.
Source code in outlines/models/openai.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Union[AsyncOpenAI, AsyncAzureOpenAI]
|
The |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/openai.py
generate(model_input, output_type=None, **inference_kwargs)
async
Generate text using OpenAI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Union[type[BaseModel], str]]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema or an empty dictionary. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The text generated by the model. |
Source code in outlines/models/openai.py
generate_stream(model_input, output_type=None, **inference_kwargs)
async
Stream text using OpenAI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Union[type[BaseModel], str]]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema or an empty dictionary. |
None
|
**inference_kwargs
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/openai.py
AsyncSGLang
Bases: AsyncModel
Thin async wrapper around the openai.OpenAI client used to communicate
with an SGLang server.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the openai.OpenAI client for the
SGLang server.
Source code in outlines/models/sglang.py
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 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
An |
required | |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
An |
required |
Source code in outlines/models/sglang.py
generate(model_input, output_type=None, **inference_kwargs)
async
Generate text using sglang.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, str, list]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All output types available in Outlines are supported provided your server uses a structured generation backend that supports them. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The text generated by the model. |
Source code in outlines/models/sglang.py
generate_stream(model_input, output_type=None, **inference_kwargs)
async
Return a text generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, str, list]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All output types available in Outlines are supported provided your server uses a structured generation backend that supports them. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
AsyncIterator[str]
|
An async iterator that yields the text generated by the model. |
Source code in outlines/models/sglang.py
AsyncTGI
Bases: AsyncModel
Thin async wrapper around a huggingface_hub.AsyncInferenceClient
client used to communicate with a TGI server.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the
huggingface_hub.AsyncInferenceClient client.
Source code in outlines/models/tgi.py
205 206 207 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 | |
__init__(client)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
A huggingface |
required |
generate(model_input, output_type=None, **inference_kwargs)
async
Generate text using TGI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All
output types except |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The text generated by the model. |
Source code in outlines/models/tgi.py
generate_stream(model_input, output_type=None, **inference_kwargs)
async
Stream text using TGI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All
output types except |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
AsyncIterator[str]
|
An async iterator that yields the text generated by the model. |
Source code in outlines/models/tgi.py
AsyncVLLM
Bases: AsyncModel
Thin async wrapper around the openai.OpenAI client used to communicate
with a vllm server.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the openai.OpenAI client for the
vllm server.
Source code in outlines/models/vllm.py
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 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
AsyncOpenAI
|
An |
required |
Source code in outlines/models/vllm.py
generate(model_input, output_type=None, **inference_kwargs)
async
Generate text using vLLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, str, list]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All output types available in Outlines are supported provided your server uses a structured generation backend that supports them. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The text generated by the model. |
Source code in outlines/models/vllm.py
generate_stream(model_input, output_type=None, **inference_kwargs)
async
Stream text using vLLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, str, list]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All output types available in Outlines are supported provided your server uses a structured generation backend that supports them. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
AsyncIterator[str]
|
An async iterator that yields the text generated by the model. |
Source code in outlines/models/vllm.py
Dottxt
Bases: Model
Thin wrapper around the dottxt.client.Dottxt client.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the dottxt.client.Dottxt client.
Source code in outlines/models/dottxt.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 | |
__init__(client, model_name=None, model_revision=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Dottxt
|
A |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
model_revision
|
Optional[str]
|
The revision of the model to use. |
None
|
Source code in outlines/models/dottxt.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using Dottxt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The text generated by the model. |
Source code in outlines/models/dottxt.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Not available for Dottxt.
Source code in outlines/models/dottxt.py
Gemini
Bases: Model
Thin wrapper around the google.genai.Client client.
This wrapper is used to convert the input and output types specified by
the users at a higher level to arguments to the google.genai.Client
client.
Source code in outlines/models/gemini.py
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 349 350 351 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Client
|
A |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/gemini.py
generate(model_input, output_type=None, **inference_kwargs)
Generate a response from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema, a list of such types, or a multiple choice type. |
None
|
**inference_kwargs
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The response generated by the model. |
Source code in outlines/models/gemini.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Generate a stream of responses from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema, a list of such types, or a multiple choice type. |
None
|
**inference_kwargs
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/gemini.py
LlamaCpp
Bases: Model
Thin wrapper around the llama_cpp.Llama model.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the llama_cpp.Llama model.
Source code in outlines/models/llamacpp.py
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 | |
__init__(model)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Llama
|
A |
required |
Source code in outlines/models/llamacpp.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using llama-cpp-python.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The text generated by the model. |
Source code in outlines/models/llamacpp.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Stream text using llama-cpp-python.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/llamacpp.py
MLXLM
Bases: Model
Thin wrapper around an mlx_lm model.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the mlx_lm library.
Source code in outlines/models/mlxlm.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 206 207 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 | |
__init__(model, tokenizer)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
An instance of an |
required |
tokenizer
|
PreTrainedTokenizer
|
An instance of an |
required |
Source code in outlines/models/mlxlm.py
generate(model_input, output_type=None, **kwargs)
Generate text using mlx-lm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
kwargs
|
Additional keyword arguments to pass to the |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The text generated by the model. |
Source code in outlines/models/mlxlm.py
generate_batch(model_input, output_type=None, **kwargs)
Generate a batch of text using mlx-lm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
list[str]
|
The list of prompts based on which the model will generate a response. |
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
kwargs
|
Additional keyword arguments to pass to the |
{}
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The list of text generated by the model. |
Source code in outlines/models/mlxlm.py
generate_stream(model_input, output_type=None, **kwargs)
Stream text using mlx-lm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
kwargs
|
Additional keyword arguments to pass to the |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/mlxlm.py
Mistral
Bases: Model
Thin wrapper around the mistralai.Mistral client.
Converts input and output types to arguments for the mistralai.Mistral
client's chat.complete or chat.stream methods.
Source code in outlines/models/mistral.py
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 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Mistral
|
A mistralai.Mistral client instance. |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/mistral.py
generate(model_input, output_type=None, **inference_kwargs)
Generate a response from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt or chat messages to generate a response from. |
required |
output_type
|
Optional[Any]
|
The desired format of the response (e.g., JSON schema). |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The response generated by the model as text. |
Source code in outlines/models/mistral.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Generate a stream of responses from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt or chat messages to generate a response from. |
required |
output_type
|
Optional[Any]
|
The desired format of the response (e.g., JSON schema). |
None
|
**inference_kwargs
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text chunks generated by the model. |
Source code in outlines/models/mistral.py
Model
Bases: ABC
Base class for all synchronous models.
This class defines shared __call__, batch and stream methods that can
be used to call the model directly. The generate, generate_batch, and
generate_stream methods must be implemented by the subclasses.
All models inheriting from this class must define a type_adapter
attribute of type ModelTypeAdapter. The methods of the type_adapter
attribute are used in the generate, generate_batch, and
generate_stream methods to format the input and output types received by
the model.
Additionally, steerable models must define a tensor_library_name
attribute.
Source code in outlines/models/base.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 206 207 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 | |
__call__(model_input, output_type=None, backend=None, **inference_kwargs)
Call the model.
Users can call the model directly, in which case we will create a generator instance with the output type provided and call it. Thus, those commands are equivalent:
andParameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
backend
|
Optional[str]
|
The name of the backend to use to create the logits processor that
will be used to generate the response. Only used for steerable
models if |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The response generated by the model. |
Source code in outlines/models/base.py
batch(model_input, output_type=None, backend=None, **inference_kwargs)
Make a batch call to the model (several inputs at once).
Users can use the batch method from the model directly, in which
case we will create a generator instance with the output type provided
and then invoke its batch method.
Thus, those commands are equivalent:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
List[Any]
|
The list of inputs provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
backend
|
Optional[str]
|
The name of the backend to use to create the logits processor that
will be used to generate the response. Only used for steerable
models if |
None
|
**inference_kwargs
|
Any
|
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/models/base.py
generate(model_input, output_type=None, **inference_kwargs)
abstractmethod
Generate a response from the model.
The output_type argument contains a logits processor for steerable models while it contains a type (Json, Enum...) for black-box models. This method is not intended to be used directly by end users.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The response generated by the model. |
Source code in outlines/models/base.py
generate_batch(model_input, output_type=None, **inference_kwargs)
abstractmethod
Generate a batch of responses from the model.
The output_type argument contains a logits processor for steerable models while it contains a type (Json, Enum...) for black-box models. This method is not intended to be used directly by end users.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
List[Any]
|
The list of inputs provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
**inference_kwargs
|
Any
|
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/models/base.py
generate_stream(model_input, output_type=None, **inference_kwargs)
abstractmethod
Generate a stream of responses from the model.
The output_type argument contains a logits processor for steerable models while it contains a type (Json, Enum...) for black-box models. This method is not intended to be used directly by end users.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[Any]
|
A stream of responses from the model. |
Source code in outlines/models/base.py
stream(model_input, output_type=None, backend=None, **inference_kwargs)
Stream a response from the model.
Users can use the stream method from the model directly, in which
case we will create a generator instance with the output type provided
and then invoke its stream method.
Thus, those commands are equivalent:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
backend
|
Optional[str]
|
The name of the backend to use to create the logits processor that
will be used to generate the response. Only used for steerable
models if |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[Any]
|
A stream of responses from the model. |
Source code in outlines/models/base.py
ModelTypeAdapter
Bases: ABC
Base class for all model type adapters.
A type adapter instance must be given as a value to the type_adapter
attribute when instantiating a model.
The type adapter is responsible for formatting the input and output types
passed to the model to match the specific format expected by the
associated model.
Source code in outlines/models/base.py
format_input(model_input)
abstractmethod
Format the user input to the expected format of the model.
For API-based models, it typically means creating the messages
argument passed to the client. For local models, it can mean casting
the input from str to list for instance.
This method is also used to validate that the input type provided by
the user is supported by the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The formatted input to be passed to the model. |
Source code in outlines/models/base.py
format_output_type(output_type=None)
abstractmethod
Format the output type to the expected format of the model.
For black-box models, this typically means creating a response_format
argument. For steerable models, it means formatting the logits processor
to create the object type expected by the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The formatted output type to be passed to the model. |
Source code in outlines/models/base.py
Ollama
Bases: Model
Thin wrapper around the ollama.Client client.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the ollama.Client client.
Source code in outlines/models/ollama.py
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 206 207 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 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Client
|
The |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/ollama.py
generate(model_input, output_type=None, **kwargs)
Generate text using Ollama.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Chat | str | list
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The text generated by the model. |
Source code in outlines/models/ollama.py
generate_stream(model_input, output_type=None, **kwargs)
Stream text using Ollama.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Chat | str | list
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/ollama.py
OpenAI
Bases: Model
Thin wrapper around the openai.OpenAI client.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the openai.OpenAI client.
Source code in outlines/models/openai.py
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 349 350 351 352 353 354 355 356 357 358 359 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Union[OpenAI, AzureOpenAI]
|
The |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/openai.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using OpenAI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Union[type[BaseModel], str]]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema or an empty dictionary. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The text generated by the model. |
Source code in outlines/models/openai.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Stream text using OpenAI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Union[type[BaseModel], str]]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema or an empty dictionary. |
None
|
**inference_kwargs
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/openai.py
SGLang
Bases: Model
Thin wrapper around the openai.OpenAI client used to communicate with
an SGLang server.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the openai.OpenAI client for the
SGLang server.
Source code in outlines/models/sglang.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
An |
required | |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/sglang.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using SGLang.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All output types available in Outlines are supported provided your server uses a structured generation backend that supports them. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The text generated by the model. |
Source code in outlines/models/sglang.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Stream text using SGLang.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All output types available in Outlines are supported provided your server uses a structured generation backend that supports them. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/sglang.py
TGI
Bases: Model
Thin wrapper around a huggingface_hub.InferenceClient client used to
communicate with a TGI server.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the
huggingface_hub.InferenceClient client.
Source code in outlines/models/tgi.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 | |
__init__(client)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
A huggingface |
required |
generate(model_input, output_type=None, **inference_kwargs)
Generate text using TGI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All
output types except |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The text generated by the model. |
Source code in outlines/models/tgi.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Stream text using TGI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All
output types except |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/tgi.py
TransformerTokenizer
Bases: Tokenizer
Represents a tokenizer for models in the transformers library.
Source code in outlines/models/transformers.py
Transformers
Bases: Model
Thin wrapper around a transformers model and a transformers
tokenizer.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the transformers model and
tokenizer.
Source code in outlines/models/transformers.py
198 199 200 201 202 203 204 205 206 207 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 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
__init__(model, tokenizer, *, device_dtype=None)
Parameters:
model
A PreTrainedModel, or any model that is compatible with the
transformers API for models.
tokenizer
A PreTrainedTokenizer, or any tokenizer that is compatible with
the transformers API for tokenizers.
device_dtype
The dtype to use for the model. If not provided, the model will use
the default dtype.
Source code in outlines/models/transformers.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using transformers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[str, dict, Chat]
|
The prompt based on which the model will generate a response. For
multi-modal models, the input should be a dictionary containing the
|
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, List[str]]
|
The text generated by the model. |
Source code in outlines/models/transformers.py
generate_batch(model_input, output_type=None, **inference_kwargs)
Source code in outlines/models/transformers.py
generate_stream(model_input, output_type, **inference_kwargs)
Not available for transformers models.
TODO: implement following completion of https://github.com/huggingface/transformers/issues/30810
Source code in outlines/models/transformers.py
TransformersMultiModal
Bases: Transformers
Thin wrapper around a transformers model and a transformers
processor.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the transformers model and
processor.
Source code in outlines/models/transformers.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
__init__(model, processor, *, device_dtype=None)
Create a TransformersMultiModal model instance
We rely on the __init__ method of the Transformers class to handle
most of the initialization and then add elements specific to multimodal
models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PreTrainedModel
|
A |
required |
processor
|
A |
required | |
device_dtype
|
Optional[dtype]
|
The dtype to use for the model. If not provided, the model will use the default dtype. |
None
|
Source code in outlines/models/transformers.py
VLLM
Bases: Model
Thin wrapper around the openai.OpenAI client used to communicate with
a vllm server.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the openai.OpenAI client for the
vllm server.
Source code in outlines/models/vllm.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 206 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
OpenAI
|
An |
required |
Source code in outlines/models/vllm.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using vLLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, str, list]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All output types available in Outlines are supported provided your server uses a structured generation backend that supports them. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The text generated by the model. |
Source code in outlines/models/vllm.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Stream text using vLLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, str, list]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All output types available in Outlines are supported provided your server uses a structured generation backend that supports them. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/vllm.py
VLLMOffline
Bases: Model
Thin wrapper around a vllm.LLM model.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the vllm.LLM model.
Source code in outlines/models/vllm_offline.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 206 207 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 | |
__init__(model)
Create a VLLM model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LLM
|
A |
required |
generate(model_input, output_type=None, **inference_kwargs)
Generate text using vLLM offline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
The prompt based on which the model will generate a response. |
required | |
output_type
|
Optional[Any]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, List[str]]
|
The text generated by the model. |
Source code in outlines/models/vllm_offline.py
generate_batch(model_input, output_type=None, **inference_kwargs)
Generate a batch of completions using vLLM offline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
The list of prompts based on which the model will generate a response. |
required | |
output_type
|
Optional[Any]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the |
{}
|
Returns:
| Type | Description |
|---|---|
Union[List[str], List[List[str]]]
|
The text generated by the model. |
Source code in outlines/models/vllm_offline.py
generate_stream(model_input, output_type, **inference_kwargs)
Not available for vllm.LLM.
TODO: Implement the streaming functionality ourselves.
Source code in outlines/models/vllm_offline.py
from_anthropic(client, model_name=None)
Create an Outlines Anthropic model instance from an
anthropic.Anthropic client instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Anthropic
|
An |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Returns:
| Type | Description |
|---|---|
Anthropic
|
An Outlines |
Source code in outlines/models/anthropic.py
from_dottxt(client, model_name=None, model_revision=None)
Create an Outlines Dottxt model instance from a dottxt.Dottxt
client instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Dottxt
|
A |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
model_revision
|
Optional[str]
|
The revision of the model to use. |
None
|
Returns:
| Type | Description |
|---|---|
Dottxt
|
An Outlines |
Source code in outlines/models/dottxt.py
from_gemini(client, model_name=None)
Create an Outlines Gemini model instance from a
google.genai.Client instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Client
|
A |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Returns:
| Type | Description |
|---|---|
Gemini
|
An Outlines |
Source code in outlines/models/gemini.py
from_llamacpp(model)
Create an Outlines LlamaCpp model instance from a
llama_cpp.Llama instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Llama
|
A |
required |
Returns:
| Type | Description |
|---|---|
LlamaCpp
|
An Outlines |
Source code in outlines/models/llamacpp.py
from_mistral(client, model_name=None, async_client=False)
Create an Outlines Mistral model instance from a mistralai.Mistral client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Mistral
|
A mistralai.Mistral client instance. |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
async_client
|
bool
|
If True, return an AsyncMistral instance; otherwise, return a Mistral instance. |
False
|
Returns:
| Type | Description |
|---|---|
Union[Mistral, AsyncMistral]
|
An Outlines Mistral or AsyncMistral model instance. |
Source code in outlines/models/mistral.py
from_mlxlm(model, tokenizer)
Create an Outlines MLXLM model instance from an mlx_lm model and a
tokenizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
An instance of an |
required |
tokenizer
|
PreTrainedTokenizer
|
An instance of an |
required |
Returns:
| Type | Description |
|---|---|
MLXLM
|
An Outlines |
Source code in outlines/models/mlxlm.py
from_ollama(client, model_name=None)
Create an Outlines Ollama model instance from an ollama.Client
or ollama.AsyncClient instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Union[Client, AsyncClient]
|
A |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Returns:
| Type | Description |
|---|---|
Union[Ollama, AsyncOllama]
|
An Outlines |
Source code in outlines/models/ollama.py
from_openai(client, model_name=None)
Create an Outlines OpenAI or AsyncOpenAI model instance from an
openai.OpenAI or openai.AsyncOpenAI client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Union[OpenAI, AsyncOpenAI, AzureOpenAI, AsyncAzureOpenAI]
|
An |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Returns:
| Type | Description |
|---|---|
OpenAI
|
An Outlines |
Source code in outlines/models/openai.py
from_sglang(client, model_name=None)
Create a SGLang or AsyncSGLang instance from an openai.OpenAI or
openai.AsyncOpenAI instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Union[OpenAI, AsyncOpenAI]
|
An |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Returns:
| Type | Description |
|---|---|
Union[SGLang, AsyncSGLang]
|
An Outlines |
Source code in outlines/models/sglang.py
from_tgi(client)
Create an Outlines TGI or AsyncTGI model instance from an
huggingface_hub.InferenceClient or huggingface_hub.AsyncInferenceClient
instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Union[InferenceClient, AsyncInferenceClient]
|
An |
required |
Returns:
| Type | Description |
|---|---|
Union[TGI, AsyncTGI]
|
An Outlines |
Source code in outlines/models/tgi.py
from_transformers(model, tokenizer_or_processor, *, device_dtype=None)
Create an Outlines Transformers or TransformersMultiModal model
instance from a PreTrainedModel instance and a PreTrainedTokenizer or
ProcessorMixin instance.
outlines supports PreTrainedModelForCausalLM,
PreTrainedMambaForCausalLM, PreTrainedModelForSeq2Seq and any model
that implements the transformers model API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PreTrainedModel
|
A |
required |
tokenizer_or_processor
|
Union[PreTrainedTokenizer, ProcessorMixin]
|
A |
required |
device_dtype
|
Optional[dtype]
|
The dtype to use for the model. If not provided, the model will use the default dtype. |
None
|
Returns:
| Type | Description |
|---|---|
Union[Transformers, TransformersMultiModal]
|
An Outlines |
Source code in outlines/models/transformers.py
from_vllm(client, model_name=None)
Create an Outlines VLLM or AsyncVLLM model instance from an
openai.OpenAI or openai.AsyncOpenAI instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Union[OpenAI, AsyncOpenAI]
|
An |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Returns:
| Type | Description |
|---|---|
Union[VLLM, AsyncVLLM]
|
An Outlines |
Source code in outlines/models/vllm.py
from_vllm_offline(model)
Create an Outlines VLLMOffline model instance from a vllm.LLM
instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LLM
|
A |
required |
Returns:
| Type | Description |
|---|---|
VLLMOffline
|
An Outlines |
Source code in outlines/models/vllm_offline.py
anthropic
Integration with Anthropic's API.
Anthropic
Bases: Model
Thin wrapper around the anthropic.Anthropic client.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the anthropic.Anthropic client.
Source code in outlines/models/anthropic.py
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 206 207 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 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Anthropic
|
An |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/anthropic.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using Anthropic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
As structured generation is not supported by Anthropic, the value
of this argument must be |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The response generated by the model. |
Source code in outlines/models/anthropic.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Stream text using Anthropic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
As structured generation is not supported by Anthropic, the value
of this argument must be |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/anthropic.py
AnthropicTypeAdapter
Bases: ModelTypeAdapter
Type adapter for the Anthropic model.
AnthropicTypeAdapter is responsible for preparing the arguments to
Anthropic's messages.create method: the input (prompt and possibly
image).
Anthropic does not support defining the output type, so
format_output_type is not implemented.
Source code in outlines/models/anthropic.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
format_chat_model_input(model_input)
Generate the messages argument to pass to the client when the user
passes a Chat instance.
Source code in outlines/models/anthropic.py
format_input(model_input)
Generate the messages argument to pass to the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
The input provided by the user. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The |
Source code in outlines/models/anthropic.py
format_output_type(output_type)
Not implemented for Anthropic.
from_anthropic(client, model_name=None)
Create an Outlines Anthropic model instance from an
anthropic.Anthropic client instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Anthropic
|
An |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Returns:
| Type | Description |
|---|---|
Anthropic
|
An Outlines |
Source code in outlines/models/anthropic.py
base
Base classes for all models and model type adapters.
AsyncModel
Bases: ABC
Base class for all asynchronous models.
This class defines shared __call__, batch and stream methods that can
be used to call the model directly. The generate, generate_batch, and
generate_stream methods must be implemented by the subclasses.
All models inheriting from this class must define a type_adapter
attribute of type ModelTypeAdapter. The methods of the type_adapter
attribute are used in the generate, generate_batch, and
generate_stream methods to format the input and output types received by
the model.
Additionally, steerable models must define a tensor_library_name
attribute.
Source code in outlines/models/base.py
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 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
__call__(model_input, output_type=None, backend=None, **inference_kwargs)
async
Call the model.
Users can call the model directly, in which case we will create a generator instance with the output type provided and call it. Thus, those commands are equivalent:
andParameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
backend
|
Optional[str]
|
The name of the backend to use to create the logits processor that
will be used to generate the response. Only used for steerable
models if |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The response generated by the model. |
Source code in outlines/models/base.py
batch(model_input, output_type=None, backend=None, **inference_kwargs)
async
Make a batch call to the model (several inputs at once).
Users can use the batch method from the model directly, in which
case we will create a generator instance with the output type provided
and then invoke its batch method.
Thus, those commands are equivalent:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
List[Any]
|
The list of inputs provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
backend
|
Optional[str]
|
The name of the backend to use to create the logits processor that
will be used to generate the response. Only used for steerable
models if |
None
|
**inference_kwargs
|
Any
|
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/models/base.py
generate(model_input, output_type=None, **inference_kwargs)
abstractmethod
async
Generate a response from the model.
The output_type argument contains a logits processor for steerable models while it contains a type (Json, Enum...) for black-box models. This method is not intended to be used directly by end users.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The response generated by the model. |
Source code in outlines/models/base.py
generate_batch(model_input, output_type=None, **inference_kwargs)
abstractmethod
async
Generate a batch of responses from the model.
The output_type argument contains a logits processor for steerable models while it contains a type (Json, Enum...) for black-box models. This method is not intended to be used directly by end users.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
List[Any]
|
The list of inputs provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
**inference_kwargs
|
Any
|
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/models/base.py
generate_stream(model_input, output_type=None, **inference_kwargs)
abstractmethod
async
Generate a stream of responses from the model.
The output_type argument contains a logits processor for steerable models while it contains a type (Json, Enum...) for black-box models. This method is not intended to be used directly by end users.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
| Type | Description |
|---|---|
AsyncIterator[Any]
|
A coroutine that will produce an async iterator of responses from the model. |
Source code in outlines/models/base.py
stream(model_input, output_type=None, backend=None, **inference_kwargs)
async
Stream a response from the model.
Users can use the stream method from the model directly, in which
case we will create a generator instance with the output type provided
and then invoke its stream method.
Thus, those commands are equivalent:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
backend
|
Optional[str]
|
The name of the backend to use to create the logits processor that
will be used to generate the response. Only used for steerable
models if |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
| Type | Description |
|---|---|
AsyncIterator[Any]
|
A stream of responses from the model. |
Source code in outlines/models/base.py
Model
Bases: ABC
Base class for all synchronous models.
This class defines shared __call__, batch and stream methods that can
be used to call the model directly. The generate, generate_batch, and
generate_stream methods must be implemented by the subclasses.
All models inheriting from this class must define a type_adapter
attribute of type ModelTypeAdapter. The methods of the type_adapter
attribute are used in the generate, generate_batch, and
generate_stream methods to format the input and output types received by
the model.
Additionally, steerable models must define a tensor_library_name
attribute.
Source code in outlines/models/base.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 206 207 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 | |
__call__(model_input, output_type=None, backend=None, **inference_kwargs)
Call the model.
Users can call the model directly, in which case we will create a generator instance with the output type provided and call it. Thus, those commands are equivalent:
andParameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
backend
|
Optional[str]
|
The name of the backend to use to create the logits processor that
will be used to generate the response. Only used for steerable
models if |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The response generated by the model. |
Source code in outlines/models/base.py
batch(model_input, output_type=None, backend=None, **inference_kwargs)
Make a batch call to the model (several inputs at once).
Users can use the batch method from the model directly, in which
case we will create a generator instance with the output type provided
and then invoke its batch method.
Thus, those commands are equivalent:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
List[Any]
|
The list of inputs provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
backend
|
Optional[str]
|
The name of the backend to use to create the logits processor that
will be used to generate the response. Only used for steerable
models if |
None
|
**inference_kwargs
|
Any
|
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/models/base.py
generate(model_input, output_type=None, **inference_kwargs)
abstractmethod
Generate a response from the model.
The output_type argument contains a logits processor for steerable models while it contains a type (Json, Enum...) for black-box models. This method is not intended to be used directly by end users.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The response generated by the model. |
Source code in outlines/models/base.py
generate_batch(model_input, output_type=None, **inference_kwargs)
abstractmethod
Generate a batch of responses from the model.
The output_type argument contains a logits processor for steerable models while it contains a type (Json, Enum...) for black-box models. This method is not intended to be used directly by end users.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
List[Any]
|
The list of inputs provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
**inference_kwargs
|
Any
|
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/models/base.py
generate_stream(model_input, output_type=None, **inference_kwargs)
abstractmethod
Generate a stream of responses from the model.
The output_type argument contains a logits processor for steerable models while it contains a type (Json, Enum...) for black-box models. This method is not intended to be used directly by end users.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[Any]
|
A stream of responses from the model. |
Source code in outlines/models/base.py
stream(model_input, output_type=None, backend=None, **inference_kwargs)
Stream a response from the model.
Users can use the stream method from the model directly, in which
case we will create a generator instance with the output type provided
and then invoke its stream method.
Thus, those commands are equivalent:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
backend
|
Optional[str]
|
The name of the backend to use to create the logits processor that
will be used to generate the response. Only used for steerable
models if |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the model. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[Any]
|
A stream of responses from the model. |
Source code in outlines/models/base.py
ModelTypeAdapter
Bases: ABC
Base class for all model type adapters.
A type adapter instance must be given as a value to the type_adapter
attribute when instantiating a model.
The type adapter is responsible for formatting the input and output types
passed to the model to match the specific format expected by the
associated model.
Source code in outlines/models/base.py
format_input(model_input)
abstractmethod
Format the user input to the expected format of the model.
For API-based models, it typically means creating the messages
argument passed to the client. For local models, it can mean casting
the input from str to list for instance.
This method is also used to validate that the input type provided by
the user is supported by the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Any
|
The input provided by the user. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The formatted input to be passed to the model. |
Source code in outlines/models/base.py
format_output_type(output_type=None)
abstractmethod
Format the output type to the expected format of the model.
For black-box models, this typically means creating a response_format
argument. For steerable models, it means formatting the logits processor
to create the object type expected by the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The formatted output type to be passed to the model. |
Source code in outlines/models/base.py
dottxt
Integration with Dottxt's API.
Dottxt
Bases: Model
Thin wrapper around the dottxt.client.Dottxt client.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the dottxt.client.Dottxt client.
Source code in outlines/models/dottxt.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 | |
__init__(client, model_name=None, model_revision=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Dottxt
|
A |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
model_revision
|
Optional[str]
|
The revision of the model to use. |
None
|
Source code in outlines/models/dottxt.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using Dottxt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The text generated by the model. |
Source code in outlines/models/dottxt.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Not available for Dottxt.
Source code in outlines/models/dottxt.py
DottxtTypeAdapter
Bases: ModelTypeAdapter
Type adapter for the Dottxt model.
Source code in outlines/models/dottxt.py
format_input(model_input)
Format the prompt to pass to the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str
|
The input provided by the user. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The input to pass to the client. |
Source code in outlines/models/dottxt.py
format_output_type(output_type=None)
Format the output type to pass to the client.
TODO: int, float and other Python types could be supported via
JSON Schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The output type to pass to the client. |
Source code in outlines/models/dottxt.py
from_dottxt(client, model_name=None, model_revision=None)
Create an Outlines Dottxt model instance from a dottxt.Dottxt
client instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Dottxt
|
A |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
model_revision
|
Optional[str]
|
The revision of the model to use. |
None
|
Returns:
| Type | Description |
|---|---|
Dottxt
|
An Outlines |
Source code in outlines/models/dottxt.py
gemini
Integration with Gemini's API.
Gemini
Bases: Model
Thin wrapper around the google.genai.Client client.
This wrapper is used to convert the input and output types specified by
the users at a higher level to arguments to the google.genai.Client
client.
Source code in outlines/models/gemini.py
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 349 350 351 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Client
|
A |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/gemini.py
generate(model_input, output_type=None, **inference_kwargs)
Generate a response from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema, a list of such types, or a multiple choice type. |
None
|
**inference_kwargs
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The response generated by the model. |
Source code in outlines/models/gemini.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Generate a stream of responses from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema, a list of such types, or a multiple choice type. |
None
|
**inference_kwargs
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/gemini.py
GeminiTypeAdapter
Bases: ModelTypeAdapter
Type adapter for the Gemini model.
GeminiTypeAdapter is responsible for preparing the arguments to Gemini's
client models.generate_content method: the input (prompt and possibly
image), as well as the output type (either JSON or multiple choice).
Source code in outlines/models/gemini.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 206 207 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 | |
format_chat_model_input(model_input)
Generate the contents argument to pass to the client when the user
passes a Chat instance.
Source code in outlines/models/gemini.py
format_input(model_input)
Generate the contents argument to pass to the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
The input provided by the user. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The |
Source code in outlines/models/gemini.py
format_output_type(output_type=None)
Generate the generation_config argument to pass to the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
The |
Source code in outlines/models/gemini.py
from_gemini(client, model_name=None)
Create an Outlines Gemini model instance from a
google.genai.Client instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Client
|
A |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Returns:
| Type | Description |
|---|---|
Gemini
|
An Outlines |
Source code in outlines/models/gemini.py
llamacpp
Integration with the llama-cpp-python library.
LlamaCpp
Bases: Model
Thin wrapper around the llama_cpp.Llama model.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the llama_cpp.Llama model.
Source code in outlines/models/llamacpp.py
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 | |
__init__(model)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Llama
|
A |
required |
Source code in outlines/models/llamacpp.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using llama-cpp-python.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The text generated by the model. |
Source code in outlines/models/llamacpp.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Stream text using llama-cpp-python.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/llamacpp.py
LlamaCppTokenizer
Bases: Tokenizer
Source code in outlines/models/llamacpp.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 | |
__getstate__()
Create a stable representation for outlines.caching
LlamaCppTypeAdapter
Bases: ModelTypeAdapter
Type adapter for the LlamaCpp model.
LlamaCppTypeAdapter is responsible for preparing the arguments to
the Llama object text generation methods.
Source code in outlines/models/llamacpp.py
format_input(model_input)
Generate the prompt argument to pass to the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
The input provided by the user. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formatted input to be passed to the model. |
Source code in outlines/models/llamacpp.py
format_output_type(output_type=None)
Generate the logits processor argument to pass to the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor provided. |
None
|
Returns:
| Type | Description |
|---|---|
LogitsProcessorList
|
The logits processor to pass to the model. |
Source code in outlines/models/llamacpp.py
from_llamacpp(model)
Create an Outlines LlamaCpp model instance from a
llama_cpp.Llama instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Llama
|
A |
required |
Returns:
| Type | Description |
|---|---|
LlamaCpp
|
An Outlines |
Source code in outlines/models/llamacpp.py
mistral
Integration with Mistral AI API.
AsyncMistral
Bases: AsyncModel
Async thin wrapper around the mistralai.Mistral client.
Converts input and output types to arguments for the mistralai.Mistral
client's async methods (chat.complete_async or chat.stream_async).
Source code in outlines/models/mistral.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Mistral
|
A mistralai.Mistral client instance. |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/mistral.py
generate(model_input, output_type=None, **inference_kwargs)
async
Generate a response from the model asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt or chat messages to generate a response from. |
required |
output_type
|
Optional[Any]
|
The desired format of the response (e.g., JSON schema). |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The response generated by the model as text. |
Source code in outlines/models/mistral.py
generate_stream(model_input, output_type=None, **inference_kwargs)
async
Generate text from the model as an async stream of chunks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str, list, or chat input to generate from. |
required | |
output_type
|
Optional type for structured output. |
None
|
|
**inference_kwargs
|
Extra kwargs like "model" name. |
{}
|
Yields:
| Type | Description |
|---|---|
str
|
Chunks of text as they are streamed. |
Source code in outlines/models/mistral.py
Mistral
Bases: Model
Thin wrapper around the mistralai.Mistral client.
Converts input and output types to arguments for the mistralai.Mistral
client's chat.complete or chat.stream methods.
Source code in outlines/models/mistral.py
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 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Mistral
|
A mistralai.Mistral client instance. |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/mistral.py
generate(model_input, output_type=None, **inference_kwargs)
Generate a response from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt or chat messages to generate a response from. |
required |
output_type
|
Optional[Any]
|
The desired format of the response (e.g., JSON schema). |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The response generated by the model as text. |
Source code in outlines/models/mistral.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Generate a stream of responses from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt or chat messages to generate a response from. |
required |
output_type
|
Optional[Any]
|
The desired format of the response (e.g., JSON schema). |
None
|
**inference_kwargs
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text chunks generated by the model. |
Source code in outlines/models/mistral.py
MistralTypeAdapter
Bases: ModelTypeAdapter
Type adapter for the Mistral model.
Prepares arguments for Mistral's client chat.complete,
chat.complete_async, or chat.stream methods. Handles input (prompt or
chat messages) and output type (JSON schema types).
Source code in outlines/models/mistral.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 206 207 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 | |
format_chat_model_input(model_input)
Format a Chat input into a list of messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Chat
|
The Chat object containing a list of message dictionaries. |
required |
Returns:
| Type | Description |
|---|---|
list
|
A list of Mistral message objects. |
Source code in outlines/models/mistral.py
format_input(model_input)
Generate the messages argument to pass to the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
The input provided by the user. |
required |
Returns:
| Type | Description |
|---|---|
list
|
The |
Source code in outlines/models/mistral.py
format_json_schema_type(schema, schema_name='default')
Create the response_format argument to pass to the client from a
JSON schema dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict
|
The JSON schema to format. |
required |
schema_name
|
str
|
The name of the schema. |
'default'
|
Returns:
| Type | Description |
|---|---|
dict
|
The value of the |
Source code in outlines/models/mistral.py
format_list_model_input(model_input)
Format a list input into a list of messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
list
|
The input list, containing a string prompt and optionally Image objects (vision models only). |
required |
Returns:
| Type | Description |
|---|---|
list
|
A list of Mistral message objects. |
Source code in outlines/models/mistral.py
format_output_type(output_type=None)
Generate the response_format argument to pass to the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
Optional[Any]
|
The desired output type provided by the user. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
The |
Source code in outlines/models/mistral.py
format_str_model_input(model_input)
Format a string input into a list of messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str
|
The input string prompt. |
required |
Returns:
| Type | Description |
|---|---|
list
|
A list of Mistral message objects. |
Source code in outlines/models/mistral.py
from_mistral(client, model_name=None, async_client=False)
Create an Outlines Mistral model instance from a mistralai.Mistral client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Mistral
|
A mistralai.Mistral client instance. |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
async_client
|
bool
|
If True, return an AsyncMistral instance; otherwise, return a Mistral instance. |
False
|
Returns:
| Type | Description |
|---|---|
Union[Mistral, AsyncMistral]
|
An Outlines Mistral or AsyncMistral model instance. |
Source code in outlines/models/mistral.py
mlxlm
Integration with the mlx_lm library.
MLXLM
Bases: Model
Thin wrapper around an mlx_lm model.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the mlx_lm library.
Source code in outlines/models/mlxlm.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 206 207 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 | |
__init__(model, tokenizer)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
An instance of an |
required |
tokenizer
|
PreTrainedTokenizer
|
An instance of an |
required |
Source code in outlines/models/mlxlm.py
generate(model_input, output_type=None, **kwargs)
Generate text using mlx-lm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
kwargs
|
Additional keyword arguments to pass to the |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The text generated by the model. |
Source code in outlines/models/mlxlm.py
generate_batch(model_input, output_type=None, **kwargs)
Generate a batch of text using mlx-lm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
list[str]
|
The list of prompts based on which the model will generate a response. |
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
kwargs
|
Additional keyword arguments to pass to the |
{}
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The list of text generated by the model. |
Source code in outlines/models/mlxlm.py
generate_stream(model_input, output_type=None, **kwargs)
Stream text using mlx-lm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
str
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
kwargs
|
Additional keyword arguments to pass to the |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/mlxlm.py
MLXLMTypeAdapter
Bases: ModelTypeAdapter
Type adapter for the MLXLM model.
Source code in outlines/models/mlxlm.py
format_input(model_input)
Generate the prompt argument to pass to the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
The input provided by the user. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formatted input to be passed to the model. |
Source code in outlines/models/mlxlm.py
format_output_type(output_type=None)
Generate the logits processor argument to pass to the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor provided. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[list[OutlinesLogitsProcessor]]
|
The logits processor argument to be passed to the model. |
Source code in outlines/models/mlxlm.py
from_mlxlm(model, tokenizer)
Create an Outlines MLXLM model instance from an mlx_lm model and a
tokenizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
An instance of an |
required |
tokenizer
|
PreTrainedTokenizer
|
An instance of an |
required |
Returns:
| Type | Description |
|---|---|
MLXLM
|
An Outlines |
Source code in outlines/models/mlxlm.py
ollama
Integration with the ollama library.
AsyncOllama
Bases: AsyncModel
Thin wrapper around the ollama.AsyncClient client.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the ollama.AsyncClient client.
Source code in outlines/models/ollama.py
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 349 350 351 352 353 354 355 356 357 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
AsyncClient
|
The |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/ollama.py
generate(model_input, output_type=None, **kwargs)
async
Generate text using Ollama.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Chat | str | list
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The text generated by the model. |
Source code in outlines/models/ollama.py
generate_stream(model_input, output_type=None, **kwargs)
async
Stream text using Ollama.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Chat | str | list
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/ollama.py
Ollama
Bases: Model
Thin wrapper around the ollama.Client client.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the ollama.Client client.
Source code in outlines/models/ollama.py
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 206 207 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 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Client
|
The |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/ollama.py
generate(model_input, output_type=None, **kwargs)
Generate text using Ollama.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Chat | str | list
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The text generated by the model. |
Source code in outlines/models/ollama.py
generate_stream(model_input, output_type=None, **kwargs)
Stream text using Ollama.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Chat | str | list
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/ollama.py
OllamaTypeAdapter
Bases: ModelTypeAdapter
Type adapter for the Ollama model.
Source code in outlines/models/ollama.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 | |
format_chat_model_input(model_input)
Generate the value of the messages argument to pass to the
client when the user passes a Chat instance.
Source code in outlines/models/ollama.py
format_input(model_input)
Generate the value of the messages argument to pass to the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
The input provided by the user. |
required |
Returns:
| Type | Description |
|---|---|
list
|
The formatted value of the |
Source code in outlines/models/ollama.py
format_list_model_input(model_input)
Generate the value of the messages argument to pass to the
client when the user passes a prompt and images.
Source code in outlines/models/ollama.py
format_output_type(output_type=None)
Format the output type to pass to the client.
TODO: int, float and other Python types could be supported via
JSON Schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The formatted output type to be passed to the model. |
Source code in outlines/models/ollama.py
format_str_model_input(model_input)
Generate the value of the messages argument to pass to the
client when the user only passes a prompt.
Source code in outlines/models/ollama.py
from_ollama(client, model_name=None)
Create an Outlines Ollama model instance from an ollama.Client
or ollama.AsyncClient instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Union[Client, AsyncClient]
|
A |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Returns:
| Type | Description |
|---|---|
Union[Ollama, AsyncOllama]
|
An Outlines |
Source code in outlines/models/ollama.py
openai
Integration with OpenAI's API.
AsyncOpenAI
Bases: AsyncModel
Thin wrapper around the openai.AsyncOpenAI client.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the openai.AsyncOpenAI client.
Source code in outlines/models/openai.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Union[AsyncOpenAI, AsyncAzureOpenAI]
|
The |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/openai.py
generate(model_input, output_type=None, **inference_kwargs)
async
Generate text using OpenAI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Union[type[BaseModel], str]]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema or an empty dictionary. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The text generated by the model. |
Source code in outlines/models/openai.py
generate_stream(model_input, output_type=None, **inference_kwargs)
async
Stream text using OpenAI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Union[type[BaseModel], str]]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema or an empty dictionary. |
None
|
**inference_kwargs
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/openai.py
OpenAI
Bases: Model
Thin wrapper around the openai.OpenAI client.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the openai.OpenAI client.
Source code in outlines/models/openai.py
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 349 350 351 352 353 354 355 356 357 358 359 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Union[OpenAI, AzureOpenAI]
|
The |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/openai.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using OpenAI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Union[type[BaseModel], str]]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema or an empty dictionary. |
None
|
**inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The text generated by the model. |
Source code in outlines/models/openai.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Stream text using OpenAI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Union[type[BaseModel], str]]
|
The desired format of the response generated by the model. The output type must be of a type that can be converted to a JSON schema or an empty dictionary. |
None
|
**inference_kwargs
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/openai.py
OpenAITypeAdapter
Bases: ModelTypeAdapter
Type adapter for the OpenAI model.
OpenAITypeAdapter is responsible for preparing the arguments to OpenAI's
completions.create methods: the input (prompt and possibly image), as
well as the output type (only JSON).
Source code in outlines/models/openai.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 206 207 208 209 | |
format_chat_model_input(model_input)
Generate the value of the messages argument to pass to the
client when the user passes a Chat instance.
Source code in outlines/models/openai.py
format_input(model_input)
Generate the messages argument to pass to the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
The input provided by the user. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The formatted input to be passed to the client. |
Source code in outlines/models/openai.py
format_json_mode_type()
Generate the response_format argument to the client when the user
specified the output type should be a JSON but without specifying the
schema (also called "JSON mode").
Source code in outlines/models/openai.py
format_json_output_type(schema)
Generate the response_format argument to the client when the user
specified a Json output type.
Source code in outlines/models/openai.py
format_list_model_input(model_input)
Generate the value of the messages argument to pass to the
client when the user passes a prompt and images.
Source code in outlines/models/openai.py
format_output_type(output_type=None)
Generate the response_format argument to the client based on the
output type specified by the user.
TODO: int, float and other Python types could be supported via
JSON Schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_type
|
Optional[Any]
|
The output type provided by the user. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
The formatted output type to be passed to the client. |
Source code in outlines/models/openai.py
format_str_model_input(model_input)
Generate the value of the messages argument to pass to the
client when the user only passes a prompt.
Source code in outlines/models/openai.py
from_openai(client, model_name=None)
Create an Outlines OpenAI or AsyncOpenAI model instance from an
openai.OpenAI or openai.AsyncOpenAI client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Union[OpenAI, AsyncOpenAI, AzureOpenAI, AsyncAzureOpenAI]
|
An |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Returns:
| Type | Description |
|---|---|
OpenAI
|
An Outlines |
Source code in outlines/models/openai.py
sglang
Integration with an SGLang server.
AsyncSGLang
Bases: AsyncModel
Thin async wrapper around the openai.OpenAI client used to communicate
with an SGLang server.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the openai.OpenAI client for the
SGLang server.
Source code in outlines/models/sglang.py
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 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
An |
required | |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
An |
required |
Source code in outlines/models/sglang.py
generate(model_input, output_type=None, **inference_kwargs)
async
Generate text using sglang.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, str, list]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All output types available in Outlines are supported provided your server uses a structured generation backend that supports them. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The text generated by the model. |
Source code in outlines/models/sglang.py
generate_stream(model_input, output_type=None, **inference_kwargs)
async
Return a text generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, str, list]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All output types available in Outlines are supported provided your server uses a structured generation backend that supports them. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
AsyncIterator[str]
|
An async iterator that yields the text generated by the model. |
Source code in outlines/models/sglang.py
SGLang
Bases: Model
Thin wrapper around the openai.OpenAI client used to communicate with
an SGLang server.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the openai.OpenAI client for the
SGLang server.
Source code in outlines/models/sglang.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
__init__(client, model_name=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
An |
required | |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Source code in outlines/models/sglang.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using SGLang.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All output types available in Outlines are supported provided your server uses a structured generation backend that supports them. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[str, list[str]]
|
The text generated by the model. |
Source code in outlines/models/sglang.py
generate_stream(model_input, output_type=None, **inference_kwargs)
Stream text using SGLang.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[Any]
|
The desired format of the response generated by the model. All output types available in Outlines are supported provided your server uses a structured generation backend that supports them. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the client. |
{}
|
Returns:
| Type | Description |
|---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/sglang.py
SGLangTypeAdapter
Bases: ModelTypeAdapter
Type adapter for the SGLang and AsyncSGLang models.
Source code in outlines/models/sglang.py
format_input(model_input)
Generate the value of the messages argument to pass to the client.
We rely on the OpenAITypeAdapter to format the input as the sglang server expects input in the same format as OpenAI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_input
|
Union[Chat, list, str]
|
The input passed by the user. |
required |
Returns:
| Type | Description |
|---|---|
list
|
The formatted input to be passed to the client. |