@aigne/openai 0.16.5-beta.1 → 0.16.5-beta.2

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +223 -1
  3. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.16.5-beta.2](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.16.5-beta.1...openai-v0.16.5-beta.2) (2025-11-04)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **docs:** update video mode docs ([#695](https://github.com/AIGNE-io/aigne-framework/issues/695)) ([d691001](https://github.com/AIGNE-io/aigne-framework/commit/d69100169457c16c14f2f3e2f7fcd6b2a99330f3))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @aigne/core bumped to 1.65.1-beta.2
16
+ * devDependencies
17
+ * @aigne/test-utils bumped to 0.5.58-beta.2
18
+
3
19
  ## [0.16.5-beta.1](https://github.com/AIGNE-io/aigne-framework/compare/openai-v0.16.5-beta...openai-v0.16.5-beta.1) (2025-11-04)
4
20
 
5
21
 
package/README.md CHANGED
@@ -57,7 +57,9 @@ yarn add @aigne/openai @aigne/core
57
57
  pnpm add @aigne/openai @aigne/core
58
58
  ```
59
59
 
60
- ## Basic Usage
60
+ ## Chat Completions
61
+
62
+ ### Basic Usage
61
63
 
62
64
  ```typescript file="test/openai-chat-model.test.ts" region="example-openai-chat-model"
63
65
  import { OpenAIChatModel } from "@aigne/openai";
@@ -88,6 +90,37 @@ console.log(result);
88
90
  */
89
91
  ```
90
92
 
93
+ ### OpenAIChatModel Input
94
+
95
+ - `messages` (array, required): Conversation messages
96
+ - Each message has: `role` ("user" | "assistant" | "system" | "tool"), `content` (string or multimodal array)
97
+ - Multimodal content supports: text, images (url/base64), files
98
+ - `tools` (array, optional): Available function tools for the model to call
99
+ - Each tool has: `type: "function"`, `function` with `name`, `description`, `parameters` (JSON schema)
100
+ - `toolChoice` (string/object, optional): Control tool usage - "auto", "required", "none", or specific tool
101
+ - `responseFormat` (object, optional): Control output format
102
+ - `type: "json_schema"` with `jsonSchema` for structured JSON output
103
+ - `model` (string, optional): Model to use (e.g., "gpt-4o", "gpt-4o-mini", "o1", "o3-mini")
104
+ - `temperature` (number, optional): Sampling temperature (0-2), controls randomness
105
+ - `topP` (number, optional): Nucleus sampling parameter (0-1), alternative to temperature
106
+ - `frequencyPenalty` (number, optional): Frequency penalty (-2 to 2), reduces repetition
107
+ - `presencePenalty` (number, optional): Presence penalty (-2 to 2), encourages topic diversity
108
+ - `parallelToolCalls` (boolean, optional): Enable parallel tool calls (default: true)
109
+ - `reasoningEffort` (string/number, optional): For reasoning models (o1/o3) - "minimal", "low", "medium", "high" or token count
110
+
111
+ ### OpenAIChatModel Output
112
+
113
+ - `text` (string, optional): Generated text response
114
+ - `toolCalls` (array, optional): Function calls requested by the model
115
+ - Each call has: `id`, `type: "function"`, `function` with `name` and `arguments` (parsed JSON)
116
+ - `json` (object, optional): Structured JSON output (when using `responseFormat`)
117
+ - `usage` (object): Token usage statistics
118
+ - `inputTokens` (number): Input tokens consumed
119
+ - `outputTokens` (number): Output tokens generated
120
+ - `model` (string): Actual model used for the request
121
+ - `modelOptions` (object, optional): Model options used
122
+ - `reasoningEffort` (string, optional): Reasoning effort applied
123
+
91
124
  ## Streaming Responses
92
125
 
93
126
  ```typescript file="test/openai-chat-model.test.ts" region="example-openai-chat-model-stream"
@@ -121,6 +154,195 @@ console.log(fullText); // Output: "Hello! How can I assist you today?"
121
154
  console.log(json); // { model: "gpt-4o", usage: { inputTokens: 10, outputTokens: 9 } }
122
155
  ```
123
156
 
157
+ ## Image Generation
158
+
159
+ Use `OpenAIImageModel` to generate or edit images with DALL-E models.
160
+
161
+ ### Basic Image Generation
162
+
163
+ ```typescript
164
+ import { OpenAIImageModel } from "@aigne/openai";
165
+
166
+ const imageModel = new OpenAIImageModel({
167
+ apiKey: "your-api-key",
168
+ model: "dall-e-3", // or "dall-e-2", "gpt-image-1"
169
+ modelOptions: {
170
+ size: "1024x1024",
171
+ quality: "standard", // or "hd" for dall-e-3
172
+ style: "vivid", // or "natural"
173
+ },
174
+ });
175
+
176
+ const result = await imageModel.invoke({
177
+ prompt: "A futuristic city at sunset with flying cars",
178
+ });
179
+
180
+ console.log(result);
181
+ /* Output:
182
+ {
183
+ images: [
184
+ {
185
+ type: "url",
186
+ url: "https://...",
187
+ mimeType: "image/png"
188
+ }
189
+ ],
190
+ usage: {
191
+ inputTokens: 0,
192
+ outputTokens: 0
193
+ },
194
+ model: "dall-e-3"
195
+ }
196
+ */
197
+ ```
198
+
199
+ ### Image Editing
200
+
201
+ **Note**: Image editing is only supported by `gpt-image-1` model.
202
+
203
+ ```typescript
204
+ import { OpenAIImageModel } from "@aigne/openai";
205
+
206
+ const imageModel = new OpenAIImageModel({
207
+ apiKey: "your-api-key",
208
+ model: "gpt-image-1",
209
+ });
210
+
211
+ const result = await imageModel.invoke({
212
+ prompt: "Add a rainbow to the sky",
213
+ image: [
214
+ {
215
+ type: "url",
216
+ url: "https://example.com/original-image.png",
217
+ },
218
+ ],
219
+ });
220
+
221
+ console.log(result.images); // Array of edited images
222
+ ```
223
+
224
+ ### OpenAIImageModel Input
225
+
226
+ - `prompt` (string, required): Text description of the desired image
227
+ - `model` (string, optional): Model to use - "dall-e-2", "dall-e-3", or "gpt-image-1" (default: "dall-e-2")
228
+ - `size` (string, optional): Image dimensions
229
+ - dall-e-2: "256x256", "512x512", "1024x1024"
230
+ - dall-e-3: "1024x1024", "1792x1024", "1024x1792"
231
+ - gpt-image-1: Various sizes supported
232
+ - `n` (number, optional): Number of images to generate
233
+ - dall-e-2: 1-10
234
+ - dall-e-3: 1 only
235
+ - `quality` (string, optional): "standard" or "hd" (dall-e-3 only)
236
+ - `style` (string, optional): "vivid" or "natural" (dall-e-3 only)
237
+ - `image` (array, optional): Reference images for editing (gpt-image-1 only)
238
+ - `background` (string, optional): Background style (gpt-image-1 only)
239
+ - `moderation` (boolean, optional): Enable content moderation (gpt-image-1 only)
240
+ - `outputCompression` (string, optional): Output compression level (gpt-image-1 only)
241
+ - `outputFormat` (string, optional): Output format (gpt-image-1 only)
242
+ - `user` (string, optional): User identifier for tracking
243
+
244
+ ### OpenAIImageModel Output
245
+
246
+ - `images` (array): Generated/edited images as `FileUnionContent[]`
247
+ - Each image contains: `type`, `url` or `data` (base64), `mimeType`
248
+ - `usage` (object): Token usage information
249
+ - `inputTokens` (number): Input tokens used
250
+ - `outputTokens` (number): Output tokens used
251
+ - `model` (string): The model used for generation
252
+
253
+ ## Video Generation
254
+
255
+ Use `OpenAIVideoModel` to generate videos with OpenAI's Sora models.
256
+
257
+ ### Basic Video Generation
258
+
259
+ ```typescript
260
+ import { OpenAIVideoModel } from "@aigne/openai";
261
+
262
+ const videoModel = new OpenAIVideoModel({
263
+ apiKey: "your-api-key",
264
+ model: "sora-2", // or "sora-2-pro"
265
+ modelOptions: {
266
+ size: "1280x720", // 16:9 horizontal
267
+ seconds: "4", // "4", "8", or "12"
268
+ },
269
+ });
270
+
271
+ const result = await videoModel.invoke({
272
+ prompt: "A serene lake with mountains in the background, gentle waves rippling",
273
+ });
274
+
275
+ console.log(result);
276
+ /* Output:
277
+ {
278
+ videos: [
279
+ {
280
+ type: "file",
281
+ data: "base64-encoded-video-data...",
282
+ mimeType: "video/mp4",
283
+ filename: "video-id.mp4"
284
+ }
285
+ ],
286
+ usage: {
287
+ inputTokens: 0,
288
+ outputTokens: 0
289
+ },
290
+ model: "sora-2",
291
+ seconds: 4
292
+ }
293
+ */
294
+ ```
295
+
296
+ ### Image-to-Video
297
+
298
+ ```typescript
299
+ import { OpenAIVideoModel } from "@aigne/openai";
300
+
301
+ const videoModel = new OpenAIVideoModel({
302
+ apiKey: "your-api-key",
303
+ model: "sora-2",
304
+ });
305
+
306
+ const result = await videoModel.invoke({
307
+ prompt: "Animate this image with gentle movement",
308
+ image: {
309
+ type: "url",
310
+ url: "https://example.com/input-image.png",
311
+ },
312
+ size: "1280x720",
313
+ seconds: "8",
314
+ });
315
+
316
+ console.log(result.videos); // Array containing generated video
317
+ ```
318
+
319
+ ### OpenAIVideoModel Input
320
+
321
+ - `prompt` (string, required): Text description of the desired video
322
+ - `model` (string, optional): "sora-2" (standard, lower cost) or "sora-2-pro" (higher quality) (default: "sora-2")
323
+ - `size` (string, optional): Video resolution
324
+ - "720x1280": Vertical 9:16
325
+ - "1280x720": Horizontal 16:9 (default)
326
+ - "1024x1792": Vertical 9:16 (higher res)
327
+ - "1792x1024": Horizontal 16:9 (higher res)
328
+ - `seconds` (string, optional): Video duration - "4", "8", or "12" seconds (default: "4")
329
+ - `image` (object, optional): Reference image for image-to-video generation
330
+ - Supports `type: "url"` with `url` or `type: "file"` with base64 `data`
331
+
332
+ ### OpenAIVideoModel Output
333
+
334
+ - `videos` (array): Generated videos as `FileUnionContent[]`
335
+ - Each video contains: `type: "file"`, `data` (base64), `mimeType: "video/mp4"`, `filename`
336
+ - `usage` (object): Token usage information
337
+ - `inputTokens` (number): Input tokens used (typically 0 for video generation)
338
+ - `outputTokens` (number): Output tokens used (typically 0 for video generation)
339
+ - `model` (string): The model used for generation
340
+ - `seconds` (number): Actual duration of the generated video
341
+
342
+ ## API Reference
343
+
344
+ For complete API documentation, please visit the [AIGNE Documentation](https://aigne.io/docs).
345
+
124
346
  ## License
125
347
 
126
348
  Elastic-2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/openai",
3
- "version": "0.16.5-beta.1",
3
+ "version": "0.16.5-beta.2",
4
4
  "description": "AIGNE OpenAI SDK for integrating with OpenAI's GPT models and API services",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -38,7 +38,7 @@
38
38
  "@aigne/uuid": "^13.0.1",
39
39
  "openai": "^6.5.0",
40
40
  "zod": "^3.25.67",
41
- "@aigne/core": "^1.65.1-beta.1",
41
+ "@aigne/core": "^1.65.1-beta.2",
42
42
  "@aigne/platform-helpers": "^0.6.3"
43
43
  },
44
44
  "devDependencies": {
@@ -47,7 +47,7 @@
47
47
  "npm-run-all": "^4.1.5",
48
48
  "rimraf": "^6.0.1",
49
49
  "typescript": "^5.9.2",
50
- "@aigne/test-utils": "^0.5.58-beta.1"
50
+ "@aigne/test-utils": "^0.5.58-beta.2"
51
51
  },
52
52
  "scripts": {
53
53
  "lint": "tsc --noEmit",