@ljoukov/llm 7.0.11 → 7.0.13
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 +42 -4
- package/dist/index.cjs +447 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +113 -23
- package/dist/index.d.ts +113 -23
- package/dist/index.js +433 -19
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -182,6 +182,42 @@ 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
|
+
|
|
185
221
|
### Streaming (response + thoughts + usage)
|
|
186
222
|
|
|
187
223
|
```ts
|
|
@@ -628,20 +664,22 @@ Architecture note:
|
|
|
628
664
|
|
|
629
665
|
### Provider-Native Tools (`generateText()`)
|
|
630
666
|
|
|
631
|
-
Use this when the model provider executes the tool remotely (for example search/code-exec style tools).
|
|
667
|
+
Use this when the model provider executes the tool remotely (for example search/code-exec/shell style tools).
|
|
632
668
|
|
|
633
669
|
```ts
|
|
634
670
|
import { generateText } from "@ljoukov/llm";
|
|
635
671
|
|
|
636
672
|
const result = await generateText({
|
|
637
|
-
model: "gpt-5.
|
|
638
|
-
input: "
|
|
639
|
-
tools: [{ type: "
|
|
673
|
+
model: "gpt-5.5",
|
|
674
|
+
input: "Run python --version in a hosted shell and summarize the result.",
|
|
675
|
+
tools: [{ type: "shell" }],
|
|
640
676
|
});
|
|
641
677
|
|
|
642
678
|
console.log(result.text);
|
|
643
679
|
```
|
|
644
680
|
|
|
681
|
+
`{ type: "shell" }` uses OpenAI hosted shell containers by default. It is only supported for OpenAI API models; ChatGPT-authenticated, Gemini, and Fireworks providers reject it.
|
|
682
|
+
|
|
645
683
|
### Runtime Tools (`runToolLoop()`)
|
|
646
684
|
|
|
647
685
|
Use this when the model should call your local runtime functions.
|