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 |