clarity-ai 6.5.0 → 6.5.1
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 +3 -9
- package/package.json +1 -1
- package/requirements.txt +2 -3
- package/space_app.py +18 -25
- package/src/providers/index.js +25 -7
package/README.md
CHANGED
|
@@ -103,16 +103,10 @@ clarity /bash ls -la
|
|
|
103
103
|
| Gemini 2.0 Flash | Google | 32K (fast) |
|
|
104
104
|
| DeepSeek R1 Free | OpenRouter | 128K |
|
|
105
105
|
|
|
106
|
-
##
|
|
106
|
+
## Architecture
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|---|---|---|---|
|
|
110
|
-
| Groq | ✓ | ✓ | 1 (fastest) |
|
|
111
|
-
| Google Gemini | ✓ | ✓ | 2 |
|
|
112
|
-
| HuggingFace (Clarity Flash) | Needs HF_TOKEN | ✓ | 3 |
|
|
113
|
-
| DeepSeek | Cheap | ✓ | 4 |
|
|
114
|
-
| OpenRouter | ✓ | ✓ | 5 |
|
|
108
|
+
Clarity Flash 14B is served via `Clarity-main` HF Space — a streaming inference proxy at `*.hf.space/v1/chat/completions`. No API keys needed.
|
|
115
109
|
|
|
116
110
|
## License
|
|
117
111
|
|
|
118
|
-
|
|
112
|
+
Proprietary — all rights reserved. See [LICENSE](LICENSE).
|
package/package.json
CHANGED
package/requirements.txt
CHANGED
package/space_app.py
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
import os, json,
|
|
2
|
-
import
|
|
1
|
+
import os, json, asyncio
|
|
2
|
+
import httpx
|
|
3
3
|
from fastapi import FastAPI, Request
|
|
4
4
|
from fastapi.responses import StreamingResponse, JSONResponse
|
|
5
|
-
import
|
|
5
|
+
from contextlib import asynccontextmanager
|
|
6
6
|
|
|
7
7
|
HF_TOKEN = os.environ.get('HF_TOKEN', '')
|
|
8
|
-
MODEL = 'Universal-618/Clarity-flash-weights'
|
|
8
|
+
MODEL = os.environ.get('HF_MODEL', 'Universal-618/Clarity-flash-weights')
|
|
9
9
|
API = f'https://api-inference.huggingface.co/models/{MODEL}/v1/chat/completions'
|
|
10
10
|
HEADERS = {'Authorization': f'Bearer {HF_TOKEN}', 'Content-Type': 'application/json'}
|
|
11
11
|
|
|
12
12
|
app = FastAPI()
|
|
13
13
|
|
|
14
14
|
@app.post('/v1/chat/completions')
|
|
15
|
-
async def
|
|
15
|
+
async def proxy(request: Request):
|
|
16
16
|
body = await request.json()
|
|
17
17
|
body['model'] = MODEL
|
|
18
18
|
stream = body.get('stream', True)
|
|
19
19
|
body['stream'] = stream
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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()
|
|
26
29
|
|
|
27
30
|
@app.get('/main-data/{path:path}')
|
|
28
31
|
async def main_data(path: str):
|
|
@@ -33,20 +36,10 @@ async def main_data(path: str):
|
|
|
33
36
|
with open(fp) as f:
|
|
34
37
|
return JSONResponse(json.load(f))
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
body = {'model': MODEL, 'messages': msgs, 'stream': False, 'max_tokens': 4096}
|
|
40
|
-
resp = requests.post(API, headers=HEADERS, json=body)
|
|
41
|
-
if resp.status_code == 200:
|
|
42
|
-
return resp.json()['choices'][0]['message']['content']
|
|
43
|
-
return f'Error: {resp.status_code}'
|
|
44
|
-
|
|
45
|
-
with gr.Blocks(title='CLARITY Flash', css='footer{display:none!important}') as ui:
|
|
46
|
-
gr.Markdown('# CLARITY Flash 14B')
|
|
47
|
-
gr.ChatInterface(chat_ui, title='Chat')
|
|
48
|
-
|
|
49
|
-
app = gr.mount_gradio_app(app, ui, path='/')
|
|
39
|
+
@app.get('/')
|
|
40
|
+
async def root():
|
|
41
|
+
return {'status': 'ok', 'model': MODEL, 'docs': '/v1/chat/completions'}
|
|
50
42
|
|
|
51
43
|
if __name__ == '__main__':
|
|
44
|
+
import uvicorn
|
|
52
45
|
uvicorn.run(app, host='0.0.0.0', port=7860)
|
package/src/providers/index.js
CHANGED
|
@@ -2,17 +2,26 @@ import { getKey } from '../config/keys.js';
|
|
|
2
2
|
import { streamResponse } from './streaming.js';
|
|
3
3
|
import { parseErrorResponse } from './errors.js';
|
|
4
4
|
|
|
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
|
+
];
|
|
13
|
+
|
|
5
14
|
const PROVIDERS = {
|
|
6
15
|
huggingface: {
|
|
7
|
-
|
|
16
|
+
endpoints: SPACES.map(s => s + '/v1/chat/completions'),
|
|
8
17
|
name: 'huggingface',
|
|
9
18
|
},
|
|
10
19
|
groq: {
|
|
11
|
-
|
|
20
|
+
endpoints: ['https://api.groq.com/openai/v1/chat/completions'],
|
|
12
21
|
name: 'groq',
|
|
13
22
|
},
|
|
14
23
|
openrouter: {
|
|
15
|
-
|
|
24
|
+
endpoints: ['https://openrouter.ai/api/v1/chat/completions'],
|
|
16
25
|
name: 'openrouter',
|
|
17
26
|
},
|
|
18
27
|
};
|
|
@@ -40,17 +49,26 @@ export async function* callAI(providerName, model, messages, options = {}) {
|
|
|
40
49
|
body.tool_choice = 'auto';
|
|
41
50
|
}
|
|
42
51
|
|
|
43
|
-
let endpoint = provider.endpoint;
|
|
44
52
|
const extraHeaders = {};
|
|
45
53
|
if (providerName === 'openrouter') {
|
|
46
54
|
extraHeaders['HTTP-Referer'] = 'https://clarity-ai.local';
|
|
47
55
|
extraHeaders['X-Title'] = 'CLARITY AI';
|
|
48
56
|
}
|
|
49
57
|
|
|
50
|
-
|
|
51
|
-
for
|
|
52
|
-
|
|
58
|
+
let lastErr;
|
|
59
|
+
for (const endpoint of provider.endpoints) {
|
|
60
|
+
try {
|
|
61
|
+
const stream = streamResponse(endpoint, body, key || 'none', extraHeaders, options.signal);
|
|
62
|
+
for await (const event of stream) {
|
|
63
|
+
yield event;
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
} catch (err) {
|
|
67
|
+
lastErr = err;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
53
70
|
}
|
|
71
|
+
throw lastErr;
|
|
54
72
|
}
|
|
55
73
|
|
|
56
74
|
export async function callAISync(providerName, model, messages, options = {}) {
|