@danonino/moon 1.0.0 → 1.0.2
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/index.mjs +1 -0
- package/package.json +1 -1
- package/src/deepseek.js +108 -0
package/index.mjs
CHANGED
|
@@ -12,5 +12,6 @@ export const sharpify = scraper.sharpify;
|
|
|
12
12
|
export const threadsdownload = scraper.threadsdownload;
|
|
13
13
|
export const twetterdownload = scraper.twetterdownload;
|
|
14
14
|
export const docs = scraper.docs;
|
|
15
|
+
export const deepseek = scraper.deepseek;
|
|
15
16
|
|
|
16
17
|
export default scraper;
|
package/package.json
CHANGED
package/src/deepseek.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const axios = require("axios");
|
|
2
|
+
const cheerio = require("cheerio");
|
|
3
|
+
const { CookieJar } = require("tough-cookie");
|
|
4
|
+
const { wrapper } = require("axios-cookiejar-support");
|
|
5
|
+
|
|
6
|
+
const jar = new CookieJar();
|
|
7
|
+
|
|
8
|
+
const client = wrapper(
|
|
9
|
+
axios.create({
|
|
10
|
+
jar,
|
|
11
|
+
withCredentials: true,
|
|
12
|
+
headers: {
|
|
13
|
+
"User-Agent":
|
|
14
|
+
"Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 Chrome/139 Mobile Safari/537.36"
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
let csrfToken = null;
|
|
20
|
+
|
|
21
|
+
async function initSession() {
|
|
22
|
+
const res = await client.get("https://deep-seek.ai/chat");
|
|
23
|
+
const $ = cheerio.load(res.data);
|
|
24
|
+
csrfToken = $('meta[name="csrf-token"]').attr("content") || $('input[name="_token"]').val();
|
|
25
|
+
if (!csrfToken) {
|
|
26
|
+
throw new Error("Gagal mendapatkan CSRF Token.");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function DeepSeek(prompt) {
|
|
31
|
+
try {
|
|
32
|
+
if (!csrfToken) {
|
|
33
|
+
await initSession();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const res = await client.post(
|
|
37
|
+
"https://deep-seek.ai/api/chat",
|
|
38
|
+
{
|
|
39
|
+
model: "deepseek/deepseek-chat-v3.1",
|
|
40
|
+
messages: [{ role: "user", content: prompt }]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
headers: {
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
Origin: "https://deep-seek.ai",
|
|
46
|
+
Referer: "https://deep-seek.ai/chat",
|
|
47
|
+
"X-Csrf-Token": csrfToken,
|
|
48
|
+
Accept: "text/event-stream"
|
|
49
|
+
},
|
|
50
|
+
responseType: "stream"
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return await new Promise((resolve, reject) => {
|
|
55
|
+
let full = "";
|
|
56
|
+
res.data.on("data", chunk => {
|
|
57
|
+
const text = chunk.toString();
|
|
58
|
+
const lines = text.split("\n");
|
|
59
|
+
for (const line of lines) {
|
|
60
|
+
if (!line.startsWith("data:")) continue;
|
|
61
|
+
const jsonStr = line.replace("data:", "").trim();
|
|
62
|
+
if (!jsonStr || jsonStr === "[DONE]") continue;
|
|
63
|
+
try {
|
|
64
|
+
const json = JSON.parse(jsonStr);
|
|
65
|
+
const content = json.choices?.[0]?.delta?.content || json.choices?.[0]?.message?.content || "";
|
|
66
|
+
if (content) full += content;
|
|
67
|
+
} catch {}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
res.data.on("end", () => {
|
|
71
|
+
resolve({
|
|
72
|
+
status: true,
|
|
73
|
+
result: full.trim()
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
res.data.on("error", err => {
|
|
77
|
+
resolve({
|
|
78
|
+
status: false,
|
|
79
|
+
error: err.message
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
} catch (e) {
|
|
85
|
+
return {
|
|
86
|
+
status: false,
|
|
87
|
+
error: e.response?.data || e.message || "Unknown Error"
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Si se ejecuta directamente
|
|
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;
|