@zodic/shared 0.0.146 → 0.0.147

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.
@@ -198,40 +198,65 @@ export class ConceptService {
198
198
  * Generate the Leonardo prompt for a concept.
199
199
  */
200
200
  async generatePrompt(
201
- language: Languages,
202
201
  conceptSlug: Concept,
203
- combinationString: string
202
+ combinationString: string,
203
+ override: boolean = false
204
204
  ): Promise<void> {
205
- const kvKey = buildConceptKVKey(language, conceptSlug, combinationString);
206
205
  console.log(
207
- `Generating Leonardo prompt for concept: ${conceptSlug}, combination: ${combinationString}, language: ${language}`
206
+ `🚀 Generating Leonardo prompt for concept: ${conceptSlug}, combination: ${combinationString}`
208
207
  );
209
-
210
- const concept = await this.getKVConcept(kvKey);
211
- if (!concept.name || !concept.description || !concept.poem) {
208
+
209
+ // Build KV keys for both languages
210
+ const kvKeyEN = buildConceptKVKey('en-us', conceptSlug, combinationString);
211
+ const kvKeyPT = buildConceptKVKey('pt-br', conceptSlug, combinationString);
212
+
213
+ // ✅ Retrieve existing KV data
214
+ const conceptEN = await this.getKVConcept(kvKeyEN);
215
+ const conceptPT = await this.getKVConcept(kvKeyPT);
216
+
217
+ // ✅ Check if prompt already exists
218
+ if (!override && conceptEN.leonardoPrompt && conceptPT.leonardoPrompt) {
219
+ console.log(`⚡ Leonardo prompt already exists for ${conceptSlug}, skipping.`);
220
+ return; // ✅ Skip regeneration
221
+ }
222
+
223
+ // ✅ Ensure basic info is present
224
+ if (
225
+ !conceptEN.name || !conceptEN.description || !conceptEN.poem ||
226
+ !conceptPT.name || !conceptPT.description || !conceptPT.poem
227
+ ) {
212
228
  throw new Error(
213
- `Basic info must be populated before generating prompt for concept: ${conceptSlug}`
229
+ `❌ Basic info must be populated before generating Leonardo prompt for concept: ${conceptSlug}`
214
230
  );
215
231
  }
216
-
232
+
233
+ // ✅ Generate prompt request
217
234
  const messages = this.context
218
235
  .buildLLMMessages()
219
236
  .generateConceptLeonardoPrompt({
220
237
  conceptSlug,
221
238
  combination: combinationString,
222
239
  });
223
-
240
+
241
+ // ✅ Call ChatGPT API
224
242
  const response = await this.context.api().callChatGPT.single(messages, {});
225
243
  if (!response) {
226
244
  throw new Error(
227
- `Failed to generate Leonardo prompt for concept: ${conceptSlug}`
245
+ `❌ Failed to generate Leonardo prompt for concept: ${conceptSlug}`
228
246
  );
229
247
  }
230
-
231
- concept.leonardoPrompt = response.trim();
232
- await this.context.kvConceptsStore().put(kvKey, JSON.stringify(concept));
248
+
249
+ // Store the generated prompt in both languages
250
+ conceptEN.leonardoPrompt = response.trim();
251
+ conceptPT.leonardoPrompt = response.trim();
252
+
253
+ await Promise.all([
254
+ this.context.kvConceptsStore().put(kvKeyEN, JSON.stringify(conceptEN)),
255
+ this.context.kvConceptsStore().put(kvKeyPT, JSON.stringify(conceptPT)),
256
+ ]);
257
+
233
258
  console.log(
234
- `Leonardo prompt stored for concept: ${conceptSlug}, combination: ${combinationString}, language: ${language}`
259
+ `✅ Leonardo prompt stored for concept: ${conceptSlug}, combination: ${combinationString}, in both languages.`
235
260
  );
236
261
  }
237
262
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.146",
3
+ "version": "0.0.147",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -122,18 +122,22 @@ export const buildLLMMessages = (env: BackendBindings) => ({
122
122
  }: {
123
123
  combination: string;
124
124
  conceptSlug: Concept;
125
- }): ChatMessages => [
126
- {
127
- role: 'system',
128
- content: conceptPrompts(env)['leonardoPrompt'][conceptSlug],
129
- },
130
- {
131
- role: 'user',
132
- content: `
133
- Combination: ${combination}
125
+ }): ChatMessages => {
126
+ const zodiacCombination = mapConceptToPlanets(conceptSlug, combination);
127
+
128
+ return [
129
+ {
130
+ role: 'system',
131
+ content: conceptPrompts(env)['leonardoPrompt'][conceptSlug],
132
+ },
133
+ {
134
+ role: 'user',
135
+ content: `
136
+ Combination: ${zodiacCombination}
134
137
  `,
135
- },
136
- ],
138
+ },
139
+ ];
140
+ },
137
141
  generateConceptContent: ({
138
142
  name,
139
143
  description,