clarity-ai 6.5.1 → 6.5.3

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 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/Dockerfile ADDED
@@ -0,0 +1,9 @@
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+ COPY requirements.txt .
5
+ RUN pip install --no-cache-dir -r requirements.txt
6
+ COPY app.py .
7
+
8
+ EXPOSE 7860
9
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clarity-ai",
3
- "version": "6.5.1",
3
+ "version": "6.5.3",
4
4
  "description": "CLARITY — terminal AI agent with Clarity Flash 14B",
5
5
  "type": "module",
6
6
  "bin": {
package/requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
- fastapi>=0.100
1
+ gradio>=5
2
+ huggingface-hub>=0.22
2
3
  httpx>=0.27
3
- uvicorn>=0.20
4
+ fastapi>=0.100
package/space_app.py CHANGED
@@ -1,45 +1,26 @@
1
- import os, json, asyncio
2
- import httpx
3
- from fastapi import FastAPI, Request
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
- MODEL = os.environ.get('HF_MODEL', 'Universal-618/Clarity-flash-weights')
9
- API = f'https://api-inference.huggingface.co/models/{MODEL}/v1/chat/completions'
10
- HEADERS = {'Authorization': f'Bearer {HF_TOKEN}', 'Content-Type': 'application/json'}
6
+ MODEL_NAME = os.environ.get('HF_MODEL', 'Clarity-flash-weights')
11
7
 
12
- app = FastAPI()
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
13
16
 
14
- @app.post('/v1/chat/completions')
15
- async def proxy(request: Request):
16
- body = await request.json()
17
- body['model'] = MODEL
18
- stream = body.get('stream', True)
19
- body['stream'] = stream
20
- async with httpx.AsyncClient(timeout=120) as client:
21
- resp = await client.post(API, headers=HEADERS, json=body)
22
- if resp.status_code != 200:
23
- return JSONResponse({'error': await resp.aread()}, status_code=resp.status_code)
24
- if stream:
25
- return StreamingResponse(resp.aiter_lines(), media_type='text/event-stream', headers={
26
- 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'X-Accel-Buffering': 'no'
27
- })
28
- return resp.json()
29
-
30
- @app.get('/main-data/{path:path}')
31
- async def main_data(path: str):
32
- path = path or 'index.json'
33
- fp = f'/data/{path}'
34
- if not os.path.exists(fp):
35
- return JSONResponse({'error': 'not found'}, status_code=404)
36
- with open(fp) as f:
37
- return JSONResponse(json.load(f))
38
-
39
- @app.get('/')
40
- async def root():
41
- return {'status': 'ok', 'model': MODEL, 'docs': '/v1/chat/completions'}
42
-
43
- if __name__ == '__main__':
44
- import uvicorn
45
- uvicorn.run(app, host='0.0.0.0', port=7860)
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
+ )
@@ -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 },
@@ -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 SPACES = [
6
- 'https://universal-618-clarity-main.hf.space',
7
- 'https://universal-618-clarity-2.hf.space',
8
- 'https://universal-618-clarity-3.hf.space',
9
- 'https://universal-618-clarity-4.hf.space',
10
- 'https://universal-618-clarity-5.hf.space',
11
- 'https://universal-618-clarity-6.hf.space',
12
- ];
4
+ const MODEL_ROUTES = {
5
+ 'Universal-618/Clarity-flash-weights': [
6
+ process.env.HUGGINGFACE_ENDPOINT || '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
+ process.env.HUGGINGFACE_ENDPOINT || '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 PROVIDERS = {
15
- huggingface: {
16
- endpoints: SPACES.map(s => s + '/v1/chat/completions'),
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 provider.endpoints) {
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) {