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 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
- ## Provider Comparison
106
+ ## Architecture
107
107
 
108
- | Provider | Free Tier | Streaming | Priority |
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
- MIT
112
+ Proprietary — all rights reserved. See [LICENSE](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clarity-ai",
3
- "version": "6.5.0",
3
+ "version": "6.5.1",
4
4
  "description": "CLARITY — terminal AI agent with Clarity Flash 14B",
5
5
  "type": "module",
6
6
  "bin": {
package/requirements.txt CHANGED
@@ -1,4 +1,3 @@
1
- gradio>=4
2
- requests>=2
3
- uvicorn>=0.20
4
1
  fastapi>=0.100
2
+ httpx>=0.27
3
+ uvicorn>=0.20
package/space_app.py CHANGED
@@ -1,28 +1,31 @@
1
- import os, json, requests
2
- import gradio as gr
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 uvicorn
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 chat_completions(request: Request):
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
- resp = requests.post(API, headers=HEADERS, json=body, stream=True)
21
- if resp.status_code != 200:
22
- return JSONResponse({'error': resp.text}, status_code=resp.status_code)
23
- if stream:
24
- return StreamingResponse(resp.iter_lines(), media_type='text/event-stream', headers={'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'X-Accel-Buffering': 'no'})
25
- return resp.json()
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
- def chat_ui(message, history):
37
- history = history or []
38
- msgs = [{'role': 'user' if i % 2 == 0 else 'assistant', 'content': m} for i, m in enumerate(history + [message])]
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)
@@ -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
- endpoint: 'https://Universal-618-Clarity-main.hf.space/v1/chat/completions',
16
+ endpoints: SPACES.map(s => s + '/v1/chat/completions'),
8
17
  name: 'huggingface',
9
18
  },
10
19
  groq: {
11
- endpoint: 'https://api.groq.com/openai/v1/chat/completions',
20
+ endpoints: ['https://api.groq.com/openai/v1/chat/completions'],
12
21
  name: 'groq',
13
22
  },
14
23
  openrouter: {
15
- endpoint: 'https://openrouter.ai/api/v1/chat/completions',
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
- const stream = streamResponse(endpoint, body, key || 'none', extraHeaders, options.signal);
51
- for await (const event of stream) {
52
- yield event;
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 = {}) {