@zodic/shared 0.0.70 → 0.0.72
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 +67 -0
- package/app/base/AppContext.ts +3 -3
- package/app/services/ConceptService.ts +12 -16
- package/package.json +2 -1
- package/types/scopes/cloudflare.ts +2 -0
- package/types/scopes/generic.ts +10 -1
- package/utils/buildMessages.ts +2 -2
package/app/api/index.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
1
2
|
import {
|
|
2
3
|
BackendBindings,
|
|
3
4
|
BatchInputItem,
|
|
4
5
|
ChatGPTBatchResponse,
|
|
5
6
|
ChatGPTFileUploadResponse,
|
|
6
7
|
ChatMessages,
|
|
8
|
+
DeepSeekBatchInputItem,
|
|
9
|
+
DeepSeekBatchResponse,
|
|
10
|
+
DeepSeekOptions,
|
|
7
11
|
NatalChartInterpretation,
|
|
8
12
|
} from '../../types';
|
|
9
13
|
import {
|
|
@@ -20,7 +24,70 @@ import {
|
|
|
20
24
|
} from '../../types/scopes/legacy';
|
|
21
25
|
import { makeAstrologyApiCall } from './astrology';
|
|
22
26
|
|
|
27
|
+
const deepseek = (env: BackendBindings) =>
|
|
28
|
+
new OpenAI({
|
|
29
|
+
apiKey: env.DEEPSEEK_API_KEY,
|
|
30
|
+
baseURL: 'https://api.deepseek.com/v1',
|
|
31
|
+
});
|
|
32
|
+
|
|
23
33
|
export const Api = (env: BackendBindings) => ({
|
|
34
|
+
callDeepSeek: {
|
|
35
|
+
single: async (
|
|
36
|
+
messages: ChatMessages,
|
|
37
|
+
{ model = 'deepseek-v3', options = {} }: DeepSeekOptions
|
|
38
|
+
): Promise<string> => {
|
|
39
|
+
try {
|
|
40
|
+
const response = await deepseek(env).chat.completions.create({
|
|
41
|
+
model,
|
|
42
|
+
messages,
|
|
43
|
+
...options,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (response.choices[0].message.content) {
|
|
47
|
+
return response.choices[0].message.content.trim();
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error('Content is null');
|
|
50
|
+
}
|
|
51
|
+
} catch (err: any) {
|
|
52
|
+
console.error('Error calling DeepSeek API:', err.message);
|
|
53
|
+
throw err;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
batch: async (
|
|
58
|
+
batchItems: DeepSeekBatchInputItem[]
|
|
59
|
+
): Promise<DeepSeekBatchResponse> => {
|
|
60
|
+
console.log('Preparing to send DeepSeek batch request.');
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const responses: DeepSeekBatchResponse = [];
|
|
64
|
+
|
|
65
|
+
for (const item of batchItems) {
|
|
66
|
+
const { messages, options } = item;
|
|
67
|
+
const response = await deepseek(env).chat.completions.create({
|
|
68
|
+
model: options?.model || 'deepseek-v3',
|
|
69
|
+
messages,
|
|
70
|
+
...options,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (response.choices[0].message.content) {
|
|
74
|
+
responses.push({
|
|
75
|
+
input: item,
|
|
76
|
+
output: response.choices[0].message.content.trim(),
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
console.error('Content is null');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
console.log('Batch processing completed successfully.');
|
|
84
|
+
return responses;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.error('Error in callDeepSeekBatch:', error);
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
},
|
|
24
91
|
callChatGPT: {
|
|
25
92
|
single: async (
|
|
26
93
|
messages: ChatMessages,
|
package/app/base/AppContext.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { drizzle } from 'drizzle-orm/d1';
|
|
2
2
|
import * as schema from '../../db/schema';
|
|
3
3
|
import { BackendBindings } from '../../types';
|
|
4
|
-
import {
|
|
4
|
+
import { buildLLMMessages } from '../../utils/buildMessages';
|
|
5
5
|
import { Api } from '../api';
|
|
6
6
|
|
|
7
7
|
export class AppContext {
|
|
@@ -9,8 +9,8 @@ export class AppContext {
|
|
|
9
9
|
|
|
10
10
|
constructor(public env: BackendBindings) {}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
return
|
|
12
|
+
buildLLMMessages() {
|
|
13
|
+
return buildLLMMessages(this.env);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
kvCosmicMirrorArchetypesStore() {
|
|
@@ -19,12 +19,10 @@ export class ConceptService {
|
|
|
19
19
|
`Generating basic info for concept: ${conceptSlug}, combination: ${combinationString}`
|
|
20
20
|
);
|
|
21
21
|
|
|
22
|
-
const messages = this.context
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
conceptSlug,
|
|
27
|
-
});
|
|
22
|
+
const messages = this.context.buildLLMMessages().generateConceptBasicInfo({
|
|
23
|
+
combination: combinationString,
|
|
24
|
+
conceptSlug,
|
|
25
|
+
});
|
|
28
26
|
|
|
29
27
|
const response = await this.context.api().callChatGPT.single(messages, {});
|
|
30
28
|
if (!response) {
|
|
@@ -86,7 +84,7 @@ export class ConceptService {
|
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
const messages = this.context
|
|
89
|
-
.
|
|
87
|
+
.buildLLMMessages()
|
|
90
88
|
.generateConceptLeonardoPrompt({
|
|
91
89
|
conceptSlug,
|
|
92
90
|
combination: combinationString,
|
|
@@ -125,15 +123,13 @@ export class ConceptService {
|
|
|
125
123
|
);
|
|
126
124
|
}
|
|
127
125
|
|
|
128
|
-
const messages = this.context
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
poem: concept.poem,
|
|
136
|
-
});
|
|
126
|
+
const messages = this.context.buildLLMMessages().generateConceptContent({
|
|
127
|
+
conceptSlug,
|
|
128
|
+
combination: combinationString,
|
|
129
|
+
name: concept.name,
|
|
130
|
+
description: concept.description,
|
|
131
|
+
poem: concept.poem,
|
|
132
|
+
});
|
|
137
133
|
|
|
138
134
|
const response = await this.context.api().callChatGPT.single(messages, {});
|
|
139
135
|
if (!response) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zodic/shared",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.72",
|
|
4
4
|
"module": "index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"hono": "^4.6.13",
|
|
32
32
|
"inversify": "^6.2.1",
|
|
33
33
|
"jose": "^5.9.6",
|
|
34
|
+
"openai": "^4.81.0",
|
|
34
35
|
"reflect-metadata": "^0.2.2"
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -54,6 +54,7 @@ export type CentralBindings = {
|
|
|
54
54
|
ASTROLOGY_PDF_USER_ID: string;
|
|
55
55
|
ASTROLOGY_PDF_API_KEY: string;
|
|
56
56
|
PIAPI_API_KEY: string;
|
|
57
|
+
DEEPSEEK_API_KEY: string;
|
|
57
58
|
|
|
58
59
|
API_BASE_URL: string;
|
|
59
60
|
PUBLIC_GOOGLE_CLIENT_ID: string;
|
|
@@ -113,6 +114,7 @@ export type BackendBindings = Env &
|
|
|
113
114
|
| 'PIAPI_API_KEY'
|
|
114
115
|
| 'CONCEPT_GENERATION_QUEUE'
|
|
115
116
|
| 'KV_CONCEPTS_MANAGEMENT'
|
|
117
|
+
| 'DEEPSEEK_API_KEY'
|
|
116
118
|
>;
|
|
117
119
|
|
|
118
120
|
export type BackendCtx = Context<
|
package/types/scopes/generic.ts
CHANGED
|
@@ -17,7 +17,6 @@ export const ProductType = {
|
|
|
17
17
|
REPORT: 'report',
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
|
|
21
20
|
export const VALID_GENDERS_ARRAY = ['male', 'female', 'non-binary'] as const;
|
|
22
21
|
|
|
23
22
|
export type Gender = (typeof VALID_GENDERS_ARRAY)[number];
|
|
@@ -241,3 +240,13 @@ export const ConceptPhases: Record<string, ConceptPhase> = {
|
|
|
241
240
|
CONTENT: 'content',
|
|
242
241
|
IMAGES: 'images',
|
|
243
242
|
};
|
|
243
|
+
|
|
244
|
+
export type DeepSeekOptions = { model?: string; options?: Record<string, any> };
|
|
245
|
+
export type DeepSeekBatchInputItem = {
|
|
246
|
+
messages: ChatMessages;
|
|
247
|
+
options?: DeepSeekOptions;
|
|
248
|
+
};
|
|
249
|
+
export type DeepSeekBatchResponse = Array<{
|
|
250
|
+
input: DeepSeekBatchInputItem;
|
|
251
|
+
output: string;
|
|
252
|
+
}>;
|
package/utils/buildMessages.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BackendBindings, ChatMessages, Crown } from '../types';
|
|
2
2
|
import { conceptPrompts } from './conceptPrompts';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const buildLLMMessages = (env: BackendBindings) => ({
|
|
5
5
|
generateCosmicMirrorArchetypeBasicInfo: ({
|
|
6
6
|
sun,
|
|
7
7
|
ascendant,
|
|
@@ -106,7 +106,7 @@ export const buildChatGPTMessages = (env: BackendBindings) => ({
|
|
|
106
106
|
description,
|
|
107
107
|
poem,
|
|
108
108
|
combination,
|
|
109
|
-
conceptSlug
|
|
109
|
+
conceptSlug,
|
|
110
110
|
}: {
|
|
111
111
|
name: string;
|
|
112
112
|
description: string;
|