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/recipes/ai.md
+102Lines changed: 102 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,7 @@ Lucee 7 includes full support for AI integration, allowing you to interact with
26
26
27
27
-**Multipart Content Support**: Send images, PDFs, and other documents along with text prompts
28
28
-**Multipart Response Support**: Receive generated images and other content types from AI (currently Gemini, more providers coming soon)
29
+
-**Structured JSON Responses**: Enforce specific JSON response schemas with Gemini beta API
29
30
-**Simplified Function Names**: Functions are available without the `Lucee` prefix (though the prefix is still supported as an alias for backward compatibility)
30
31
-**Stable API**: The AI functionality is no longer experimental and is ready for production use
31
32
-**Enhanced File Handling**: Automatic detection and handling of file paths in multipart requests
@@ -321,6 +322,75 @@ if (isArray(response)) {
321
322
-**ChatGPT (OpenAI)**: 🔄 Coming soon
322
323
-**Ollama**: 🔄 Coming soon
323
324
325
+
### Structured JSON Responses (Gemini Beta)
326
+
327
+
**New in Lucee 7** - With Gemini's beta API, you can enforce structured JSON responses by defining a `generationConfig` with a response schema. This ensures the AI returns data in a specific, predictable format.
328
+
329
+
#### Configuration
330
+
331
+
Add `generationConfig` to your Gemini endpoint configuration to specify the desired response structure:
332
+
333
+
```json
334
+
"recipes": {
335
+
"class": "lucee.runtime.ai.google.GeminiEngine",
336
+
"custom": {
337
+
"connectTimeout": "2000",
338
+
"beta": true,
339
+
"message": "Keep all answers concise and accurate",
340
+
"model": "gemini-2.5-flash",
341
+
"apikey": "${GEMINI_API_KEY}",
342
+
"socketTimeout": "120000",
343
+
"temperature": "0.7",
344
+
"conversationSizeLimit": "10",
345
+
346
+
"generationConfig": {
347
+
"responseMimeType": "application/json",
348
+
"responseSchema": {
349
+
"type": "ARRAY",
350
+
"items": {
351
+
"type": "OBJECT",
352
+
"properties": {
353
+
"recipeName": { "type": "STRING" },
354
+
"calories": { "type": "INTEGER" }
355
+
},
356
+
"required": ["recipeName", "calories"]
357
+
}
358
+
}
359
+
}
360
+
}
361
+
}
362
+
```
363
+
364
+
**Configuration Options:**
365
+
-**`responseMimeType`**: Set to `"application/json"` to enforce JSON responses
366
+
-**`responseSchema`**: Define the expected JSON structure using a schema
367
+
-**`generationConfig`**: All other Gemini generation config options are supported and passed directly to the API
368
+
369
+
#### Usage Example
370
+
371
+
```javascript
372
+
aiSessionJson =createAISession(
373
+
name:"recipes",
374
+
limit:100,
375
+
temperature:0.2,
376
+
systemMessage:"Keep your answers as short as possible"
{"recipeName":"Oatmeal with berries","calories":300},
387
+
{"recipeName":"Greek yogurt with fruit","calories":250},
388
+
{"recipeName":"Scrambled eggs with spinach","calories":350}
389
+
]
390
+
```
391
+
392
+
**Note**: This feature requires Gemini's beta API (`"beta": true` or URL set to `https://generativelanguage.googleapis.com/v1beta/`).
393
+
324
394
### Session Serialization
325
395
326
396
Save and restore conversation state across requests. See [AI Session Serialization](https://github.com/lucee/lucee-docs/blob/master/docs/recipes/ai-serialisation.md) for details.
@@ -466,6 +536,7 @@ If you're upgrading from Lucee 6.2 with the experimental AI features:
466
536
3.**New features**: You can now use:
467
537
- Multipart content (images, PDFs) in your AI queries
468
538
- Multipart responses (generated images and files from AI)
539
+
- Structured JSON responses with Gemini beta API
469
540
- Session serialization for persistent conversations
0 commit comments