@zodic/shared 0.0.139 → 0.0.140

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.
@@ -16,40 +16,60 @@ export class ConceptService {
16
16
  /**
17
17
  * Generate basic info for a concept: name, description, and poem.
18
18
  */
19
- async generateBasicInfo(conceptSlug: Concept, combinationString: string): Promise<void> {
20
- console.log(`🚀 Generating basic info for concept: ${conceptSlug}, combination: ${combinationString}`);
21
-
19
+ async generateBasicInfo(
20
+ conceptSlug: Concept,
21
+ combinationString: string
22
+ ): Promise<void> {
23
+ console.log(
24
+ `🚀 Generating basic info for concept: ${conceptSlug}, combination: ${combinationString}`
25
+ );
26
+
22
27
  // ✅ Build the messages to request content
23
28
  const messages = this.context.buildLLMMessages().generateConceptBasicInfo({
24
29
  combination: combinationString,
25
30
  conceptSlug,
26
31
  });
27
-
32
+
28
33
  // ✅ Call ChatGPT API
29
34
  const response = await this.context.api().callChatGPT.single(messages, {});
30
35
  if (!response) {
31
- throw new Error(`❌ Failed to generate basic info for concept: ${conceptSlug}`);
36
+ throw new Error(
37
+ `❌ Failed to generate basic info for concept: ${conceptSlug}`
38
+ );
32
39
  }
33
-
40
+
34
41
  // ✅ Parse response for both languages
35
- const { nameEN, descriptionEN, poemEN, namePT, descriptionPT, poemPT } = this.parseBasicInfoResponse(response);
36
-
42
+ const { nameEN, descriptionEN, poemEN, namePT, descriptionPT, poemPT } =
43
+ this.parseBasicInfoResponse(response);
44
+
37
45
  // ✅ Store in KV for both languages
38
46
  const kvStore = this.context.kvConceptsStore();
39
-
47
+
40
48
  // 🌍 English version
41
- const kvKeyEN = buildConceptKVKey("en-us", conceptSlug, combinationString);
49
+ const kvKeyEN = buildConceptKVKey('en-us', conceptSlug, combinationString);
42
50
  const conceptEN = await this.getKVConcept(kvKeyEN);
43
- Object.assign(conceptEN, { name: nameEN, description: descriptionEN, poem: poemEN, status: "idle" });
51
+ Object.assign(conceptEN, {
52
+ name: nameEN,
53
+ description: descriptionEN,
54
+ poem: poemEN,
55
+ status: 'idle',
56
+ });
44
57
  await kvStore.put(kvKeyEN, JSON.stringify(conceptEN));
45
-
58
+
46
59
  // 🇧🇷 Portuguese version
47
- const kvKeyPT = buildConceptKVKey("pt-br", conceptSlug, combinationString);
60
+ const kvKeyPT = buildConceptKVKey('pt-br', conceptSlug, combinationString);
48
61
  const conceptPT = await this.getKVConcept(kvKeyPT);
49
- Object.assign(conceptPT, { name: namePT, description: descriptionPT, poem: poemPT, status: "idle" });
62
+ Object.assign(conceptPT, {
63
+ name: namePT,
64
+ description: descriptionPT,
65
+ poem: poemPT,
66
+ status: 'idle',
67
+ });
50
68
  await kvStore.put(kvKeyPT, JSON.stringify(conceptPT));
51
-
52
- console.log(`✅ Basic info stored for ${conceptSlug}, combination: ${combinationString}, in both languages.`);
69
+
70
+ console.log(
71
+ `✅ Basic info stored for ${conceptSlug}, combination: ${combinationString}, in both languages.`
72
+ );
53
73
  }
54
74
 
55
75
  private parseBasicInfoResponse(response: string): {
@@ -60,30 +80,29 @@ export class ConceptService {
60
80
  descriptionPT: string;
61
81
  poemPT: string;
62
82
  } {
63
- console.log("📌 Parsing basic info response from ChatGPT:", response);
64
-
65
- const nameENMatch = response.match(/EN:\s*•\s*Name:\s*(.+)/);
66
- const descriptionENMatch = response.match(/EN:\s*•\s*Description:\s*([\s\S]+?)\s*•\s*Poetic Passage:/);
67
- const poemENMatch = response.match(/EN:\s*•\s*Poetic Passage:\s*([\s\S]+?)\s*PT:/);
68
-
69
- const namePTMatch = response.match(/PT:\s*•\s*Nome:\s*(.+)/);
70
- const descriptionPTMatch = response.match(/PT:\s*•\s*Descrição:\s*([\s\S]+?)\s*•\s*Passagem Poética:/);
71
- const poemPTMatch = response.match(/PT:\s*•\s*Passagem Poética:\s*([\s\S]+)/);
72
-
73
- if (!nameENMatch || !descriptionENMatch || !poemENMatch || !namePTMatch || !descriptionPTMatch || !poemPTMatch) {
74
- console.error("❌ Invalid basic info response format:", response);
75
- throw new Error("Invalid basic info response format");
83
+ console.log('📌 Parsing basic info response from ChatGPT:', response);
84
+
85
+ const enMatch = response.match(
86
+ /EN:\s*•\s*Name:\s*(.+?)\s*•\s*Description:\s*([\s\S]+?)\s*•\s*Poetic Passage:\s*([\s\S]+?)\s*(?=PT:|$)/
87
+ );
88
+ const ptMatch = response.match(
89
+ /PT:\s*•\s*Nome:\s*(.+?)\s*•\s*Descrição:\s*([\s\S]+?)\s*•\s*Passagem Poética:\s*([\s\S]+)/
90
+ );
91
+
92
+ if (!enMatch || !ptMatch) {
93
+ console.error('❌ Invalid basic info response format:', response);
94
+ throw new Error('Invalid basic info response format');
76
95
  }
77
-
78
- const nameEN = nameENMatch[1].trim();
79
- const descriptionEN = descriptionENMatch[1].trim();
80
- const poemEN = poemENMatch[1].trim();
81
-
82
- const namePT = namePTMatch[1].trim();
83
- const descriptionPT = descriptionPTMatch[1].trim();
84
- const poemPT = poemPTMatch[1].trim();
85
-
86
- console.log("Parsed basic info:", {
96
+
97
+ const nameEN = enMatch[1].trim();
98
+ const descriptionEN = enMatch[2].trim();
99
+ const poemEN = enMatch[3].trim();
100
+
101
+ const namePT = ptMatch[1].trim();
102
+ const descriptionPT = ptMatch[2].trim();
103
+ const poemPT = ptMatch[3].trim();
104
+
105
+ console.log('Successfully parsed basic info:', {
87
106
  nameEN,
88
107
  descriptionEN,
89
108
  poemEN,
@@ -91,7 +110,7 @@ export class ConceptService {
91
110
  descriptionPT,
92
111
  poemPT,
93
112
  });
94
-
113
+
95
114
  return { nameEN, descriptionEN, poemEN, namePT, descriptionPT, poemPT };
96
115
  }
97
116
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.139",
3
+ "version": "0.0.140",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {