@danonino/moon 1.0.3 → 1.0.5
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/package.json +1 -1
- package/src/deepseek.js +16 -28
package/package.json
CHANGED
package/src/deepseek.js
CHANGED
|
@@ -19,15 +19,19 @@ const client = wrapper(
|
|
|
19
19
|
let csrfToken = null;
|
|
20
20
|
|
|
21
21
|
async function initSession() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
try {
|
|
23
|
+
const res = await client.get("https://deep-seek.ai/chat");
|
|
24
|
+
const $ = cheerio.load(res.data);
|
|
25
|
+
csrfToken = $('meta[name="csrf-token"]').attr("content") || $('input[name="_token"]').val();
|
|
26
|
+
if (!csrfToken) {
|
|
27
|
+
throw new Error("Gagal mendapatkan CSRF Token.");
|
|
28
|
+
}
|
|
29
|
+
} catch (e) {
|
|
30
|
+
throw new Error("Failed to initialize session: " + e.message);
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
async function
|
|
34
|
+
async function deepseek(prompt) {
|
|
31
35
|
try {
|
|
32
36
|
if (!csrfToken) {
|
|
33
37
|
await initSession();
|
|
@@ -51,7 +55,7 @@ async function DeepSeek(prompt) {
|
|
|
51
55
|
}
|
|
52
56
|
);
|
|
53
57
|
|
|
54
|
-
return await new Promise((resolve
|
|
58
|
+
return await new Promise((resolve) => {
|
|
55
59
|
let full = "";
|
|
56
60
|
res.data.on("data", chunk => {
|
|
57
61
|
const text = chunk.toString();
|
|
@@ -70,13 +74,13 @@ async function DeepSeek(prompt) {
|
|
|
70
74
|
res.data.on("end", () => {
|
|
71
75
|
resolve({
|
|
72
76
|
status: true,
|
|
73
|
-
result: full.trim()
|
|
77
|
+
result: full.trim() || "No response from DeepSeek"
|
|
74
78
|
});
|
|
75
79
|
});
|
|
76
|
-
res.data.on("error", err => {
|
|
80
|
+
res.data.on("error", (err) => {
|
|
77
81
|
resolve({
|
|
78
82
|
status: false,
|
|
79
|
-
error: err.message
|
|
83
|
+
error: err.message || "Stream error"
|
|
80
84
|
});
|
|
81
85
|
});
|
|
82
86
|
});
|
|
@@ -84,25 +88,9 @@ async function DeepSeek(prompt) {
|
|
|
84
88
|
} catch (e) {
|
|
85
89
|
return {
|
|
86
90
|
status: false,
|
|
87
|
-
error: e.
|
|
91
|
+
error: e.message || "Unknown error occurred"
|
|
88
92
|
};
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
|
|
92
|
-
|
|
93
|
-
if (require.main === module) {
|
|
94
|
-
const prompt = process.argv.slice(2).join(" ");
|
|
95
|
-
if (!prompt) {
|
|
96
|
-
console.log(JSON.stringify({
|
|
97
|
-
status: false,
|
|
98
|
-
error: "Usage: node deepseek.js halo+kawan"
|
|
99
|
-
}, null, 2));
|
|
100
|
-
process.exit();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
DeepSeek(prompt)
|
|
104
|
-
.then(res => console.log(JSON.stringify(res, null, 2)))
|
|
105
|
-
.catch(err => console.log(JSON.stringify(err, null, 2)));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
module.exports = DeepSeek;
|
|
96
|
+
module.exports = deepseek;
|