@zodic/shared 0.0.153 → 0.0.154

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/api/index.ts CHANGED
@@ -38,7 +38,7 @@ export const Api = (env: BackendBindings) => ({
38
38
  callTogether: {
39
39
  single: async (
40
40
  messages: ChatMessages,
41
- { model = 'deepseek-ai/DeepSeek-V3', options = { } }: DeepSeekOptions
41
+ { model = 'deepseek-ai/DeepSeek-V3', options = {} }: DeepSeekOptions
42
42
  ): Promise<string> => {
43
43
  try {
44
44
  const response = await together(env).chat.completions.create({
@@ -1,4 +1,6 @@
1
1
  import { inject, injectable } from 'inversify';
2
+ import pMap from 'p-map';
3
+ import { zodiacSignCombinations } from '../../data/zodiacSignCombinations';
2
4
  import { Concept, ConceptPhase } from '../../types';
3
5
  import { ConceptService } from '../services/ConceptService';
4
6
 
@@ -13,7 +15,7 @@ export class ConceptWorkflow {
13
15
  override?: boolean
14
16
  ) {
15
17
  console.log(
16
- `Processing single concept for slug: ${conceptSlug}, combination: ${combinationString}, phase: ${phase}`
18
+ `🚀 Processing single concept: ${conceptSlug} | ${combinationString} | Phase: ${phase}`
17
19
  );
18
20
 
19
21
  try {
@@ -50,14 +52,73 @@ export class ConceptWorkflow {
50
52
  }
51
53
 
52
54
  console.log(
53
- `Concept ${conceptSlug}:${combinationString} successfully processed for phase: ${phase}`
55
+ `✅ Concept ${conceptSlug}:${combinationString} successfully processed for phase: ${phase}`
54
56
  );
55
57
  } catch (error) {
56
58
  console.error(
57
- `Error processing concept ${conceptSlug}:${combinationString} for phase ${phase}:`,
59
+ `❌ Error processing concept ${conceptSlug}:${combinationString} | Phase: ${phase}:`,
58
60
  error
59
61
  );
60
- throw error;
61
62
  }
62
63
  }
64
+
65
+ async processBatch(
66
+ conceptSlug: Concept,
67
+ combinations: string[],
68
+ phase: ConceptPhase,
69
+ override?: boolean
70
+ ) {
71
+ console.log(
72
+ `🚀 Processing batch for concept: ${conceptSlug}, Phase: ${phase}, Total Combinations: ${combinations.length}`
73
+ );
74
+
75
+ const concurrency = 20; // Adjust based on response speed
76
+ const failedCombinations: string[] = [];
77
+
78
+ await pMap(
79
+ combinations,
80
+ async (combination) => {
81
+ try {
82
+ await this.processSingle(conceptSlug, combination, phase, override);
83
+ } catch (error) {
84
+ console.error(`❌ Error processing ${combination}:`, error);
85
+ failedCombinations.push(combination); // Store failed ones
86
+ }
87
+ },
88
+ { concurrency }
89
+ );
90
+
91
+ if (failedCombinations.length > 0) {
92
+ console.warn(`⚠️ Retrying failed combinations:`, failedCombinations);
93
+ await this.processBatch(conceptSlug, failedCombinations, phase, override); // Retry
94
+ }
95
+ console.log(
96
+ `✅ Batch processing completed for concept: ${conceptSlug}, Phase: ${phase}`
97
+ );
98
+ }
99
+
100
+ async processAllCombinations(
101
+ conceptSlug: Concept,
102
+ phase: ConceptPhase,
103
+ override?: boolean
104
+ ) {
105
+ console.log(`🔍 Fetching all possible combinations for: ${conceptSlug}`);
106
+
107
+ // 🔥 Replace with the actual function that retrieves all pre-defined combinations from KV or DB
108
+ const combinations = zodiacSignCombinations;
109
+ if (!combinations.length) {
110
+ console.warn(`⚠️ No combinations found for ${conceptSlug}, skipping.`);
111
+ return;
112
+ }
113
+
114
+ console.log(
115
+ `🚀 Processing ALL combinations for ${conceptSlug}, Phase: ${phase}, Total: ${combinations.length}`
116
+ );
117
+
118
+ await this.processBatch(conceptSlug, combinations, phase, override);
119
+
120
+ console.log(
121
+ `✅ All combinations processed for concept: ${conceptSlug}, Phase: ${phase}`
122
+ );
123
+ }
63
124
  }