@saltcorn/large-language-model 0.9.7 → 0.9.9
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/generate.js +16 -1
- package/index.js +8 -0
- package/package.json +1 -1
package/generate.js
CHANGED
|
@@ -211,6 +211,21 @@ const getCompletionAISDK = async (
|
|
|
211
211
|
model_obj = openai(use_model_name);
|
|
212
212
|
break;
|
|
213
213
|
}
|
|
214
|
+
const modifyChat = (chat) => {
|
|
215
|
+
const f = (c) => {
|
|
216
|
+
if (c.type === "image_url")
|
|
217
|
+
return {
|
|
218
|
+
type: "image",
|
|
219
|
+
image: c.image_url?.url || c.image?.url || c.image_url || c.image,
|
|
220
|
+
};
|
|
221
|
+
else return c;
|
|
222
|
+
};
|
|
223
|
+
return {
|
|
224
|
+
...chat,
|
|
225
|
+
...(Array.isArray(chat.content) ? { content: chat.content.map(f) } : {}),
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
const newChat = chat.map(modifyChat);
|
|
214
229
|
|
|
215
230
|
const body = {
|
|
216
231
|
...rest,
|
|
@@ -220,7 +235,7 @@ const getCompletionAISDK = async (
|
|
|
220
235
|
role: "system",
|
|
221
236
|
content: systemPrompt || "You are a helpful assistant.",
|
|
222
237
|
},
|
|
223
|
-
...
|
|
238
|
+
...newChat,
|
|
224
239
|
...(prompt ? [{ role: "user", content: prompt }] : []),
|
|
225
240
|
],
|
|
226
241
|
};
|
package/index.js
CHANGED
|
@@ -820,6 +820,11 @@ module.exports = {
|
|
|
820
820
|
sublabel: "A description of the field.",
|
|
821
821
|
type: "String",
|
|
822
822
|
},
|
|
823
|
+
{
|
|
824
|
+
label: "Required",
|
|
825
|
+
name: "required",
|
|
826
|
+
type: "Bool",
|
|
827
|
+
},
|
|
823
828
|
{
|
|
824
829
|
name: "type",
|
|
825
830
|
label: "Type",
|
|
@@ -954,17 +959,20 @@ module.exports = {
|
|
|
954
959
|
history = row[chat_history_field];
|
|
955
960
|
}
|
|
956
961
|
const fieldArgs = {};
|
|
962
|
+
const required = [];
|
|
957
963
|
(fields || []).forEach((field) => {
|
|
958
964
|
fieldArgs[field.name] = {
|
|
959
965
|
type: field.type,
|
|
960
966
|
description: field.description,
|
|
961
967
|
};
|
|
968
|
+
if (field.required) required.push(field.name);
|
|
962
969
|
if (field.type === "string" && field.options)
|
|
963
970
|
fieldArgs[field.name].enum = field.options
|
|
964
971
|
.split(",")
|
|
965
972
|
.map((s) => s.trim());
|
|
966
973
|
});
|
|
967
974
|
const argObj = { type: "object", properties: fieldArgs };
|
|
975
|
+
if (required.length) argObj.required = required;
|
|
968
976
|
const args = {
|
|
969
977
|
[answer_field]: multiple ? { type: "array", items: argObj } : argObj,
|
|
970
978
|
};
|