@saltcorn/large-language-model 0.7.3 → 0.7.4

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/generate.js +13 -8
  2. package/index.js +5 -0
  3. package/package.json +1 -1
package/generate.js CHANGED
@@ -274,7 +274,7 @@ const initOAuth2Client = async (config) => {
274
274
 
275
275
  const convertChatToVertex = (chat) => {
276
276
  const history = [];
277
- for (const message of chat) {
277
+ for (const message of chat || []) {
278
278
  const role = message.role === "user" ? "user" : "model";
279
279
  if (message.content) {
280
280
  const parts = [{ text: message.content }];
@@ -320,15 +320,20 @@ const getCompletionGoogleVertex = async (config, opts, oauth2Client) => {
320
320
  const generativeModel = vertexAI.getGenerativeModel({
321
321
  model: config.model,
322
322
  });
323
- const chat = generativeModel.startChat({
324
- tools: [
323
+ const chatParams = {
324
+ history: convertChatToVertex(opts.chat),
325
+ systemPrompt: opts.systemPrompt || "You are a helpful assistant.",
326
+ };
327
+ if (opts?.tools?.length > 0) {
328
+ chatParams.tools = [
325
329
  {
326
- functionDeclarations: opts.tools.map((t) => t.function),
330
+ functionDeclarations: opts.tools.map((t) =>
331
+ prepFuncArgsForChat(t.function)
332
+ ),
327
333
  },
328
- ],
329
- history: convertChatToVertex(opts.chat),
330
- systemInstructions: opts.systemPrompt || "You are a helpful assistant.",
331
- });
334
+ ];
335
+ }
336
+ const chat = generativeModel.startChat(chatParams);
332
337
  const { response } = await chat.sendMessage([{ text: opts.prompt }]);
333
338
  const parts = response?.candidates?.[0]?.content?.parts;
334
339
  if (!parts) return "";
package/index.js CHANGED
@@ -316,6 +316,7 @@ const routes = (config) => {
316
316
  const authUrl = oauth2Client.generateAuthUrl({
317
317
  access_type: "offline",
318
318
  scope: "https://www.googleapis.com/auth/cloud-platform",
319
+ prompt: "consent",
319
320
  });
320
321
  res.redirect(authUrl);
321
322
  },
@@ -355,6 +356,10 @@ const routes = (config) => {
355
356
  const newConfig = { ...(plugin.configuration || {}), tokens };
356
357
  plugin.configuration = newConfig;
357
358
  await plugin.upsert();
359
+ getState().processSend({
360
+ refresh_plugin_cfg: plugin.name,
361
+ tenant: db.getTenantSchema(),
362
+ });
358
363
  req.flash(
359
364
  "success",
360
365
  req.__("Authentication successful! You can now use Vertex AI.")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/large-language-model",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "Large language models and functionality for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {