@zodic/shared 0.0.148 → 0.0.149
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 +63 -0
- package/app/services/ConceptService.ts +3 -3
- package/package.json +1 -1
package/app/api/index.ts
CHANGED
|
@@ -28,7 +28,70 @@ const deepseek = (env: BackendBindings) =>
|
|
|
28
28
|
baseURL: 'https://api.deepseek.com/v1',
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
+
const together = (env: BackendBindings) =>
|
|
32
|
+
new OpenAI({
|
|
33
|
+
apiKey: env.TOGETHER_API_KEY,
|
|
34
|
+
baseURL: 'https://api.together.xyz/v1',
|
|
35
|
+
});
|
|
36
|
+
|
|
31
37
|
export const Api = (env: BackendBindings) => ({
|
|
38
|
+
callTogether: {
|
|
39
|
+
single: async (
|
|
40
|
+
messages: ChatMessages,
|
|
41
|
+
{ model = 'deepseek-ai/DeepSeek-V3', options = {} }: DeepSeekOptions
|
|
42
|
+
): Promise<string> => {
|
|
43
|
+
try {
|
|
44
|
+
const response = await together(env).chat.completions.create({
|
|
45
|
+
model,
|
|
46
|
+
messages,
|
|
47
|
+
...options,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (response.choices[0].message.content) {
|
|
51
|
+
return response.choices[0].message.content.trim();
|
|
52
|
+
} else {
|
|
53
|
+
throw new Error('Content is null');
|
|
54
|
+
}
|
|
55
|
+
} catch (err: any) {
|
|
56
|
+
console.error('Error calling DeepSeek API:', err.message);
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
// batch: async (
|
|
62
|
+
// batchItems: DeepSeekBatchInputItem[]
|
|
63
|
+
// ): Promise<DeepSeekBatchResponse> => {
|
|
64
|
+
// console.log('Preparing to send DeepSeek batch request.');
|
|
65
|
+
|
|
66
|
+
// try {
|
|
67
|
+
// const responses: DeepSeekBatchResponse = [];
|
|
68
|
+
|
|
69
|
+
// for (const item of batchItems) {
|
|
70
|
+
// const { messages, options } = item;
|
|
71
|
+
// const response = await deepseek(env).chat.completions.create({
|
|
72
|
+
// model: options?.model || 'deepseek-v3',
|
|
73
|
+
// messages,
|
|
74
|
+
// ...options,
|
|
75
|
+
// });
|
|
76
|
+
|
|
77
|
+
// if (response.choices[0].message.content) {
|
|
78
|
+
// responses.push({
|
|
79
|
+
// input: item,
|
|
80
|
+
// output: response.choices[0].message.content.trim(),
|
|
81
|
+
// });
|
|
82
|
+
// } else {
|
|
83
|
+
// console.error('Content is null');
|
|
84
|
+
// }
|
|
85
|
+
// }
|
|
86
|
+
|
|
87
|
+
// console.log('Batch processing completed successfully.');
|
|
88
|
+
// return responses;
|
|
89
|
+
// } catch (error) {
|
|
90
|
+
// console.error('Error in callDeepSeekBatch:', error);
|
|
91
|
+
// throw error;
|
|
92
|
+
// }
|
|
93
|
+
// },
|
|
94
|
+
},
|
|
32
95
|
callDeepSeek: {
|
|
33
96
|
single: async (
|
|
34
97
|
messages: ChatMessages,
|
|
@@ -77,7 +77,7 @@ export class ConceptService {
|
|
|
77
77
|
// ✅ Call ChatGPT API
|
|
78
78
|
const response = await this.context
|
|
79
79
|
.api()
|
|
80
|
-
.
|
|
80
|
+
.callTogether.single(messages, {});
|
|
81
81
|
if (!response) {
|
|
82
82
|
throw new Error(`❌ AI returned an empty response`);
|
|
83
83
|
}
|
|
@@ -239,7 +239,7 @@ export class ConceptService {
|
|
|
239
239
|
});
|
|
240
240
|
|
|
241
241
|
// ✅ Call ChatGPT API
|
|
242
|
-
const response = await this.context.api().
|
|
242
|
+
const response = await this.context.api().callTogether.single(messages, {});
|
|
243
243
|
if (!response) {
|
|
244
244
|
throw new Error(
|
|
245
245
|
`❌ Failed to generate Leonardo prompt for concept: ${conceptSlug}`
|
|
@@ -327,7 +327,7 @@ export class ConceptService {
|
|
|
327
327
|
// ✅ Call ChatGPT API
|
|
328
328
|
const response = await this.context
|
|
329
329
|
.api()
|
|
330
|
-
.
|
|
330
|
+
.callTogether.single(messages, {});
|
|
331
331
|
if (!response) {
|
|
332
332
|
throw new Error(`❌ AI returned an empty response`);
|
|
333
333
|
}
|