@zodic/shared 0.0.146 → 0.0.148
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/app/services/ConceptService.ts +40 -15
- package/package.json +1 -1
- package/types/scopes/cloudflare.ts +2 -0
- package/utils/buildMessages.ts +15 -11
|
@@ -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
|
-
|
|
206
|
+
`🚀 Generating Leonardo prompt for concept: ${conceptSlug}, combination: ${combinationString}`
|
|
208
207
|
);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
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
|
-
|
|
245
|
+
`❌ Failed to generate Leonardo prompt for concept: ${conceptSlug}`
|
|
228
246
|
);
|
|
229
247
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
259
|
+
`✅ Leonardo prompt stored for concept: ${conceptSlug}, combination: ${combinationString}, in both languages.`
|
|
235
260
|
);
|
|
236
261
|
}
|
|
237
262
|
|
package/package.json
CHANGED
|
@@ -53,6 +53,7 @@ export type CentralBindings = {
|
|
|
53
53
|
ASTROLOGY_PDF_API_KEY: string;
|
|
54
54
|
PIAPI_API_KEY: string;
|
|
55
55
|
DEEPSEEK_API_KEY: string;
|
|
56
|
+
TOGETHER_API_KEY: string;
|
|
56
57
|
|
|
57
58
|
API_BASE_URL: string;
|
|
58
59
|
PUBLIC_GOOGLE_CLIENT_ID: string;
|
|
@@ -108,6 +109,7 @@ export type BackendBindings = Env &
|
|
|
108
109
|
| 'CONCEPT_GENERATION_QUEUE'
|
|
109
110
|
| 'DEEPSEEK_API_KEY'
|
|
110
111
|
| 'PROMPT_GENERATE_ARCHETYPE_BASIC_INFO'
|
|
112
|
+
| 'TOGETHER_API_KEY'
|
|
111
113
|
>;
|
|
112
114
|
|
|
113
115
|
export type BackendCtx = Context<
|
package/utils/buildMessages.ts
CHANGED
|
@@ -122,18 +122,22 @@ export const buildLLMMessages = (env: BackendBindings) => ({
|
|
|
122
122
|
}: {
|
|
123
123
|
combination: string;
|
|
124
124
|
conceptSlug: Concept;
|
|
125
|
-
}): ChatMessages =>
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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,
|