clarity-ai 6.5.1 → 6.5.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/CHANGELOG.md +15 -0
- package/package.json +1 -1
- package/requirements.txt +7 -1
- package/space_app.py +56 -18
- package/src/config/models.js +1 -0
- package/src/providers/index.js +21 -26
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
## 6.5.2 (2026-06-06)
|
|
6
|
+
|
|
7
|
+
### CoT + MoE Space Architecture
|
|
8
|
+
- Dataset repos now hold LoRA weights (flash pushed to `Universal-618/Clarity-flash-weights` dataset)
|
|
9
|
+
- Space app downloads weights from dataset repo on startup, loads base model + LoRA in 4-bit, serves `/v1/chat/completions`
|
|
10
|
+
- CLI routes by model: Flash 14B → Clarity-2 (CoT), Heavy 20B → Clarity-3 (MoE)
|
|
11
|
+
- Multiple fallback Spaces for each model
|
|
12
|
+
- All 6 Spaces connected via shared bucket to Clarity-main
|
|
13
|
+
|
|
14
|
+
## 6.5.1 (2026-06-06)
|
|
15
|
+
|
|
16
|
+
### 6-Space Fallback
|
|
17
|
+
- All 6 Spaces tried in sequence for redundancy
|
|
18
|
+
- Lowercase HF Space URL fix
|
|
19
|
+
|
|
5
20
|
## 6.5.0 (2026-06-06)
|
|
6
21
|
|
|
7
22
|
### Closed Source + Space Proxy
|
package/package.json
CHANGED
package/requirements.txt
CHANGED
package/space_app.py
CHANGED
|
@@ -1,31 +1,69 @@
|
|
|
1
|
-
import os, json, asyncio
|
|
2
|
-
import
|
|
1
|
+
import os, json, time, asyncio
|
|
2
|
+
from threading import Thread
|
|
3
3
|
from fastapi import FastAPI, Request
|
|
4
4
|
from fastapi.responses import StreamingResponse, JSONResponse
|
|
5
5
|
from contextlib import asynccontextmanager
|
|
6
6
|
|
|
7
7
|
HF_TOKEN = os.environ.get('HF_TOKEN', '')
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
MODEL_NAME = os.environ.get('HF_MODEL', 'Clarity-flash-weights')
|
|
9
|
+
BASE_MODEL = os.environ.get('BASE_MODEL_ID', '')
|
|
10
|
+
DS = f'Universal-618/{MODEL_NAME}'
|
|
11
|
+
|
|
12
|
+
print(f'[startup] model={MODEL_NAME} base={BASE_MODEL}', flush=True)
|
|
13
|
+
|
|
14
|
+
model = None
|
|
15
|
+
tokenizer = None
|
|
16
|
+
|
|
17
|
+
def load_model():
|
|
18
|
+
global model, tokenizer
|
|
19
|
+
print('[startup] downloading weights...', flush=True)
|
|
20
|
+
from huggingface_hub import snapshot_download
|
|
21
|
+
path = snapshot_download(repo_id=DS, repo_type='dataset', token=HF_TOKEN)
|
|
22
|
+
print(f'[startup] weights at {path}', flush=True)
|
|
23
|
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, TextIteratorStreamer
|
|
24
|
+
from peft import PeftModel
|
|
25
|
+
bnb = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype='float16', bnb_4bit_use_double_quant=True)
|
|
26
|
+
print('[startup] loading base model...', flush=True)
|
|
27
|
+
base = AutoModelForCausalLM.from_pretrained(
|
|
28
|
+
BASE_MODEL, quantization_config=bnb, device_map='auto',
|
|
29
|
+
trust_remote_code=True, low_cpu_mem_usage=True, token=HF_TOKEN)
|
|
30
|
+
print('[startup] loading LoRA...', flush=True)
|
|
31
|
+
model = PeftModel.from_pretrained(base, path, token=HF_TOKEN)
|
|
32
|
+
tokenizer = AutoTokenizer.from_pretrained(path, token=HF_TOKEN)
|
|
33
|
+
if tokenizer.pad_token is None:
|
|
34
|
+
tokenizer.pad_token = tokenizer.eos_token
|
|
35
|
+
print('[startup] ready', flush=True)
|
|
36
|
+
|
|
37
|
+
load_model()
|
|
11
38
|
|
|
12
39
|
app = FastAPI()
|
|
13
40
|
|
|
14
41
|
@app.post('/v1/chat/completions')
|
|
15
|
-
async def
|
|
42
|
+
async def generate(request: Request):
|
|
16
43
|
body = await request.json()
|
|
17
|
-
body['
|
|
44
|
+
prompt = tokenizer.apply_chat_template(body['messages'], tokenize=False, add_generation_prompt=True)
|
|
45
|
+
inputs = tokenizer(prompt, return_tensors='pt')
|
|
18
46
|
stream = body.get('stream', True)
|
|
19
|
-
body
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
47
|
+
max_tokens = body.get('max_tokens', 4096)
|
|
48
|
+
gen_kwargs = dict(input_ids=inputs.input_ids, attention_mask=inputs.attention_mask,
|
|
49
|
+
max_new_tokens=max_tokens, temperature=body.get('temperature', 0.7),
|
|
50
|
+
do_sample=True, pad_token_id=tokenizer.pad_token_id)
|
|
51
|
+
if stream:
|
|
52
|
+
from transformers import TextIteratorStreamer
|
|
53
|
+
streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
|
|
54
|
+
t = Thread(target=model.generate, kwargs={**gen_kwargs, 'streamer': streamer})
|
|
55
|
+
t.start()
|
|
56
|
+
async def gen():
|
|
57
|
+
yield 'data: {"choices":[{"delta":{"role":"assistant"},"index":0}]}\n\n'
|
|
58
|
+
for text in streamer:
|
|
59
|
+
if text:
|
|
60
|
+
yield f'data: {json.dumps({"choices":[{"delta":{"content":text},"index":0}]})}\n\n'
|
|
61
|
+
yield 'data: [DONE]\n\n'
|
|
62
|
+
return StreamingResponse(gen(), media_type='text/event-stream', headers={
|
|
63
|
+
'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'X-Accel-Buffering': 'no'})
|
|
64
|
+
out = model.generate(**gen_kwargs)
|
|
65
|
+
text = tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
|
66
|
+
return {'choices': [{'message': {'role': 'assistant', 'content': text}, 'index': 0}]}
|
|
29
67
|
|
|
30
68
|
@app.get('/main-data/{path:path}')
|
|
31
69
|
async def main_data(path: str):
|
|
@@ -38,7 +76,7 @@ async def main_data(path: str):
|
|
|
38
76
|
|
|
39
77
|
@app.get('/')
|
|
40
78
|
async def root():
|
|
41
|
-
return {'status': 'ok', 'model':
|
|
79
|
+
return {'status': 'ok', 'model': MODEL_NAME}
|
|
42
80
|
|
|
43
81
|
if __name__ == '__main__':
|
|
44
82
|
import uvicorn
|
package/src/config/models.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export const ALL_MODELS = [
|
|
2
2
|
{ id: 'huggingface/Universal-618/Clarity-flash-weights', provider: 'huggingface', label: 'Clarity Flash 14B', badge: '128K' },
|
|
3
|
+
{ id: 'huggingface/Universal-618/Clarity-heavy-weights', provider: 'huggingface', label: 'Clarity Heavy 20B', badge: 'MoE' },
|
|
3
4
|
{ id: 'groq/llama-3.3-70b-versatile', provider: 'groq', label: 'Llama 3.3 70B Versatile', badge: null },
|
|
4
5
|
{ id: 'groq/llama-3.1-8b-instant', provider: 'groq', label: 'Llama 3.1 8B Instant', badge: 'Fast' },
|
|
5
6
|
{ id: 'groq/llama-4-scout-17b-16e-instruct', provider: 'groq', label: 'Llama 4 Scout 17B', badge: null },
|
package/src/providers/index.js
CHANGED
|
@@ -1,35 +1,25 @@
|
|
|
1
1
|
import { getKey } from '../config/keys.js';
|
|
2
2
|
import { streamResponse } from './streaming.js';
|
|
3
|
-
import { parseErrorResponse } from './errors.js';
|
|
4
3
|
|
|
5
|
-
const
|
|
6
|
-
'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
'
|
|
12
|
-
|
|
4
|
+
const MODEL_ROUTES = {
|
|
5
|
+
'Universal-618/Clarity-flash-weights': [
|
|
6
|
+
'https://universal-618-clarity-2.hf.space/v1/chat/completions',
|
|
7
|
+
'https://universal-618-clarity-4.hf.space/v1/chat/completions',
|
|
8
|
+
'https://universal-618-clarity-5.hf.space/v1/chat/completions',
|
|
9
|
+
],
|
|
10
|
+
'Universal-618/Clarity-heavy-weights': [
|
|
11
|
+
'https://universal-618-clarity-3.hf.space/v1/chat/completions',
|
|
12
|
+
'https://universal-618-clarity-5.hf.space/v1/chat/completions',
|
|
13
|
+
'https://universal-618-clarity-6.hf.space/v1/chat/completions',
|
|
14
|
+
],
|
|
15
|
+
};
|
|
13
16
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
name: 'huggingface',
|
|
18
|
-
},
|
|
19
|
-
groq: {
|
|
20
|
-
endpoints: ['https://api.groq.com/openai/v1/chat/completions'],
|
|
21
|
-
name: 'groq',
|
|
22
|
-
},
|
|
23
|
-
openrouter: {
|
|
24
|
-
endpoints: ['https://openrouter.ai/api/v1/chat/completions'],
|
|
25
|
-
name: 'openrouter',
|
|
26
|
-
},
|
|
17
|
+
const STATIC_ENDPOINTS = {
|
|
18
|
+
groq: ['https://api.groq.com/openai/v1/chat/completions'],
|
|
19
|
+
openrouter: ['https://openrouter.ai/api/v1/chat/completions'],
|
|
27
20
|
};
|
|
28
21
|
|
|
29
22
|
export async function* callAI(providerName, model, messages, options = {}) {
|
|
30
|
-
const provider = PROVIDERS[providerName];
|
|
31
|
-
if (!provider) throw { type: 'config_error', message: 'Unknown provider: ' + providerName };
|
|
32
|
-
|
|
33
23
|
const key = getKey(providerName);
|
|
34
24
|
if (!key && providerName !== 'huggingface') {
|
|
35
25
|
throw { type: 'auth_error', provider: providerName, message: 'No API key set for ' + providerName, hint: '/keys ' + providerName + ' <your-key>' };
|
|
@@ -55,8 +45,13 @@ export async function* callAI(providerName, model, messages, options = {}) {
|
|
|
55
45
|
extraHeaders['X-Title'] = 'CLARITY AI';
|
|
56
46
|
}
|
|
57
47
|
|
|
48
|
+
const endpoints = MODEL_ROUTES[modelName] || STATIC_ENDPOINTS[providerName] || [];
|
|
49
|
+
if (!endpoints.length) {
|
|
50
|
+
throw { type: 'config_error', message: 'No endpoints for ' + providerName + '/' + modelName };
|
|
51
|
+
}
|
|
52
|
+
|
|
58
53
|
let lastErr;
|
|
59
|
-
for (const endpoint of
|
|
54
|
+
for (const endpoint of endpoints) {
|
|
60
55
|
try {
|
|
61
56
|
const stream = streamResponse(endpoint, body, key || 'none', extraHeaders, options.signal);
|
|
62
57
|
for await (const event of stream) {
|