diff --git a/chat_api.py b/chat_api.py index 2b1a36d..dc768e7 100644 --- a/chat_api.py +++ b/chat_api.py @@ -1,70 +1,45 @@ #!/usr/bin/env python3 -"""BECOMINGONE Chat API.""" +"""BECOMINGONE Chat - Simple.""" import asyncio import json from becomingone.llm_integrator import EmissaryLLM -# Initialize -MASTER = EmissaryLLM(model='llama3.1:8b') -EMISSARY = EmissaryLLM(model='deepseek-coder-v2:lite') +# Use just Emissary for now (faster) +MODEL = EmissaryLLM(model='llama3.1:8b') async def process(prompt): - """Process through both models.""" - m, e = await asyncio.gather( - MASTER.respond(prompt), - EMISSARY.respond(prompt), - return_exceptions=True - ) - return { - "master": {"response": m.get("response", str(m))[:500] if hasattr(m, 'get') else str(m)[:500]}, - "emissary": {"response": e.get("response", str(e))[:500] if hasattr(e, 'get') else str(e)[:500]} - } + r = await MODEL.respond(prompt) + return {"master": {"response": r.get("response", "")[:500]}, "emissary": {"response": r.get("response", "")[:500]}} -HTML = '''BECOMINGONE

🔗 BECOMINGONE

Master + Emissary

''' +HTML = '''BECOMINGONE

🔗 BECOMINGONE

Test Mode: Single Model

''' async def handle(r, w): try: - d = await r.read(8192) + d = await r.read(4096) if not d: return - txt = d.decode('utf-8', errors='ignore') ln = txt.split('\n')[0].split() method, path = ln[0], ln[1] if len(ln) > 1 else '/' - - # Read body body = b"" for line in txt.split('\r\n'): if line.lower().startswith('content-length:'): body = await r.read(int(line.split(':')[1].strip())) break - if path == '/health': - resp = '{"status":"ok"}' - ct = 'application/json' + w.write(b'HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 16\r\n\r\n{"status":"ok"}') elif path == '/c' and method == 'POST': - try: - data = json.loads(body.decode()) - result = await process(data.get('prompt', 'Hi')) - resp = json.dumps(result) - except Exception as e: - resp = '{"error":"' + str(e) + '"}' - ct = 'application/json' + data = json.loads(body.decode()) + result = await process(data.get('prompt', 'Hi')) + resp = json.dumps(result) + w.write(b'HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: ' + str(len(resp)).encode() + b'\r\n\r\n' + resp.encode()) else: - resp = HTML - ct = 'text/html' - - w.write(b'HTTP/1.1 200 OK\r\nContent-Type: ' + ct.encode() + b'\r\nContent-Length: ' + str(len(resp)).encode() + b'\r\nConnection: close\r\n\r\n' + resp.encode()) + w.write(b'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: ' + str(len(HTML)).encode() + b'\r\n\r\n' + HTML.encode()) except Exception as e: print('Error:', e) finally: w.close() await w.wait_closed() -async def main(): - server = await asyncio.start_server(handle, '0.0.0.0', 8001) - print('Server running on http://192.168.1.6:8001') - async with server: - await server.serve_forever() - -asyncio.run(main()) +asyncio.run(asyncio.start_server(handle, '0.0.0.0', 8001)) +print('Running on http://192.168.1.6:8001')