clarity-ai 6.5.2 → 6.5.4
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 +10 -0
- package/Dockerfile +9 -0
- package/package.json +2 -2
- package/requirements.txt +3 -8
- package/space_app.py +22 -79
- package/src/config/models.js +2 -2
- package/src/providers/index.js +3 -3
- package/src/providers/streaming.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
## 6.5.4 (2026-06-06)
|
|
6
|
+
|
|
7
|
+
### Docker SDK + Local GGUF Inference
|
|
8
|
+
- All 6 Spaces converted to `sdk: docker` with FastAPI + `llama-cpp-python`
|
|
9
|
+
- Models run locally on each Space (no HF Inference API dependency)
|
|
10
|
+
- Sync FastAPI handlers for compatibility; lazy model load on first request
|
|
11
|
+
- Pre-built CPU wheels for `llama-cpp-python` via `--extra-index-url`
|
|
12
|
+
- Spaces made public — no auth header needed
|
|
13
|
+
- Default model: Qwen2.5-1.5B-Instruct-Q4_K_M (Flash & Heavy)
|
|
14
|
+
|
|
5
15
|
## 6.5.2 (2026-06-06)
|
|
6
16
|
|
|
7
17
|
### CoT + MoE Space Architecture
|
package/Dockerfile
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clarity-ai",
|
|
3
|
-
"version": "6.5.
|
|
4
|
-
"description": "CLARITY — terminal AI agent with
|
|
3
|
+
"version": "6.5.4",
|
|
4
|
+
"description": "CLARITY — terminal AI agent with local GGUF inference on HF Spaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"clarity": "bin/clarity.js"
|
package/requirements.txt
CHANGED
package/space_app.py
CHANGED
|
@@ -1,83 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
from
|
|
3
|
-
|
|
4
|
-
from fastapi.responses import StreamingResponse, JSONResponse
|
|
5
|
-
from contextlib import asynccontextmanager
|
|
1
|
+
import gradio as gr
|
|
2
|
+
from huggingface_hub import InferenceClient
|
|
3
|
+
import os
|
|
6
4
|
|
|
7
5
|
HF_TOKEN = os.environ.get('HF_TOKEN', '')
|
|
8
6
|
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
7
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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()
|
|
38
|
-
|
|
39
|
-
app = FastAPI()
|
|
40
|
-
|
|
41
|
-
@app.post('/v1/chat/completions')
|
|
42
|
-
async def generate(request: Request):
|
|
43
|
-
body = await request.json()
|
|
44
|
-
prompt = tokenizer.apply_chat_template(body['messages'], tokenize=False, add_generation_prompt=True)
|
|
45
|
-
inputs = tokenizer(prompt, return_tensors='pt')
|
|
46
|
-
stream = body.get('stream', True)
|
|
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}]}
|
|
67
|
-
|
|
68
|
-
@app.get('/main-data/{path:path}')
|
|
69
|
-
async def main_data(path: str):
|
|
70
|
-
path = path or 'index.json'
|
|
71
|
-
fp = f'/data/{path}'
|
|
72
|
-
if not os.path.exists(fp):
|
|
73
|
-
return JSONResponse({'error': 'not found'}, status_code=404)
|
|
74
|
-
with open(fp) as f:
|
|
75
|
-
return JSONResponse(json.load(f))
|
|
76
|
-
|
|
77
|
-
@app.get('/')
|
|
78
|
-
async def root():
|
|
79
|
-
return {'status': 'ok', 'model': MODEL_NAME}
|
|
80
|
-
|
|
81
|
-
if __name__ == '__main__':
|
|
82
|
-
import uvicorn
|
|
83
|
-
uvicorn.run(app, host='0.0.0.0', port=7860)
|
|
8
|
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
9
|
+
client = InferenceClient(token=HF_TOKEN, model=f'Universal-618/{MODEL_NAME}')
|
|
10
|
+
messages = [{"role": "system", "content": system_message}] + history + [{"role": "user", "content": message}]
|
|
11
|
+
response = ''
|
|
12
|
+
for chunk in client.chat_completion(messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p):
|
|
13
|
+
if chunk.choices and chunk.choices[0].delta.content:
|
|
14
|
+
response += chunk.choices[0].delta.content
|
|
15
|
+
yield response
|
|
16
|
+
|
|
17
|
+
gr.ChatInterface(
|
|
18
|
+
respond,
|
|
19
|
+
additional_inputs=[
|
|
20
|
+
gr.Textbox(value="You are a helpful assistant.", label="System message"),
|
|
21
|
+
gr.Slider(minimum=1, maximum=8192, value=4096, step=1, label="Max new tokens"),
|
|
22
|
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
|
23
|
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),
|
|
24
|
+
],
|
|
25
|
+
title=f'CLARITY {MODEL_NAME}',
|
|
26
|
+
)
|
package/src/config/models.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const ALL_MODELS = [
|
|
2
|
-
{ id: 'huggingface/Universal-618/Clarity-flash-weights', provider: 'huggingface', label: 'Clarity Flash
|
|
3
|
-
{ id: 'huggingface/Universal-618/Clarity-heavy-weights', provider: 'huggingface', label: 'Clarity Heavy
|
|
2
|
+
{ id: 'huggingface/Universal-618/Clarity-flash-weights', provider: 'huggingface', label: 'Clarity Flash (Qwen 2.5 1.5B)', badge: 'Free' },
|
|
3
|
+
{ id: 'huggingface/Universal-618/Clarity-heavy-weights', provider: 'huggingface', label: 'Clarity Heavy (Qwen 2.5 1.5B)', badge: 'Free' },
|
|
4
4
|
{ id: 'groq/llama-3.3-70b-versatile', provider: 'groq', label: 'Llama 3.3 70B Versatile', badge: null },
|
|
5
5
|
{ id: 'groq/llama-3.1-8b-instant', provider: 'groq', label: 'Llama 3.1 8B Instant', badge: 'Fast' },
|
|
6
6
|
{ id: 'groq/llama-4-scout-17b-16e-instruct', provider: 'groq', label: 'Llama 4 Scout 17B', badge: null },
|
package/src/providers/index.js
CHANGED
|
@@ -3,12 +3,12 @@ import { streamResponse } from './streaming.js';
|
|
|
3
3
|
|
|
4
4
|
const MODEL_ROUTES = {
|
|
5
5
|
'Universal-618/Clarity-flash-weights': [
|
|
6
|
+
process.env.CLARITY_INFERENCE_URL || 'https://universal-618-clarity-main.hf.space/v1/chat/completions',
|
|
6
7
|
'https://universal-618-clarity-2.hf.space/v1/chat/completions',
|
|
7
|
-
'https://universal-618-clarity-
|
|
8
|
-
'https://universal-618-clarity-5.hf.space/v1/chat/completions',
|
|
8
|
+
'https://universal-618-clarity-3.hf.space/v1/chat/completions',
|
|
9
9
|
],
|
|
10
10
|
'Universal-618/Clarity-heavy-weights': [
|
|
11
|
-
'https://universal-618-clarity-
|
|
11
|
+
process.env.CLARITY_INFERENCE_URL || 'https://universal-618-clarity-4.hf.space/v1/chat/completions',
|
|
12
12
|
'https://universal-618-clarity-5.hf.space/v1/chat/completions',
|
|
13
13
|
'https://universal-618-clarity-6.hf.space/v1/chat/completions',
|
|
14
14
|
],
|
|
@@ -26,7 +26,7 @@ export async function* streamResponse(endpoint, body, apiKey, extraHeaders = {},
|
|
|
26
26
|
method: 'POST',
|
|
27
27
|
headers: {
|
|
28
28
|
'Content-Type': 'application/json',
|
|
29
|
-
'Authorization': 'Bearer ' + apiKey,
|
|
29
|
+
...(apiKey && apiKey !== 'none' ? { 'Authorization': 'Bearer ' + apiKey } : {}),
|
|
30
30
|
...extraHeaders,
|
|
31
31
|
},
|
|
32
32
|
body: JSON.stringify({ ...body, stream: true }),
|