dsh-plugin-marginalia 0.1.0 → 0.2.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/client.js +838 -162
- package/index.js +12 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -96,8 +96,11 @@ export function apply(ctx) {
|
|
|
96
96
|
const question = typeof body?.question === 'string' ? body.question.trim() : '';
|
|
97
97
|
const includeContext = body?.includeContext !== false;
|
|
98
98
|
const rawHistory = Array.isArray(body?.history) ? body.history : [];
|
|
99
|
+
const rawQuotes = Array.isArray(body?.quotes)
|
|
100
|
+
? body.quotes.filter((q) => typeof q === 'string' && q.trim()).map((q) => q.trim().slice(0, 4000))
|
|
101
|
+
: [];
|
|
99
102
|
|
|
100
|
-
if (!question) {
|
|
103
|
+
if (!question && rawQuotes.length === 0) {
|
|
101
104
|
return Response.json({ error: 'Question is required' }, { status: 400 });
|
|
102
105
|
}
|
|
103
106
|
|
|
@@ -166,9 +169,16 @@ export function apply(ctx) {
|
|
|
166
169
|
content: [{ type: 'text', text }],
|
|
167
170
|
});
|
|
168
171
|
}
|
|
172
|
+
const userText =
|
|
173
|
+
rawQuotes.length > 0
|
|
174
|
+
? rawQuotes.map((q, i) => `> [Selected excerpt ${i + 1}]\n> ${q.replace(/\n/g, '\n> ')}`).join('\n\n') +
|
|
175
|
+
'\n\n' +
|
|
176
|
+
(question || 'Please explain the selected excerpt(s).')
|
|
177
|
+
: question;
|
|
178
|
+
|
|
169
179
|
messages.push({
|
|
170
180
|
role: 'user',
|
|
171
|
-
content: [{ type: 'text', text:
|
|
181
|
+
content: [{ type: 'text', text: userText }],
|
|
172
182
|
});
|
|
173
183
|
|
|
174
184
|
let prepared;
|
package/package.json
CHANGED