You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/models/openai.md
+40-10Lines changed: 40 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,30 +2,29 @@
2
2
3
3
!!! Installation
4
4
5
-
You need to install the `openai` and `tiktoken` libraries to be able to use the OpenAI API in Outlines.
5
+
You need to install the `openai` library to be able to use the OpenAI API in Outlines.
6
6
7
7
## OpenAI models
8
8
9
-
Outlines supports models available via the OpenAI Chat API, e.g. ChatGPT and GPT-4. You can initialize the model by passing the model name to `outlines.models.openai`:
9
+
Outlines supports models available via the OpenAI Chat API, e.g. GPT-4o, ChatGPT and GPT-4. You can initialize the model by passing the model name to `outlines.models.openai`:
10
10
11
11
```python
12
12
from outlines import models
13
13
14
14
15
-
model = models.openai("gpt-3.5-turbo")
16
-
model = models.openai("gpt-4-turbo")
15
+
model = models.openai("gpt-4o-mini")
17
16
model = models.openai("gpt-4o")
18
17
```
19
18
20
-
Check the [OpenAI documentation](https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4) for an up-to-date list of available models. You can pass any parameter you would pass to `openai.AsyncOpenAI` as keyword arguments:
19
+
Check the [OpenAI documentation](https://platform.openai.com/docs/models/gpt-4o) for an up-to-date list of available models. You can pass any parameter you would pass to `openai.AsyncOpenAI` as keyword arguments:
@@ -111,6 +110,37 @@ model = models.openai(client, config)
111
110
112
111
You need to pass the async client to be able to do batch inference.
113
112
113
+
## Structured Generation Support
114
+
115
+
Outlines provides support for [OpenAI Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs/json-mode) via `outlines.generate.json`, `outlines.generate.choice`
116
+
117
+
```python
118
+
from pydantic import BaseModel, ConfigDict
119
+
import outlines.models as models
120
+
from outlines import generate
121
+
122
+
model = models.openai("gpt-4o-mini")
123
+
124
+
classPerson(BaseModel):
125
+
model_config = ConfigDict(extra='forbid') # required for openai
126
+
first_name: str
127
+
last_name: str
128
+
age: int
129
+
130
+
generate.json(model, Person)
131
+
generator("current indian prime minister on january 1st 2023")
Structured generation support only provided to OpenAI-compatible endpoints which conform to OpenAI's standard. Additionally, `generate.regex` and `generate.cfg` are not supported.
142
+
143
+
114
144
## Advanced configuration
115
145
116
146
For more advanced configuration option, such as support proxy, please consult the [OpenAI SDK's documentation](https://github.com/openai/openai-python):
@@ -146,7 +176,7 @@ config = OpenAIConfig(
146
176
top_p=.95,
147
177
seed=0,
148
178
)
149
-
model = models.openai("gpt-3.5-turbo", config)
179
+
model = models.openai("gpt-4o-mini", config)
150
180
```
151
181
152
182
## Monitoring API use
@@ -158,7 +188,7 @@ from openai import AsyncOpenAI
0 commit comments