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
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
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 |
|
__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[str, Vision]
|
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[str, Vision]
|
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
format_input(model_input)
Generate the messages
argument to pass to the client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_input
|
Union[str, Vision]
|
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 a shared __call__
method that can be used to call the
model directly.
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
method to format the input and output
types received by the model.
Additionally, local models must define a tensor_library_name
attribute.
Source code in outlines/models/base.py
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 |
|
__call__(model_input, output_type=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
|
**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(model_input, output_type=None, **inference_kwargs)
abstractmethod
async
Generate a response from the model.
The output_type argument contains a logits processor for local models while it contains a type (Json, Enum...) for the API-based 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_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 local models while it contains a type (Json, Enum...) for the API-based 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, **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
|
**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 a shared __call__
method that can be used to call the
model directly.
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
method to format the input and output
types received by the model.
Additionally, local 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 |
|
__call__(model_input, output_type=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
|
**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(model_input, output_type=None, **inference_kwargs)
abstractmethod
Generate a response from the model.
The output_type argument contains a logits processor for local models while it contains a type (Json, Enum...) for the API-based 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_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 local models while it contains a type (Json, Enum...) for the API-based 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, **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
|
**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 API-based models, this typically means creating a response_format
argument. For local 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
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 |
|
__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
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 |
|
__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[str, Vision]
|
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[str, Vision]
|
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
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 |
|
format_input(model_input)
Generate the contents
argument to pass to the client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_input
|
Union[str, Vision]
|
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
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 306 307 308 309 310 |
|
__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
|
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
|
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
load_lora(adapter_path)
Load a LoRA adapter. Deprecated since v1.0.0.
Source code in outlines/models/llamacpp.py
LlamaCppTokenizer
Bases: Tokenizer
Source code in outlines/models/llamacpp.py
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 |
|
__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
llama-cpp-python
's Llama.__call__
method: the input (a string prompt),
as well as the logits processor (an instance of LogitsProcessorList
).
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
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
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 |
|
__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_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.
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
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 |
|
__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
|
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
|
**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
|
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
|
**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
format_input(model_input)
Generate the prompt argument to pass to the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_input
|
str
|
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/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
from_ollama(client, model_name=None)
Create an Outlines Ollama
model instance from an ollama.Client
client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
Client
|
A |
required |
model_name
|
Optional[str]
|
The name of the model to use. |
None
|
Returns:
Type | Description |
---|---|
Ollama
|
An Outlines |
Source code in outlines/models/ollama.py
openai
Integration with OpenAI's API.
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
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 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 |
|
__init__(client, model_name=None, **kwargs)
Initialize the OpenAI model.
To provide temporary backwards compatibility with Outlines v0,
the class can be instantiated with a OpenAIConfig
instance as
a value for the model_name
argument. This is deprecated and will
be removed in v1.1.0. Please provide a model name instead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
Union[OpenAI, AzureOpenAI]
|
The |
required |
model_name
|
Optional[Union[str, OpenAIConfig]]
|
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[str, Vision]
|
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[str, Vision]
|
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
OpenAIConfig
dataclass
Represents the parameters of the OpenAI API.
The information was last fetched on 2023/11/20. We document below the properties that are specific to the OpenAI API. Not all these properties are supported by Outlines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
The name of the model. Available models can be found on OpenAI's website. |
''
|
frequency_penalty
|
float
|
Number between 2.0 and -2.0. Positive values penalize new tokens based on their existing frequency in the text, |
0
|
logit_bias
|
Dict[int, int]
|
Modifies the likelihood of specified tokens to appear in the completion. Number between -100 (forbid) and +100 (only allows). |
dict()
|
n
|
int
|
The number of completions to return for each prompt. |
1
|
presence_penalty
|
float
|
Similar to frequency penalty. |
0
|
response_format
|
Optional[Dict[str, str]]
|
Specifies the format the model must output. |
None
|
seed
|
Optional[int]
|
Two completions with the same |
None
|
stop
|
Optional[Union[str, List[str]]]
|
Up to 4 words where the API will stop the completion. |
None
|
temperature
|
float
|
Number between 0 and 2. Higher values make the output more random, while lower values make it more deterministic. |
1.0
|
top_p
|
int
|
Number between 0 and 1. Parameter for nucleus sampling. |
1
|
user
|
str
|
A unique identifier for the end-user. |
str()
|
Source code in outlines/models/openai.py
OpenAILegacy
An object that represents the OpenAI API.
Source code in outlines/models/openai.py
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 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
|
__call__(prompt, max_tokens=None, stop_at=None, *, system_prompt=None, temperature=None, samples=None)
Call the OpenAI API to generate text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
Union[str, List[str]]
|
A string or list of strings that will be used to prompt the model |
required |
max_tokens
|
Optional[int]
|
The maximum number of tokens to generate |
None
|
stop_at
|
Optional[Union[List[str], str]]
|
A string or array of strings which, such that the generation stops when they are generated. |
None
|
system_prompt
|
Optional[str]
|
The content of the system message that precedes the user's prompt. |
None
|
temperature
|
Optional[float]
|
The value of the temperature used to sample tokens |
None
|
samples
|
Optional[int]
|
The number of completions to generate for each prompt |
None
|
stop_at
|
Optional[Union[List[str], str]]
|
Up to 4 words where the API will stop the completion. |
None
|
Source code in outlines/models/openai.py
__init__(client, config, system_prompt=None)
Create an OpenAI
instance.
This class supports the standard OpenAI API, the Azure OpeanAI API as well as compatible APIs that rely on the OpenAI client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
An instance of the API's async client. |
required | |
config
|
An instance of |
required |
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
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 |
|
format_input(model_input)
Generate the messages
argument to pass to the client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_input
|
Union[str, Vision]
|
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_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 messages
argument to pass to the client when the user
only passes a prompt.
Source code in outlines/models/openai.py
format_vision_model_input(model_input)
Generate the messages
argument to pass to the client when the user
passes a prompt and an image.
Source code in outlines/models/openai.py
error_handler(api_call_fn)
Handle OpenAI API errors and missing API key.
Source code in outlines/models/openai.py
from_openai(client, model_name=None)
Create an Outlines OpenAI
model instance from an openai.OpenAI
client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
Union[OpenAI, AzureOpenAI]
|
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
generate_chat(prompt, system_prompt, client, config)
async
Call OpenAI's Chat Completion API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
str
|
The prompt we use to start the generation. Passed to the model with the "user" role. |
required |
system_prompt
|
Union[str, None]
|
The system prompt, passed to the model with the "system" role before the prompt. |
required |
client
|
The API client |
required | |
config
|
OpenAIConfig
|
An |
required |
Returns:
Type | Description |
---|---|
A tuple that contains the model's response(s) and usage statistics.
|
|
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
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 |
|
__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[str, Vision]
|
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[str, Vision]
|
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
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
|
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[str, Vision]
|
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[str, Vision]
|
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 prompt 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[str, Vision]
|
The input passed by the user. |
required |
Returns:
Type | Description |
---|---|
dict
|
The formatted input to be passed to the client. |
Source code in outlines/models/sglang.py
format_output_type(output_type=None)
Generate the structured output argument to pass to the client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_type
|
Optional[Any]
|
The structured output type provided. |
None
|
Returns:
Type | Description |
---|---|
dict
|
The formatted output type to be passed to the client. |
Source code in outlines/models/sglang.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
tgi
Integration with a TGI server.
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
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 |
|
__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
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
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 |
|
__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
TGITypeAdapter
Bases: ModelTypeAdapter
Type adapter for the TGI
and AsyncTGI
models.
Source code in outlines/models/tgi.py
format_input(model_input)
Generate the prompt argument to pass to the client.
Argument
model_input The input passed by the user.
Returns:
Type | Description |
---|---|
str
|
The formatted input to be passed to the model. |
Source code in outlines/models/tgi.py
format_output_type(output_type=None)
Generate the structured output argument to pass to the client.
Argument
output_type The structured output type provided.
Returns:
Type | Description |
---|---|
dict
|
The structured output argument to pass to the client. |
Source code in outlines/models/tgi.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
tokenizer
Tokenizer
Bases: Hashable
, Protocol
Source code in outlines/models/tokenizer.py
convert_token_to_string(token)
Convert a token to its equivalent string.
This is for instance useful for BPE tokenizers where whitespaces are
represented by the special characted Ġ
. This prevents matching a raw
token that includes Ġ
with a string.
Source code in outlines/models/tokenizer.py
decode(token_ids)
encode(prompt)
Translate the input prompts into arrays of token ids and attention mask.
transformers
Integration with the transformers
library.
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
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 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 |
|
__init__(model, tokenizer)
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.
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, List[str], dict]
|
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_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
__init__(model, processor)
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 vision
models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
PreTrainedModel
|
A |
required |
processor
|
A |
required |
Source code in outlines/models/transformers.py
TransformersMultiModalTypeAdapter
Bases: ModelTypeAdapter
Type adapter for TransformersMultiModal
model.
Source code in outlines/models/transformers.py
format_input(model_input)
Generate the prompt arguments to pass to the model.
Argument
model_input The input passed by the user.
Returns:
Type | Description |
---|---|
dict
|
The formatted input to be passed to the model. |
Source code in outlines/models/transformers.py
format_output_type(output_type=None)
Generate the logits processor argument to pass to the model.
Argument
output_type The logits processor provided.
Returns:
Type | Description |
---|---|
Optional[LogitsProcessorList]
|
The logits processor to pass to the model. |
Source code in outlines/models/transformers.py
TransformersTypeAdapter
Bases: ModelTypeAdapter
Type adapter for the Transformers
model.
Source code in outlines/models/transformers.py
format_input(model_input)
Generate the prompt argument to pass to the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_input
|
The input passed by the user. |
required |
Returns:
Type | Description |
---|---|
str
|
The formatted input to be passed to the model. |
Source code in outlines/models/transformers.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[LogitsProcessorList]
|
The logits processor to pass to the model. |
Source code in outlines/models/transformers.py
from_transformers(model, tokenizer_or_processor)
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 |
Returns:
Type | Description |
---|---|
Union[Transformers, TransformersMultiModal]
|
An Outlines |
Source code in outlines/models/transformers.py
get_llama_tokenizer_types()
Get all the Llama tokenizer types/classes that need work-arounds.
When they can't be imported, a dummy class is created.
Source code in outlines/models/transformers.py
vllm
Integration with a vLLM server.
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
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 |
|
__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[str, Vision]
|
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[str, Vision]
|
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
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 |
|
__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[str, Vision]
|
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[str, Vision]
|
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
VLLMTypeAdapter
Bases: ModelTypeAdapter
Type adapter for the VLLM
and AsyncVLLM
models.
Source code in outlines/models/vllm.py
format_input(model_input)
Generate the prompt argument to pass to the client.
We rely on the OpenAITypeAdapter to format the input as the vLLM server expects input in the same format as OpenAI.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_input
|
Union[str, Vision]
|
The input passed by the user. |
required |
Returns:
Type | Description |
---|---|
dict
|
The formatted input to be passed to the model. |
Source code in outlines/models/vllm.py
format_output_type(output_type=None)
Generate the structured output argument to pass to the client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_type
|
Optional[Any]
|
The structured output type provided. |
None
|
Returns:
Type | Description |
---|---|
dict
|
The structured output argument to pass to the model. |
Source code in outlines/models/vllm.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
vllm_offline
Integration with the vllm
library (offline mode).
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
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 |
|
__init__(model)
Create a VLLM model instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
LLM
|
A |
required |
Source code in outlines/models/vllm_offline.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using vLLM.
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], 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
load_lora(adapter_path)
Load a LoRA adapter. Deprecated since v1.0.0.
Use the lora_request
argument when calling the model or generator
instead.
Source code in outlines/models/vllm_offline.py
VLLMOfflineTypeAdapter
Bases: ModelTypeAdapter
Type adapter for the VLLMOffline
model.
Source code in outlines/models/vllm_offline.py
format_input(model_input)
Generate the prompt argument to pass to the model.
Argument
model_input The input passed by the user.
Source code in outlines/models/vllm_offline.py
format_output_type(output_type=None)
Generate the structured output argument to pass to the model.
For vLLM, the structured output definition is set in the
GuidedDecodingParams
constructor that is provided as a value to the
guided_decoding
parameter of the SamplingParams
constructor, itself
provided as a value to the sampling_params
parameter of the generate
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_type
|
Optional[Any]
|
The structured output type provided. |
None
|
Returns:
Type | Description |
---|---|
dict
|
The arguments to provide to the |
Source code in outlines/models/vllm_offline.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 |