Upload 18 files
Browse files- DOCKER.md +26 -0
- src/pow.js +6 -3
DOCKER.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Docker usage
|
| 2 |
+
|
| 3 |
+
Build:
|
| 4 |
+
|
| 5 |
+
```bash
|
| 6 |
+
docker build -t deepseek-2api .
|
| 7 |
+
```
|
| 8 |
+
|
| 9 |
+
Run on default port 7860:
|
| 10 |
+
|
| 11 |
+
```bash
|
| 12 |
+
docker run -d --name deepseek-2api -p 7860:7860 \
|
| 13 |
+
-e DS_TOKEN=your_token \
|
| 14 |
+
-e API_KEY=your_api_key \
|
| 15 |
+
deepseek-2api
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
Environment variables:
|
| 19 |
+
|
| 20 |
+
- `DS_TOKEN`: DeepSeek token. Takes precedence.
|
| 21 |
+
- `DS_EMAIL` / `DS_PASSWORD`: DeepSeek email/password fallback.
|
| 22 |
+
- `PORT`: service port. Defaults to `7860`.
|
| 23 |
+
- `API_KEY`: optional service API key. Leave empty to disable auth.
|
| 24 |
+
- `USE_WASM_POW`: optional. Set to `false` to skip WASM PoW and use BigInt directly.
|
| 25 |
+
|
| 26 |
+
If you have `sha3_wasm_bg.wasm`, place it in the project root before building. The Docker image will copy it. If it is absent, the service automatically falls back to the BigInt implementation.
|
src/pow.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import { pickToken } from './auth.js';
|
| 2 |
import { apiHeaders, proxiedFetch } from './headers.js';
|
| 3 |
-
import { readFileSync } from 'fs';
|
| 4 |
import { fileURLToPath } from 'url';
|
| 5 |
import { dirname, join } from 'path';
|
| 6 |
|
|
@@ -12,6 +12,9 @@ let wasmInstance = null;
|
|
| 12 |
async function getWasm() {
|
| 13 |
if (wasmInstance) return wasmInstance;
|
| 14 |
const wasmPath = join(dirname(fileURLToPath(import.meta.url)), '..', 'sha3_wasm_bg.wasm');
|
|
|
|
|
|
|
|
|
|
| 15 |
const wasmBuf = readFileSync(wasmPath);
|
| 16 |
const { instance } = await WebAssembly.instantiate(wasmBuf, { wbg: {} });
|
| 17 |
wasmInstance = instance;
|
|
@@ -151,7 +154,7 @@ function solvePowBigInt(challengeHex, salt, expireAt, difficulty) {
|
|
| 151 |
throw new Error('PoW solve failed: no solution within difficulty');
|
| 152 |
}
|
| 153 |
|
| 154 |
-
let useWasm =
|
| 155 |
|
| 156 |
async function solvePowInternal(token, targetPath = '/api/v0/chat/completion') {
|
| 157 |
const res = await proxiedFetch(`${BASE_URL}/api/v0/chat/create_pow_challenge`, {
|
|
@@ -181,7 +184,7 @@ async function solvePowInternal(token, targetPath = '/api/v0/chat/completion') {
|
|
| 181 |
const instance = await getWasm();
|
| 182 |
answer = wasmSolve(instance, c.challenge, prefix, difficulty);
|
| 183 |
} catch (e) {
|
| 184 |
-
console.warn('WASM PoW
|
| 185 |
useWasm = false;
|
| 186 |
answer = solvePowBigInt(c.challenge, c.salt, c.expire_at, difficulty);
|
| 187 |
}
|
|
|
|
| 1 |
import { pickToken } from './auth.js';
|
| 2 |
import { apiHeaders, proxiedFetch } from './headers.js';
|
| 3 |
+
import { existsSync, readFileSync } from 'fs';
|
| 4 |
import { fileURLToPath } from 'url';
|
| 5 |
import { dirname, join } from 'path';
|
| 6 |
|
|
|
|
| 12 |
async function getWasm() {
|
| 13 |
if (wasmInstance) return wasmInstance;
|
| 14 |
const wasmPath = join(dirname(fileURLToPath(import.meta.url)), '..', 'sha3_wasm_bg.wasm');
|
| 15 |
+
if (!existsSync(wasmPath)) {
|
| 16 |
+
throw new Error(`WASM file not found at ${wasmPath}`);
|
| 17 |
+
}
|
| 18 |
const wasmBuf = readFileSync(wasmPath);
|
| 19 |
const { instance } = await WebAssembly.instantiate(wasmBuf, { wbg: {} });
|
| 20 |
wasmInstance = instance;
|
|
|
|
| 154 |
throw new Error('PoW solve failed: no solution within difficulty');
|
| 155 |
}
|
| 156 |
|
| 157 |
+
let useWasm = process.env.USE_WASM_POW !== 'false';
|
| 158 |
|
| 159 |
async function solvePowInternal(token, targetPath = '/api/v0/chat/completion') {
|
| 160 |
const res = await proxiedFetch(`${BASE_URL}/api/v0/chat/create_pow_challenge`, {
|
|
|
|
| 184 |
const instance = await getWasm();
|
| 185 |
answer = wasmSolve(instance, c.challenge, prefix, difficulty);
|
| 186 |
} catch (e) {
|
| 187 |
+
console.warn('WASM PoW unavailable, falling back to BigInt:', e.message);
|
| 188 |
useWasm = false;
|
| 189 |
answer = solvePowBigInt(c.challenge, c.salt, c.expire_at, difficulty);
|
| 190 |
}
|