@saltcorn/large-language-model 0.5.2 → 0.5.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 (2) hide show
  1. package/index.js +57 -16
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -120,24 +120,65 @@ const configuration_workflow = () =>
120
120
  },
121
121
  ],
122
122
  });
123
- const functions = (config) => ({
124
- llm_generate: {
125
- run: async (prompt, opts) => {
126
- return await getCompletion(config, { prompt, ...opts });
123
+
124
+ let initialConfig;
125
+ const functions = (config) => {
126
+ initialConfig = JSON.stringify(config);
127
+ console.log("Initialising LLM functions with Config", config);
128
+ return {
129
+ llm_generate: {
130
+ run: async (prompt, opts) => {
131
+ let changedBefore = false;
132
+ if (JSON.stringify(config) !== initialConfig) {
133
+ console.error(
134
+ "LLM CONFIG CHANGED BEFORE COMPLETION RUN",
135
+ initialConfig,
136
+ JSON.stringify(config)
137
+ );
138
+ changedBefore = true;
139
+ }
140
+ const result = await getCompletion(config, { prompt, ...opts });
141
+ if (JSON.stringify(config) !== initialConfig && !changedBefore) {
142
+ console.error(
143
+ "LLM CONFIG CHANGED AFTER COMPLETION RUN",
144
+ initialConfig,
145
+ JSON.stringify(config)
146
+ );
147
+ }
148
+ return result;
149
+ },
150
+ isAsync: true,
151
+ description: "Generate text with GPT",
152
+ arguments: [{ name: "prompt", type: "String" }],
127
153
  },
128
- isAsync: true,
129
- description: "Generate text with GPT",
130
- arguments: [{ name: "prompt", type: "String" }],
131
- },
132
- llm_embedding: {
133
- run: async (prompt, opts) => {
134
- return await getEmbedding(config, { prompt, ...opts });
154
+ llm_embedding: {
155
+ run: async (prompt, opts) => {
156
+ let changedBefore = false;
157
+ if (JSON.stringify(config) !== initialConfig) {
158
+ console.error(
159
+ "LLM CONFIG CHANGED BEFORE EMBEDDING RUN",
160
+ initialConfig,
161
+ JSON.stringify(config)
162
+ );
163
+ changedBefore = true;
164
+ }
165
+
166
+ const result = await getEmbedding(config, { prompt, ...opts });
167
+ if (JSON.stringify(config) !== initialConfig && !changedBefore) {
168
+ console.error(
169
+ "LLM CONFIG CHANGED AFTER EMBEDDING RUN",
170
+ initialConfig,
171
+ JSON.stringify(config)
172
+ );
173
+ }
174
+ return result;
175
+ },
176
+ isAsync: true,
177
+ description: "Get vector embedding",
178
+ arguments: [{ name: "prompt", type: "String" }],
135
179
  },
136
- isAsync: true,
137
- description: "Get vector embedding",
138
- arguments: [{ name: "prompt", type: "String" }],
139
- },
140
- });
180
+ };
181
+ };
141
182
 
142
183
  module.exports = {
143
184
  sc_plugin_api_version: 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/large-language-model",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Large language models and functionality for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {