@ljoukov/llm 7.0.12 → 7.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -3
- package/dist/index.cjs +572 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +94 -23
- package/dist/index.d.ts +94 -23
- package/dist/index.js +555 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -182,6 +182,59 @@ console.log(result.text);
|
|
|
182
182
|
console.log(result.usage, result.costUsd);
|
|
183
183
|
```
|
|
184
184
|
|
|
185
|
+
### Image Generation
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import {
|
|
189
|
+
generateImages,
|
|
190
|
+
type LlmOpenAiImageResolution,
|
|
191
|
+
OPENAI_GPT_IMAGE_2_QUALITY_LEVELS,
|
|
192
|
+
OPENAI_GPT_IMAGE_2_RESOLUTIONS,
|
|
193
|
+
OPENAI_GPT_IMAGE_2_SIZE_CONSTRAINTS,
|
|
194
|
+
} from "@ljoukov/llm";
|
|
195
|
+
|
|
196
|
+
const customResolution = "1440x960" satisfies LlmOpenAiImageResolution;
|
|
197
|
+
|
|
198
|
+
const images = await generateImages({
|
|
199
|
+
model: "gpt-image-2",
|
|
200
|
+
stylePrompt: "Warm amber desk light, deep blue night, cinematic laboratory mood.",
|
|
201
|
+
imagePrompts: ["A compact lab bench still life with glassware and an open notebook"],
|
|
202
|
+
imageResolution: customResolution,
|
|
203
|
+
imageQuality: "low",
|
|
204
|
+
numImages: 1,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
console.log(OPENAI_GPT_IMAGE_2_RESOLUTIONS, OPENAI_GPT_IMAGE_2_QUALITY_LEVELS);
|
|
208
|
+
console.log(OPENAI_GPT_IMAGE_2_SIZE_CONSTRAINTS);
|
|
209
|
+
console.log(images[0]?.mimeType, images[0]?.data.byteLength);
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`generateImages()` is typed as a discriminated union by `model`: `gpt-image-2` requests use
|
|
213
|
+
`imageResolution`, while Gemini image requests use `imageSize` (`"1K" | "2K" | "4K"`). For
|
|
214
|
+
`gpt-image-2`, `OPENAI_GPT_IMAGE_2_RESOLUTIONS` exposes the documented popular presets plus
|
|
215
|
+
`"auto"`; custom literal `WIDTHxHEIGHT` resolutions are also accepted when they satisfy
|
|
216
|
+
`OPENAI_GPT_IMAGE_2_SIZE_CONSTRAINTS`: each edge must be at most 3840px, each edge must be a
|
|
217
|
+
multiple of 16px, the long edge must be at most 3:1 relative to the short edge, and total pixels
|
|
218
|
+
must be between 655,360 and 8,294,400. Resolutions above 3,686,400 pixels are documented as
|
|
219
|
+
experimental by OpenAI.
|
|
220
|
+
|
|
221
|
+
To use ChatGPT/Codex subscription-backed image generation instead of the public Images API, use
|
|
222
|
+
`chatgpt-gpt-image-2`:
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
const images = await generateImages({
|
|
226
|
+
model: "chatgpt-gpt-image-2",
|
|
227
|
+
stylePrompt: "Warm amber desk light, deep blue night, cinematic laboratory mood.",
|
|
228
|
+
imagePrompts: ["A compact lab bench still life with glassware and an open notebook"],
|
|
229
|
+
numImages: 1,
|
|
230
|
+
});
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
That path reuses the same ChatGPT auth setup as other `chatgpt-*` models and sends the request
|
|
234
|
+
through the ChatGPT/Codex Responses `image_generation` built-in tool. It returns PNG images. The
|
|
235
|
+
public Images API controls such as `imageResolution`, `imageQuality`, `outputFormat`, and
|
|
236
|
+
`outputCompression` are intentionally only on the `gpt-image-2` request type.
|
|
237
|
+
|
|
185
238
|
### Streaming (response + thoughts + usage)
|
|
186
239
|
|
|
187
240
|
```ts
|
|
@@ -459,10 +512,12 @@ console.log(result.text);
|
|
|
459
512
|
|
|
460
513
|
`gpt-5.5-fast` and `chatgpt-gpt-5.5-fast` are also supported as convenience aliases for `gpt-5.5` with priority processing enabled (`service_tier="priority"`), matching Codex `/fast` semantics.
|
|
461
514
|
|
|
462
|
-
Supported OpenAI
|
|
515
|
+
Supported OpenAI and ChatGPT model ids are fixed literal unions in code, not arbitrary strings:
|
|
463
516
|
|
|
464
|
-
- OpenAI API: `gpt-5.5`, `gpt-5.5-fast`, `gpt-5.4`, `gpt-5.4-mini`, `gpt-5.4-nano`
|
|
465
|
-
-
|
|
517
|
+
- OpenAI API text: `gpt-5.5`, `gpt-5.5-fast`, `gpt-5.4`, `gpt-5.4-mini`, `gpt-5.4-nano`
|
|
518
|
+
- OpenAI API image: `gpt-image-2`
|
|
519
|
+
- ChatGPT auth text: `chatgpt-gpt-5.5`, `chatgpt-gpt-5.5-fast`, `chatgpt-gpt-5.4`, `chatgpt-gpt-5.4-fast`, `chatgpt-gpt-5.4-mini`, `chatgpt-gpt-5.3-codex-spark`
|
|
520
|
+
- ChatGPT auth image: `chatgpt-gpt-image-2`
|
|
466
521
|
|
|
467
522
|
## JSON outputs
|
|
468
523
|
|