mohdel 1.1.0 → 1.3.0
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/README.md +2 -0
- package/config/curated.schema.json +41 -3
- package/js/client/call_embedding.js +50 -0
- package/js/client/index.js +1 -0
- package/js/core/embedding.js +76 -0
- package/js/factory/bridge.js +44 -0
- package/js/session/_rate_limiter.js +33 -7
- package/js/session/adapters/_pricing.js +19 -1
- package/js/session/adapters/embedding/_shared.js +92 -0
- package/js/session/adapters/embedding/cohere.js +91 -0
- package/js/session/adapters/embedding/gemini.js +92 -0
- package/js/session/adapters/embedding/index.js +37 -0
- package/js/session/adapters/embedding/openai_compatible.js +92 -0
- package/js/session/driver.js +11 -0
- package/js/session/run_embedding.js +94 -0
- package/package.json +2 -2
- package/src/cli/complete.js +1 -0
- package/src/cli/index.js +2 -2
- package/src/cli/ratelimit.js +118 -47
- package/src/lib/creators.js +12 -0
- package/src/lib/index.js +39 -20
- package/src/lib/provider-info.js +7 -0
- package/src/lib/providers.js +12 -0
- package/src/lib/schema.js +9 -0
- package/src/lib/rate-limiter.js +0 -50
package/src/lib/provider-info.js
CHANGED
|
@@ -86,6 +86,13 @@ const PROVIDER_INFO = {
|
|
|
86
86
|
hint: 'Create an API key in the MiMo open platform console',
|
|
87
87
|
free: false
|
|
88
88
|
},
|
|
89
|
+
cohere: {
|
|
90
|
+
label: 'Cohere',
|
|
91
|
+
description: 'Embeddings and reranking for retrieval. No chat models through mohdel.',
|
|
92
|
+
url: 'https://dashboard.cohere.com/api-keys',
|
|
93
|
+
hint: 'Create an API key in the Cohere dashboard under API Keys',
|
|
94
|
+
free: true
|
|
95
|
+
},
|
|
89
96
|
qwen: {
|
|
90
97
|
label: 'Qwen Cloud',
|
|
91
98
|
description: 'Qwen — reasoning, coding, long context. Free quota for new users.',
|
package/src/lib/providers.js
CHANGED
|
@@ -86,6 +86,18 @@ const providers = {
|
|
|
86
86
|
contextSemantics: 'shared',
|
|
87
87
|
outputCapStrategy: 'accept'
|
|
88
88
|
},
|
|
89
|
+
cohere: {
|
|
90
|
+
sdk: 'cohere',
|
|
91
|
+
api: 'embeddings',
|
|
92
|
+
apiKeyEnv: 'COHERE_API_SK',
|
|
93
|
+
baseURL: 'https://api.cohere.com/v2',
|
|
94
|
+
createConfiguration: apiKey => ({ apiKey }),
|
|
95
|
+
references: {
|
|
96
|
+
pricing: 'https://cohere.com/pricing',
|
|
97
|
+
models: 'https://docs.cohere.com/docs/models',
|
|
98
|
+
rateLimits: 'https://docs.cohere.com/docs/rate-limits'
|
|
99
|
+
}
|
|
100
|
+
},
|
|
89
101
|
mistral: {
|
|
90
102
|
sdk: 'openai',
|
|
91
103
|
api: 'chatCompletions',
|
package/src/lib/schema.js
CHANGED
|
@@ -58,10 +58,18 @@ const fieldDefs = {
|
|
|
58
58
|
imageEndpoint: { type: 'string' },
|
|
59
59
|
imageDefaultSize: { type: 'string' },
|
|
60
60
|
transcriptionPrice: { type: 'number' },
|
|
61
|
+
embeddingPrice: { type: 'number' },
|
|
62
|
+
dimensions: { type: 'number' },
|
|
63
|
+
dimensionsSelectable: { type: 'boolean' },
|
|
64
|
+
maxBatch: { type: 'number' },
|
|
65
|
+
maxInputTokens: { type: 'number' },
|
|
66
|
+
inputTypes: { type: 'object' },
|
|
67
|
+
defaultInputType: { type: 'string' },
|
|
61
68
|
deprecated: { type: 'string' },
|
|
62
69
|
suspended: { type: 'string' },
|
|
63
70
|
rpmLimit: { type: 'number' },
|
|
64
71
|
tpmLimit: { type: 'number' },
|
|
72
|
+
inpmLimit: { type: 'number' },
|
|
65
73
|
rateLimitScope: { type: 'string', validate: (v) => ['model', 'provider'].includes(v) ? null : 'must be "model" or "provider"' },
|
|
66
74
|
outputCapStrategy: { type: 'string', validate: (v) => ['error', 'accept'].includes(v) ? null : "must be 'error' or 'accept'" },
|
|
67
75
|
supportsTools: { type: 'boolean' },
|
|
@@ -77,6 +85,7 @@ const COMPUTED_FIELDS = new Set(['upstreamIds'])
|
|
|
77
85
|
const TYPE_CHECKERS = {
|
|
78
86
|
string: (v) => typeof v === 'string',
|
|
79
87
|
number: (v) => typeof v === 'number',
|
|
88
|
+
boolean: (v) => typeof v === 'boolean',
|
|
80
89
|
array: (v) => Array.isArray(v),
|
|
81
90
|
object: (v) => typeof v === 'object' && v !== null && !Array.isArray(v)
|
|
82
91
|
}
|
package/src/lib/rate-limiter.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// Lightweight per-minute rate limiter.
|
|
2
|
-
// Tracks RPM and TPM with minute-bucket granularity.
|
|
3
|
-
// Throttles (delays) rather than rejects — returns ms to wait.
|
|
4
|
-
|
|
5
|
-
const createRateLimiter = () => {
|
|
6
|
-
// key → { count, tokens, minute }
|
|
7
|
-
const buckets = new Map()
|
|
8
|
-
|
|
9
|
-
const currentMinute = () => Math.floor(Date.now() / 60000)
|
|
10
|
-
|
|
11
|
-
const getBucket = (key) => {
|
|
12
|
-
const minute = currentMinute()
|
|
13
|
-
const bucket = buckets.get(key)
|
|
14
|
-
if (bucket && bucket.minute === minute) return bucket
|
|
15
|
-
const fresh = { count: 0, tokens: 0, minute }
|
|
16
|
-
buckets.set(key, fresh)
|
|
17
|
-
return fresh
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const msUntilNextMinute = (minute) => Math.max(0, (minute + 1) * 60000 - Date.now())
|
|
21
|
-
|
|
22
|
-
// Returns ms to wait before sending (0 = go ahead)
|
|
23
|
-
const check = (key, { rpmLimit, tpmLimit } = {}) => {
|
|
24
|
-
if (!rpmLimit && !tpmLimit) return 0
|
|
25
|
-
const bucket = getBucket(key)
|
|
26
|
-
if (rpmLimit && bucket.count >= rpmLimit) {
|
|
27
|
-
return msUntilNextMinute(bucket.minute)
|
|
28
|
-
}
|
|
29
|
-
if (tpmLimit && bucket.tokens >= tpmLimit) {
|
|
30
|
-
return msUntilNextMinute(bucket.minute)
|
|
31
|
-
}
|
|
32
|
-
return 0
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Record a request count (call before sending — RPM tracking)
|
|
36
|
-
const recordRequest = (key) => {
|
|
37
|
-
const bucket = getBucket(key)
|
|
38
|
-
bucket.count++
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Record token usage (call after response — TPM tracking)
|
|
42
|
-
const recordTokens = (key, tokens) => {
|
|
43
|
-
const bucket = getBucket(key)
|
|
44
|
-
bucket.tokens += tokens
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return { check, recordRequest, recordTokens }
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export default createRateLimiter
|