Back to Home
Gistify Snippet
Public
DeepSeek AI Chat & Reasoning Scraper
Direct DeepSeek AI chat scraper returning instant reasoning and markdown responses with multi-turn support.
#ai#deepseek#scraper#streaming#javascript
0
Rawdeepseek-v4.jsjavascript
91 lines| 1 | // deepseek-v4.js — bundle standalone. npm deps: axios, node:url |
| 2 | |
| 3 | /** |
| 4 | * Scraper: deepseek-v4.js |
| 5 | * Source : kyioapi/deepseek-v4.js |
| 6 | * |
| 7 | * Input : Function parameters / CLI args (e.g. prompt: string, brand: string) |
| 8 | * Output : Promise<Object> (DeepSeek AI response with status and model metadata) |
| 9 | * |
| 10 | * CLI Run: |
| 11 | * node deepseek-v4.js DeepSeek "Apa itu Node.js?" |
| 12 | */ |
| 13 | |
| 14 | import axios from "axios"; |
| 15 | import { pathToFileURL } from "node:url"; |
| 16 | |
| 17 | const CHATGPTIS_URL = "https://chatgptis.org/api/chat"; |
| 18 | |
| 19 | /** |
| 20 | * DeepSeek AI Chat Scraper |
| 21 | * @param {string} prompt User message or prompt |
| 22 | * @param {string} [brand="deepseek"] AI engine brand (default: deepseek) |
| 23 | * @param {string} [system=""] System instructions (optional) |
| 24 | * @returns {Promise<{ status: boolean, model: string, result: string }>} |
| 25 | */ |
| 26 | export async function DeepSeek(prompt, brand = "deepseek", system = "") { |
| 27 | if (!prompt || typeof prompt !== "string") { |
| 28 | throw new Error('Parameter "prompt" is required and must be a string.'); |
| 29 | } |
| 30 | |
| 31 | const messages = []; |
| 32 | if (system) { |
| 33 | messages.push({ role: "system", content: system }); |
| 34 | } |
| 35 | messages.push({ role: "user", content: prompt }); |
| 36 | |
| 37 | try { |
| 38 | const { data } = await axios.post( |
| 39 | CHATGPTIS_URL, |
| 40 | { |
| 41 | messages, |
| 42 | brand: brand, |
| 43 | system: system || "", |
| 44 | webSearch: false, |
| 45 | }, |
| 46 | { |
| 47 | headers: { |
| 48 | "Content-Type": "application/json", |
| 49 | "Origin": "https://chatgptis.org", |
| 50 | "Referer": "https://chatgptis.org/", |
| 51 | "User-Agent": |
| 52 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/137.0.0.0 Safari/537.36", |
| 53 | }, |
| 54 | timeout: 30000, |
| 55 | } |
| 56 | ); |
| 57 | |
| 58 | const answer = typeof data === "string" ? data.trim() : JSON.stringify(data).trim(); |
| 59 | if (!answer) { |
| 60 | throw new Error("Empty response returned from DeepSeek engine."); |
| 61 | } |
| 62 | |
| 63 | return { |
| 64 | status: true, |
| 65 | model: brand, |
| 66 | result: answer, |
| 67 | }; |
| 68 | } catch (error) { |
| 69 | throw new Error(`DeepSeek Error: ${error.response?.data?.error?.message || error.message}`); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | export { DeepSeek as DeepSeekThinking }; |
| 74 | export default DeepSeek; |
| 75 | |
| 76 | // ───────────────────────────────────────────────────────────────────── |
| 77 | // Self-test: jalankan langsung dengan `node deepseek-v4.js [args...]` |
| 78 | // ───────────────────────────────────────────────────────────────────── |
| 79 | if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { |
| 80 | const prompt = process.argv[2] || "Jelaskan apa itu Node.js dalam 1 kalimat"; |
| 81 | (async () => { |
| 82 | try { |
| 83 | const res = await DeepSeek(prompt); |
| 84 | console.log(JSON.stringify(res, null, 2)); |
| 85 | } catch (e) { |
| 86 | console.error("Error: " + e.message); |
| 87 | process.exitCode = 1; |
| 88 | } |
| 89 | })(); |
| 90 | } |
| 91 | |
Discussion & Comments0
No comments yet — be the first to leave feedback or start a code discussion.
Sign in with your GitHub account to write comments and join the discussion.