@vibes.diy/prompts 14.1.0 → 14.1.1
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/llms/callai.md +47 -0
- package/package.json +4 -4
package/llms/callai.md
CHANGED
|
@@ -56,6 +56,51 @@ console.log(demoData.items); // Array of item objects
|
|
|
56
56
|
- Use simple property names like `name`, `type`, `items`, `price`.
|
|
57
57
|
- Keep array items simple (strings or flat objects).
|
|
58
58
|
|
|
59
|
+
## Reading an Image
|
|
60
|
+
|
|
61
|
+
Send an image by passing the prompt as an array of content parts: an `image_url` part carrying the picture beside a `text` part asking the question.
|
|
62
|
+
|
|
63
|
+
The prompt is the content of one user message, so a plain string means exactly one text part and the array is that same message's parts. Read the picture the user picked with a `FileReader` and hand over the data URL it produces:
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { callAI } from "call-ai";
|
|
67
|
+
|
|
68
|
+
function readAsDataUrl(file) {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
const reader = new FileReader();
|
|
71
|
+
reader.onload = () => resolve(reader.result);
|
|
72
|
+
reader.onerror = () => reject(reader.error);
|
|
73
|
+
reader.readAsDataURL(file);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function readFlyer(file) {
|
|
78
|
+
const dataUrl = await readAsDataUrl(file);
|
|
79
|
+
const response = await callAI(
|
|
80
|
+
[
|
|
81
|
+
{ type: "text", text: "Read this event flyer and pull out the event details." },
|
|
82
|
+
{ type: "image_url", image_url: { url: dataUrl } },
|
|
83
|
+
],
|
|
84
|
+
{
|
|
85
|
+
schema: {
|
|
86
|
+
properties: {
|
|
87
|
+
title: { type: "string", description: "Name of the event" },
|
|
88
|
+
date: { type: "string", description: "Date as printed on the flyer" },
|
|
89
|
+
time: { type: "string" },
|
|
90
|
+
venue: { type: "string" },
|
|
91
|
+
description: { type: "string" },
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
return JSON.parse(response);
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
A string prompt stays the common path for text-only work and behaves exactly as it always has. A model that reads text alone answers an image request with an error naming that model, so an app that asks about a picture hears when the picture went unread — surface that message the way you surface any other `callAI` error.
|
|
101
|
+
|
|
102
|
+
Inside `backend.js`, `ctx.callAI` takes a string prompt.
|
|
103
|
+
|
|
59
104
|
## Error Handling
|
|
60
105
|
|
|
61
106
|
```javascript
|
|
@@ -74,3 +119,5 @@ try {
|
|
|
74
119
|
console.error("API error:", error.message);
|
|
75
120
|
}
|
|
76
121
|
```
|
|
122
|
+
|
|
123
|
+
Let the request finish. Reading an image takes several seconds, so a slow answer is still an answer: show a waiting state ("reading your photo…") and keep awaiting the call. The `catch` above is what tells the app a request actually failed.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibes.diy/prompts",
|
|
3
|
-
"version": "14.1.
|
|
3
|
+
"version": "14.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"exports": {
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"license": "Apache-2.0",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@adviser/cement": "~0.5.34",
|
|
37
|
-
"@vibes.diy/call-ai-v2": "14.1.
|
|
38
|
-
"@vibes.diy/identity": "14.1.
|
|
39
|
-
"@vibes.diy/use-vibes-types": "14.1.
|
|
37
|
+
"@vibes.diy/call-ai-v2": "14.1.1",
|
|
38
|
+
"@vibes.diy/identity": "14.1.1",
|
|
39
|
+
"@vibes.diy/use-vibes-types": "14.1.1",
|
|
40
40
|
"arktype": "~2.2.3",
|
|
41
41
|
"json-schema-faker": "~0.6.3"
|
|
42
42
|
},
|