@gringow/gringow 0.0.9 → 0.1.0

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.
@@ -52,12 +52,12 @@ var configSchema = z.object({
52
52
  model: z.string().nullable(),
53
53
  temperature: z.number().optional(),
54
54
  sleep: z.number().optional(),
55
- prePrompt: z.string().optional(),
56
- postPrompt: z.string().optional(),
55
+ prePrompt: z.string().max(128).optional(),
56
+ postPrompt: z.string().max(128).optional(),
57
57
  prePromptReplace: z.string().optional(),
58
58
  postPromptReplace: z.string().optional(),
59
59
  prePromptAppend: z.string().optional(),
60
- postPromptAppend: z.string().optional()
60
+ postPromptPrepend: z.string().optional()
61
61
  }),
62
62
  globby: z.string().regex(/^\.\/.*/).optional()
63
63
  }).refine(
@@ -83,8 +83,16 @@ async function loadUserConfig() {
83
83
  try {
84
84
  const mergedConfig = merge({}, defaultConfig, result?.config);
85
85
  const parsedConfig = await configSchema.parseAsync(mergedConfig);
86
- parsedConfig.llm.prePrompt = prePrompt(parsedConfig);
87
- parsedConfig.llm.postPrompt = postPrompt(parsedConfig);
86
+ parsedConfig.llm.prePrompt = prePrompt(
87
+ parsedConfig,
88
+ parsedConfig.llm.prePromptAppend ?? "",
89
+ parsedConfig.llm.prePromptReplace ?? ""
90
+ );
91
+ parsedConfig.llm.postPrompt = postPrompt(
92
+ parsedConfig,
93
+ parsedConfig.llm.postPromptPrepend ?? "",
94
+ parsedConfig.llm.postPromptReplace ?? ""
95
+ );
88
96
  return parsedConfig;
89
97
  } catch (error) {
90
98
  console.warn(`${error?.message}, using default configuration`);
@@ -133,21 +141,21 @@ function defaultPostPrompt(_config) {
133
141
  [/POST-MESSAGE]
134
142
  `;
135
143
  }
136
- function prePrompt(config) {
144
+ function prePrompt(config, append, replace) {
137
145
  return [
138
- config.llm.prePromptReplace ? `${config.llm.prePromptReplace}` : defaultPrePrompt(config),
139
- config.llm.prePromptAppend ? ` ${config.llm.prePromptAppend}` : ""
146
+ ...append ? ["[SPECIFIC_INPUTS]", String(append), "[/SPECIFIC_INPUTS]"] : [],
147
+ replace ? String(replace) : defaultPrePrompt(config)
140
148
  ].join(" ").trim();
141
149
  }
142
- function postPrompt(config) {
150
+ function postPrompt(config, prepend, replace) {
143
151
  return [
144
- config?.llm?.postPromptReplace ? `${config.llm.postPromptReplace}` : defaultPostPrompt(),
145
- config.llm.postPromptAppend ? ` ${config.llm.postPromptAppend}` : ""
152
+ ...prepend ? ["[SPECIFIC_INPUTS]", String(prepend), "[/SPECIFIC_INPUTS]"] : [],
153
+ replace ? String(replace) : defaultPostPrompt()
146
154
  ].join(" ").trim();
147
155
  }
148
156
 
149
157
  // src/io/anthropic/ask.ts
150
- async function askAnthropic(message) {
158
+ async function askAnthropic(prompt, prePrompt2, postPrompt2) {
151
159
  const config = await awaitedConfig;
152
160
  if (Number(config.llm.sleep)) {
153
161
  await new Promise((resolve) => setTimeout(resolve, config.llm.sleep ?? 1));
@@ -159,19 +167,20 @@ async function askAnthropic(message) {
159
167
  apiKey: config.keys.anthropicApiKey,
160
168
  dangerouslyAllowBrowser: true
161
169
  });
170
+ const fullPrompt = String(`${prePrompt2}
171
+
172
+
173
+ ${prompt}
174
+
175
+
176
+ ${postPrompt2}`).trim();
162
177
  const response = await anthropic.messages.create({
163
178
  model: config.llm.model,
164
179
  max_tokens: 1024,
165
180
  messages: [
166
181
  {
167
182
  role: "user",
168
- content: `${config.llm.prePrompt}
169
-
170
-
171
- ${message}
172
-
173
-
174
- ${config.llm.postPrompt}`
183
+ content: fullPrompt
175
184
  }
176
185
  ]
177
186
  });
@@ -14,6 +14,6 @@ import '../flat-template-string.mjs';
14
14
  * @param prompt - The prompt to ask the model.
15
15
  * @returns The parsed response.
16
16
  */
17
- declare function askLLM(prompt: string): Promise<GringowCacheItem>;
17
+ declare function askLLM(prompt: string, prePrompt: string, postPrompt: string): Promise<GringowCacheItem>;
18
18
 
19
19
  export { askLLM };
@@ -55,12 +55,12 @@ var configSchema = z.object({
55
55
  model: z.string().nullable(),
56
56
  temperature: z.number().optional(),
57
57
  sleep: z.number().optional(),
58
- prePrompt: z.string().optional(),
59
- postPrompt: z.string().optional(),
58
+ prePrompt: z.string().max(128).optional(),
59
+ postPrompt: z.string().max(128).optional(),
60
60
  prePromptReplace: z.string().optional(),
61
61
  postPromptReplace: z.string().optional(),
62
62
  prePromptAppend: z.string().optional(),
63
- postPromptAppend: z.string().optional()
63
+ postPromptPrepend: z.string().optional()
64
64
  }),
65
65
  globby: z.string().regex(/^\.\/.*/).optional()
66
66
  }).refine(
@@ -86,8 +86,16 @@ async function loadUserConfig() {
86
86
  try {
87
87
  const mergedConfig = merge({}, defaultConfig, result?.config);
88
88
  const parsedConfig = await configSchema.parseAsync(mergedConfig);
89
- parsedConfig.llm.prePrompt = prePrompt(parsedConfig);
90
- parsedConfig.llm.postPrompt = postPrompt(parsedConfig);
89
+ parsedConfig.llm.prePrompt = prePrompt(
90
+ parsedConfig,
91
+ parsedConfig.llm.prePromptAppend ?? "",
92
+ parsedConfig.llm.prePromptReplace ?? ""
93
+ );
94
+ parsedConfig.llm.postPrompt = postPrompt(
95
+ parsedConfig,
96
+ parsedConfig.llm.postPromptPrepend ?? "",
97
+ parsedConfig.llm.postPromptReplace ?? ""
98
+ );
91
99
  return parsedConfig;
92
100
  } catch (error) {
93
101
  console.warn(`${error?.message}, using default configuration`);
@@ -136,19 +144,19 @@ function defaultPostPrompt(_config) {
136
144
  [/POST-MESSAGE]
137
145
  `;
138
146
  }
139
- function prePrompt(config) {
147
+ function prePrompt(config, append, replace) {
140
148
  return [
141
- config.llm.prePromptReplace ? `${config.llm.prePromptReplace}` : defaultPrePrompt(config),
142
- config.llm.prePromptAppend ? ` ${config.llm.prePromptAppend}` : ""
149
+ ...append ? ["[SPECIFIC_INPUTS]", String(append), "[/SPECIFIC_INPUTS]"] : [],
150
+ replace ? String(replace) : defaultPrePrompt(config)
143
151
  ].join(" ").trim();
144
152
  }
145
- function postPrompt(config) {
153
+ function postPrompt(config, prepend, replace) {
146
154
  return [
147
- config?.llm?.postPromptReplace ? `${config.llm.postPromptReplace}` : defaultPostPrompt(),
148
- config.llm.postPromptAppend ? ` ${config.llm.postPromptAppend}` : ""
155
+ ...prepend ? ["[SPECIFIC_INPUTS]", String(prepend), "[/SPECIFIC_INPUTS]"] : [],
156
+ replace ? String(replace) : defaultPostPrompt()
149
157
  ].join(" ").trim();
150
158
  }
151
- async function askAnthropic(message) {
159
+ async function askAnthropic(prompt, prePrompt2, postPrompt2) {
152
160
  const config = await awaitedConfig;
153
161
  if (Number(config.llm.sleep)) {
154
162
  await new Promise((resolve) => setTimeout(resolve, config.llm.sleep ?? 1));
@@ -160,19 +168,20 @@ async function askAnthropic(message) {
160
168
  apiKey: config.keys.anthropicApiKey,
161
169
  dangerouslyAllowBrowser: true
162
170
  });
171
+ const fullPrompt = String(`${prePrompt2}
172
+
173
+
174
+ ${prompt}
175
+
176
+
177
+ ${postPrompt2}`).trim();
163
178
  const response = await anthropic.messages.create({
164
179
  model: config.llm.model,
165
180
  max_tokens: 1024,
166
181
  messages: [
167
182
  {
168
183
  role: "user",
169
- content: `${config.llm.prePrompt}
170
-
171
-
172
- ${message}
173
-
174
-
175
- ${config.llm.postPrompt}`
184
+ content: fullPrompt
176
185
  }
177
186
  ]
178
187
  });
@@ -196,7 +205,7 @@ function parseAnthropic(unparsed) {
196
205
  const parsed = JSON.parse(unparsed);
197
206
  return parsed;
198
207
  }
199
- async function generateResponse(message, temperature = 1) {
208
+ async function generateResponse(prompt, temperature = 1) {
200
209
  const config = await awaitedConfig;
201
210
  if (!config.keys.geminiApiKey) {
202
211
  throw new Error("Gemini API key is not set in the config");
@@ -208,20 +217,13 @@ async function generateResponse(message, temperature = 1) {
208
217
  temperature
209
218
  }
210
219
  });
211
- const prompt = String(`${config.llm.prePrompt}
212
-
213
-
214
- ${message}
215
-
216
-
217
- ${config.llm.postPrompt}`).trim();
218
220
  if (config.debug) {
219
221
  console.log("Gemini model prompt:", JSON.stringify({ prompt }));
220
222
  }
221
223
  const response = await model.generateContent([prompt]);
222
224
  return response;
223
225
  }
224
- async function askGemini(message) {
226
+ async function askGemini(prompt, prePrompt2, postPrompt2) {
225
227
  const config = await awaitedConfig;
226
228
  if (Number(config.llm.sleep)) {
227
229
  await new Promise((resolve) => setTimeout(resolve, config.llm.sleep ?? 1));
@@ -230,11 +232,18 @@ async function askGemini(message) {
230
232
  throw new Error("Gemini API key is not set in the config");
231
233
  }
232
234
  if (config.debug) {
233
- console.log("\nAsking Gemini model:", JSON.stringify({ model: config.llm.model, message }));
235
+ console.log("\nAsking Gemini model:", JSON.stringify({ model: config.llm.model, message: prompt }));
234
236
  }
237
+ const fullPrompt = String(`${prePrompt2}
238
+
239
+
240
+ ${prompt}
241
+
242
+
243
+ ${postPrompt2}`).trim();
235
244
  let response;
236
245
  for (let i = 0; i < 3; i++) {
237
- const maybeResponse = await generateResponse(message, config.llm.temperature);
246
+ const maybeResponse = await generateResponse(fullPrompt, config.llm.temperature);
238
247
  if (!String(maybeResponse.response.candidates?.[0]?.content?.parts?.[0]?.text ?? "").includes("```json")) {
239
248
  response = maybeResponse;
240
249
  break;
@@ -554,20 +563,20 @@ var llmChoices = {
554
563
  parse: parseHuggingface
555
564
  }
556
565
  };
557
- async function processLLMChoice(llmChoice, prompt) {
558
- const response = await llmChoice.ask(prompt);
566
+ async function processLLMChoice(llmChoice, prompt, prePrompt2, postPrompt2) {
567
+ const response = await llmChoice.ask(prompt, prePrompt2, postPrompt2);
559
568
  const unparsed = llmChoice.commitResponse(response);
560
569
  const parsed = llmChoice.parse(unparsed);
561
570
  return parsed;
562
571
  }
563
- async function askLLM(prompt) {
572
+ async function askLLM(prompt, prePrompt2, postPrompt2) {
564
573
  const config = await awaitedConfig;
565
574
  const llmChoiceName = config.llm.choice;
566
575
  const llmChoice = llmChoices[llmChoiceName];
567
576
  if (!llmChoice) {
568
577
  throw new Error("LLMChoice not found");
569
578
  }
570
- return processLLMChoice(llmChoice, prompt);
579
+ return processLLMChoice(llmChoice, prompt, prePrompt2, postPrompt2);
571
580
  }
572
581
 
573
582
  export { askLLM };
@@ -3,9 +3,9 @@ import { GenerateContentResult } from '@google/generative-ai';
3
3
  /**
4
4
  * Asks the Gemini model for a response.
5
5
  *
6
- * @param message - The message to ask the model.
6
+ * @param prompt - The message to ask the model.
7
7
  * @returns The response from the model.
8
8
  */
9
- declare function askGemini(message: string): Promise<GenerateContentResult>;
9
+ declare function askGemini(prompt: string, prePrompt: string, postPrompt: string): Promise<GenerateContentResult>;
10
10
 
11
11
  export { askGemini };
@@ -52,12 +52,12 @@ var configSchema = z.object({
52
52
  model: z.string().nullable(),
53
53
  temperature: z.number().optional(),
54
54
  sleep: z.number().optional(),
55
- prePrompt: z.string().optional(),
56
- postPrompt: z.string().optional(),
55
+ prePrompt: z.string().max(128).optional(),
56
+ postPrompt: z.string().max(128).optional(),
57
57
  prePromptReplace: z.string().optional(),
58
58
  postPromptReplace: z.string().optional(),
59
59
  prePromptAppend: z.string().optional(),
60
- postPromptAppend: z.string().optional()
60
+ postPromptPrepend: z.string().optional()
61
61
  }),
62
62
  globby: z.string().regex(/^\.\/.*/).optional()
63
63
  }).refine(
@@ -83,8 +83,16 @@ async function loadUserConfig() {
83
83
  try {
84
84
  const mergedConfig = merge({}, defaultConfig, result?.config);
85
85
  const parsedConfig = await configSchema.parseAsync(mergedConfig);
86
- parsedConfig.llm.prePrompt = prePrompt(parsedConfig);
87
- parsedConfig.llm.postPrompt = postPrompt(parsedConfig);
86
+ parsedConfig.llm.prePrompt = prePrompt(
87
+ parsedConfig,
88
+ parsedConfig.llm.prePromptAppend ?? "",
89
+ parsedConfig.llm.prePromptReplace ?? ""
90
+ );
91
+ parsedConfig.llm.postPrompt = postPrompt(
92
+ parsedConfig,
93
+ parsedConfig.llm.postPromptPrepend ?? "",
94
+ parsedConfig.llm.postPromptReplace ?? ""
95
+ );
88
96
  return parsedConfig;
89
97
  } catch (error) {
90
98
  console.warn(`${error?.message}, using default configuration`);
@@ -133,21 +141,21 @@ function defaultPostPrompt(_config) {
133
141
  [/POST-MESSAGE]
134
142
  `;
135
143
  }
136
- function prePrompt(config) {
144
+ function prePrompt(config, append, replace) {
137
145
  return [
138
- config.llm.prePromptReplace ? `${config.llm.prePromptReplace}` : defaultPrePrompt(config),
139
- config.llm.prePromptAppend ? ` ${config.llm.prePromptAppend}` : ""
146
+ ...append ? ["[SPECIFIC_INPUTS]", String(append), "[/SPECIFIC_INPUTS]"] : [],
147
+ replace ? String(replace) : defaultPrePrompt(config)
140
148
  ].join(" ").trim();
141
149
  }
142
- function postPrompt(config) {
150
+ function postPrompt(config, prepend, replace) {
143
151
  return [
144
- config?.llm?.postPromptReplace ? `${config.llm.postPromptReplace}` : defaultPostPrompt(),
145
- config.llm.postPromptAppend ? ` ${config.llm.postPromptAppend}` : ""
152
+ ...prepend ? ["[SPECIFIC_INPUTS]", String(prepend), "[/SPECIFIC_INPUTS]"] : [],
153
+ replace ? String(replace) : defaultPostPrompt()
146
154
  ].join(" ").trim();
147
155
  }
148
156
 
149
157
  // src/io/gemini/ask.ts
150
- async function generateResponse(message, temperature = 1) {
158
+ async function generateResponse(prompt, temperature = 1) {
151
159
  const config = await awaitedConfig;
152
160
  if (!config.keys.geminiApiKey) {
153
161
  throw new Error("Gemini API key is not set in the config");
@@ -159,20 +167,13 @@ async function generateResponse(message, temperature = 1) {
159
167
  temperature
160
168
  }
161
169
  });
162
- const prompt = String(`${config.llm.prePrompt}
163
-
164
-
165
- ${message}
166
-
167
-
168
- ${config.llm.postPrompt}`).trim();
169
170
  if (config.debug) {
170
171
  console.log("Gemini model prompt:", JSON.stringify({ prompt }));
171
172
  }
172
173
  const response = await model.generateContent([prompt]);
173
174
  return response;
174
175
  }
175
- async function askGemini(message) {
176
+ async function askGemini(prompt, prePrompt2, postPrompt2) {
176
177
  const config = await awaitedConfig;
177
178
  if (Number(config.llm.sleep)) {
178
179
  await new Promise((resolve) => setTimeout(resolve, config.llm.sleep ?? 1));
@@ -181,11 +182,18 @@ async function askGemini(message) {
181
182
  throw new Error("Gemini API key is not set in the config");
182
183
  }
183
184
  if (config.debug) {
184
- console.log("\nAsking Gemini model:", JSON.stringify({ model: config.llm.model, message }));
185
+ console.log("\nAsking Gemini model:", JSON.stringify({ model: config.llm.model, message: prompt }));
185
186
  }
187
+ const fullPrompt = String(`${prePrompt2}
188
+
189
+
190
+ ${prompt}
191
+
192
+
193
+ ${postPrompt2}`).trim();
186
194
  let response;
187
195
  for (let i = 0; i < 3; i++) {
188
- const maybeResponse = await generateResponse(message, config.llm.temperature);
196
+ const maybeResponse = await generateResponse(fullPrompt, config.llm.temperature);
189
197
  if (!String(maybeResponse.response.candidates?.[0]?.content?.parts?.[0]?.text ?? "").includes("```json")) {
190
198
  response = maybeResponse;
191
199
  break;
@@ -52,12 +52,12 @@ var configSchema = z.object({
52
52
  model: z.string().nullable(),
53
53
  temperature: z.number().optional(),
54
54
  sleep: z.number().optional(),
55
- prePrompt: z.string().optional(),
56
- postPrompt: z.string().optional(),
55
+ prePrompt: z.string().max(128).optional(),
56
+ postPrompt: z.string().max(128).optional(),
57
57
  prePromptReplace: z.string().optional(),
58
58
  postPromptReplace: z.string().optional(),
59
59
  prePromptAppend: z.string().optional(),
60
- postPromptAppend: z.string().optional()
60
+ postPromptPrepend: z.string().optional()
61
61
  }),
62
62
  globby: z.string().regex(/^\.\/.*/).optional()
63
63
  }).refine(
@@ -83,8 +83,16 @@ async function loadUserConfig() {
83
83
  try {
84
84
  const mergedConfig = merge({}, defaultConfig, result?.config);
85
85
  const parsedConfig = await configSchema.parseAsync(mergedConfig);
86
- parsedConfig.llm.prePrompt = prePrompt(parsedConfig);
87
- parsedConfig.llm.postPrompt = postPrompt(parsedConfig);
86
+ parsedConfig.llm.prePrompt = prePrompt(
87
+ parsedConfig,
88
+ parsedConfig.llm.prePromptAppend ?? "",
89
+ parsedConfig.llm.prePromptReplace ?? ""
90
+ );
91
+ parsedConfig.llm.postPrompt = postPrompt(
92
+ parsedConfig,
93
+ parsedConfig.llm.postPromptPrepend ?? "",
94
+ parsedConfig.llm.postPromptReplace ?? ""
95
+ );
88
96
  return parsedConfig;
89
97
  } catch (error) {
90
98
  console.warn(`${error?.message}, using default configuration`);
@@ -133,21 +141,21 @@ function defaultPostPrompt(_config) {
133
141
  [/POST-MESSAGE]
134
142
  `;
135
143
  }
136
- function prePrompt(config) {
144
+ function prePrompt(config, append, replace) {
137
145
  return [
138
- config.llm.prePromptReplace ? `${config.llm.prePromptReplace}` : defaultPrePrompt(config),
139
- config.llm.prePromptAppend ? ` ${config.llm.prePromptAppend}` : ""
146
+ ...append ? ["[SPECIFIC_INPUTS]", String(append), "[/SPECIFIC_INPUTS]"] : [],
147
+ replace ? String(replace) : defaultPrePrompt(config)
140
148
  ].join(" ").trim();
141
149
  }
142
- function postPrompt(config) {
150
+ function postPrompt(config, prepend, replace) {
143
151
  return [
144
- config?.llm?.postPromptReplace ? `${config.llm.postPromptReplace}` : defaultPostPrompt(),
145
- config.llm.postPromptAppend ? ` ${config.llm.postPromptAppend}` : ""
152
+ ...prepend ? ["[SPECIFIC_INPUTS]", String(prepend), "[/SPECIFIC_INPUTS]"] : [],
153
+ replace ? String(replace) : defaultPostPrompt()
146
154
  ].join(" ").trim();
147
155
  }
148
156
 
149
157
  // src/io/gemini/ask.ts
150
- async function generateResponse(message, temperature = 1) {
158
+ async function generateResponse(prompt, temperature = 1) {
151
159
  const config = await awaitedConfig;
152
160
  if (!config.keys.geminiApiKey) {
153
161
  throw new Error("Gemini API key is not set in the config");
@@ -159,20 +167,13 @@ async function generateResponse(message, temperature = 1) {
159
167
  temperature
160
168
  }
161
169
  });
162
- const prompt = String(`${config.llm.prePrompt}
163
-
164
-
165
- ${message}
166
-
167
-
168
- ${config.llm.postPrompt}`).trim();
169
170
  if (config.debug) {
170
171
  console.log("Gemini model prompt:", JSON.stringify({ prompt }));
171
172
  }
172
173
  const response = await model.generateContent([prompt]);
173
174
  return response;
174
175
  }
175
- async function askGemini(message) {
176
+ async function askGemini(prompt, prePrompt2, postPrompt2) {
176
177
  const config = await awaitedConfig;
177
178
  if (Number(config.llm.sleep)) {
178
179
  await new Promise((resolve) => setTimeout(resolve, config.llm.sleep ?? 1));
@@ -181,11 +182,18 @@ async function askGemini(message) {
181
182
  throw new Error("Gemini API key is not set in the config");
182
183
  }
183
184
  if (config.debug) {
184
- console.log("\nAsking Gemini model:", JSON.stringify({ model: config.llm.model, message }));
185
+ console.log("\nAsking Gemini model:", JSON.stringify({ model: config.llm.model, message: prompt }));
185
186
  }
187
+ const fullPrompt = String(`${prePrompt2}
188
+
189
+
190
+ ${prompt}
191
+
192
+
193
+ ${postPrompt2}`).trim();
186
194
  let response;
187
195
  for (let i = 0; i < 3; i++) {
188
- const maybeResponse = await generateResponse(message, config.llm.temperature);
196
+ const maybeResponse = await generateResponse(fullPrompt, config.llm.temperature);
189
197
  if (!String(maybeResponse.response.candidates?.[0]?.content?.parts?.[0]?.text ?? "").includes("```json")) {
190
198
  response = maybeResponse;
191
199
  break;
@@ -53,12 +53,12 @@ var configSchema = z.object({
53
53
  model: z.string().nullable(),
54
54
  temperature: z.number().optional(),
55
55
  sleep: z.number().optional(),
56
- prePrompt: z.string().optional(),
57
- postPrompt: z.string().optional(),
56
+ prePrompt: z.string().max(128).optional(),
57
+ postPrompt: z.string().max(128).optional(),
58
58
  prePromptReplace: z.string().optional(),
59
59
  postPromptReplace: z.string().optional(),
60
60
  prePromptAppend: z.string().optional(),
61
- postPromptAppend: z.string().optional()
61
+ postPromptPrepend: z.string().optional()
62
62
  }),
63
63
  globby: z.string().regex(/^\.\/.*/).optional()
64
64
  }).refine(
@@ -84,8 +84,16 @@ async function loadUserConfig() {
84
84
  try {
85
85
  const mergedConfig = merge({}, defaultConfig, result?.config);
86
86
  const parsedConfig = await configSchema.parseAsync(mergedConfig);
87
- parsedConfig.llm.prePrompt = prePrompt(parsedConfig);
88
- parsedConfig.llm.postPrompt = postPrompt(parsedConfig);
87
+ parsedConfig.llm.prePrompt = prePrompt(
88
+ parsedConfig,
89
+ parsedConfig.llm.prePromptAppend ?? "",
90
+ parsedConfig.llm.prePromptReplace ?? ""
91
+ );
92
+ parsedConfig.llm.postPrompt = postPrompt(
93
+ parsedConfig,
94
+ parsedConfig.llm.postPromptPrepend ?? "",
95
+ parsedConfig.llm.postPromptReplace ?? ""
96
+ );
89
97
  return parsedConfig;
90
98
  } catch (error) {
91
99
  console.warn(`${error?.message}, using default configuration`);
@@ -134,16 +142,16 @@ function defaultPostPrompt(_config) {
134
142
  [/POST-MESSAGE]
135
143
  `;
136
144
  }
137
- function prePrompt(config) {
145
+ function prePrompt(config, append, replace) {
138
146
  return [
139
- config.llm.prePromptReplace ? `${config.llm.prePromptReplace}` : defaultPrePrompt(config),
140
- config.llm.prePromptAppend ? ` ${config.llm.prePromptAppend}` : ""
147
+ ...append ? ["[SPECIFIC_INPUTS]", String(append), "[/SPECIFIC_INPUTS]"] : [],
148
+ replace ? String(replace) : defaultPrePrompt(config)
141
149
  ].join(" ").trim();
142
150
  }
143
- function postPrompt(config) {
151
+ function postPrompt(config, prepend, replace) {
144
152
  return [
145
- config?.llm?.postPromptReplace ? `${config.llm.postPromptReplace}` : defaultPostPrompt(),
146
- config.llm.postPromptAppend ? ` ${config.llm.postPromptAppend}` : ""
153
+ ...prepend ? ["[SPECIFIC_INPUTS]", String(prepend), "[/SPECIFIC_INPUTS]"] : [],
154
+ replace ? String(replace) : defaultPostPrompt()
147
155
  ].join(" ").trim();
148
156
  }
149
157
 
@@ -53,12 +53,12 @@ var configSchema = z.object({
53
53
  model: z.string().nullable(),
54
54
  temperature: z.number().optional(),
55
55
  sleep: z.number().optional(),
56
- prePrompt: z.string().optional(),
57
- postPrompt: z.string().optional(),
56
+ prePrompt: z.string().max(128).optional(),
57
+ postPrompt: z.string().max(128).optional(),
58
58
  prePromptReplace: z.string().optional(),
59
59
  postPromptReplace: z.string().optional(),
60
60
  prePromptAppend: z.string().optional(),
61
- postPromptAppend: z.string().optional()
61
+ postPromptPrepend: z.string().optional()
62
62
  }),
63
63
  globby: z.string().regex(/^\.\/.*/).optional()
64
64
  }).refine(
@@ -84,8 +84,16 @@ async function loadUserConfig() {
84
84
  try {
85
85
  const mergedConfig = merge({}, defaultConfig, result?.config);
86
86
  const parsedConfig = await configSchema.parseAsync(mergedConfig);
87
- parsedConfig.llm.prePrompt = prePrompt(parsedConfig);
88
- parsedConfig.llm.postPrompt = postPrompt(parsedConfig);
87
+ parsedConfig.llm.prePrompt = prePrompt(
88
+ parsedConfig,
89
+ parsedConfig.llm.prePromptAppend ?? "",
90
+ parsedConfig.llm.prePromptReplace ?? ""
91
+ );
92
+ parsedConfig.llm.postPrompt = postPrompt(
93
+ parsedConfig,
94
+ parsedConfig.llm.postPromptPrepend ?? "",
95
+ parsedConfig.llm.postPromptReplace ?? ""
96
+ );
89
97
  return parsedConfig;
90
98
  } catch (error) {
91
99
  console.warn(`${error?.message}, using default configuration`);
@@ -134,16 +142,16 @@ function defaultPostPrompt(_config) {
134
142
  [/POST-MESSAGE]
135
143
  `;
136
144
  }
137
- function prePrompt(config) {
145
+ function prePrompt(config, append, replace) {
138
146
  return [
139
- config.llm.prePromptReplace ? `${config.llm.prePromptReplace}` : defaultPrePrompt(config),
140
- config.llm.prePromptAppend ? ` ${config.llm.prePromptAppend}` : ""
147
+ ...append ? ["[SPECIFIC_INPUTS]", String(append), "[/SPECIFIC_INPUTS]"] : [],
148
+ replace ? String(replace) : defaultPrePrompt(config)
141
149
  ].join(" ").trim();
142
150
  }
143
- function postPrompt(config) {
151
+ function postPrompt(config, prepend, replace) {
144
152
  return [
145
- config?.llm?.postPromptReplace ? `${config.llm.postPromptReplace}` : defaultPostPrompt(),
146
- config.llm.postPromptAppend ? ` ${config.llm.postPromptAppend}` : ""
153
+ ...prepend ? ["[SPECIFIC_INPUTS]", String(prepend), "[/SPECIFIC_INPUTS]"] : [],
154
+ replace ? String(replace) : defaultPostPrompt()
147
155
  ].join(" ").trim();
148
156
  }
149
157
 
@@ -49,7 +49,7 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
49
49
  prePromptReplace: z.ZodOptional<z.ZodString>;
50
50
  postPromptReplace: z.ZodOptional<z.ZodString>;
51
51
  prePromptAppend: z.ZodOptional<z.ZodString>;
52
- postPromptAppend: z.ZodOptional<z.ZodString>;
52
+ postPromptPrepend: z.ZodOptional<z.ZodString>;
53
53
  }, "strip", z.ZodTypeAny, {
54
54
  choice: "gemini" | "anthropic" | "huggingface";
55
55
  model: string | null;
@@ -60,7 +60,7 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
60
60
  prePromptReplace?: string | undefined;
61
61
  postPromptReplace?: string | undefined;
62
62
  prePromptAppend?: string | undefined;
63
- postPromptAppend?: string | undefined;
63
+ postPromptPrepend?: string | undefined;
64
64
  }, {
65
65
  choice: "gemini" | "anthropic" | "huggingface";
66
66
  model: string | null;
@@ -71,7 +71,7 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
71
71
  prePromptReplace?: string | undefined;
72
72
  postPromptReplace?: string | undefined;
73
73
  prePromptAppend?: string | undefined;
74
- postPromptAppend?: string | undefined;
74
+ postPromptPrepend?: string | undefined;
75
75
  }>;
76
76
  globby: z.ZodOptional<z.ZodString>;
77
77
  }, "strip", z.ZodTypeAny, {
@@ -100,7 +100,7 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
100
100
  prePromptReplace?: string | undefined;
101
101
  postPromptReplace?: string | undefined;
102
102
  prePromptAppend?: string | undefined;
103
- postPromptAppend?: string | undefined;
103
+ postPromptPrepend?: string | undefined;
104
104
  };
105
105
  debug?: boolean | undefined;
106
106
  globby?: string | undefined;
@@ -130,7 +130,7 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
130
130
  prePromptReplace?: string | undefined;
131
131
  postPromptReplace?: string | undefined;
132
132
  prePromptAppend?: string | undefined;
133
- postPromptAppend?: string | undefined;
133
+ postPromptPrepend?: string | undefined;
134
134
  };
135
135
  debug?: boolean | undefined;
136
136
  globby?: string | undefined;
@@ -160,7 +160,7 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
160
160
  prePromptReplace?: string | undefined;
161
161
  postPromptReplace?: string | undefined;
162
162
  prePromptAppend?: string | undefined;
163
- postPromptAppend?: string | undefined;
163
+ postPromptPrepend?: string | undefined;
164
164
  };
165
165
  debug?: boolean | undefined;
166
166
  globby?: string | undefined;
@@ -190,7 +190,7 @@ declare const configSchema: z.ZodEffects<z.ZodObject<{
190
190
  prePromptReplace?: string | undefined;
191
191
  postPromptReplace?: string | undefined;
192
192
  prePromptAppend?: string | undefined;
193
- postPromptAppend?: string | undefined;
193
+ postPromptPrepend?: string | undefined;
194
194
  };
195
195
  debug?: boolean | undefined;
196
196
  globby?: string | undefined;