mochiii

it's over. they don't even offer the preview on their own site now.

Thanks hackerman and moe

Hosts on http://127.0.0.1:8080/

You're in. You now have full 100K Context Claude, Mixtral, and GPT 4!
Update: Working models are gpt-4-0314, gpt-4-0613, gpt-4-1106-preview, gpt-4-vision-preview, claude-instant-1.2, claude-2.1

[email protected]

to well-meaning hosters: please do not try to deobfuscate the code, it only makes it easier for moemate to patch this stuff. try hosting it as is. on request i can add a dockerfile.

data updated (again)

make sure to grab the new contents of DATA, the script has not changed


how to use this in ST (for dummies)
if you're not a windows user you probably know what you're doing

  1. install Python, make sure "add to system PATH" is enabled; log in and out
  2. in a new folder, paste main.py code into main.py
  3. right click on a blank space in the explorer window -> "open PowerShell window here"
  4. type the following command $env:DATA = '<insert data from below here>'
  5. type the following command exactly pip install --user requests flask
  6. type the following command exactly python main.py and leave the window open
  7. in ST, put http://127.0.0.1:8080/company/v1 in the proxy url box, replacing company with the appropriate one
  8. in ST, make sure the proxy password field is not empty
  9. enjoy

repl.it hosting vvv

  1. just clone the repl from my account

if i'm gone/banned/spitefagged, follow this guide to host your own:

  1. https://replit.com/
  2. create repl
  3. select 'python'
  4. paste main.py code into main.py
  5. bottom right 'tools' > scroll > click 'secrets'
  6. left sidebar > edit as JSON > paste secrets -> save
  7. big green run button
    • 'webview' panel will appear > click 'new tab'
  8. use pinger like https://app.checklyhq.com/ to keep it up. example pings:
    • GET https://your-url.dev/openai/v1/models
    • POST https://your-url.dev/openai/v1/chat/completions
    • every 30 seconds or something

secrets JSON

1
2
3
{
  "DATA": "eNqVkl1P2zAUhv+KlSuQSGyTrwFXUVatiH4gLYgLhCo3PWu9+kuO17BN/PfZrYCUoUmTb+L3vOc5eW0/RFgbUIzjHcXthjncamkEOK5VF52hYVnqFYiDyJTbWG14u287dMC+InnnLBPv/AP1mP8QrY2L0ySP3Q+71MF8JMQkJfQDtaDp3yotth+KR/bs9cOz6XA3NMWUkiI2FnYc+jd1xzv/46/6Ywgg+VPIFjbRxjnTXWK8BgWWhZCJ1CCZg4RrzAwfVPD8djRbVNeLelw1i3o+vZ2Mmuv5DPujAiaj/8XVk+ru8+jfIMbfA8Kde8fvqNbKgXJx89NAdIkiZozg7QH9vdMqYO46sHHlZ7rgmOpfXAiG84Sgk3uuVrrv0KxBlCTkCnmhyK7QU5Gdosqz4B6WN9zhPC2TtEAnN+NmOjlDgm8BfYF2q09R7d+UBEzPPSAs9JV9Y5YfWsL8ueVrrsLsl0B93w8SBY8fw3woG1y0JCS/oOVFVhZpkRfpp3NKsug55A2+se72SYSQJVkmK9gNYc+PfwAsDvii"
}

main.py

from flask import Flask, request, Response
import requests
import time
import json
import os
import zlib
import base64

st = int(time.time())
p1 = 0
p2 = 0
p3 = 0

app = Flask(__name__)

r1, r2, r3, r4, r5, i, j, a1, a2, a3, h1, h2 = json.loads(zlib.decompress(base64.b64decode(os.getenv("DATA").encode())).decode())

@app.route(r1, methods=['POST'])
def a1_f():
    global p1
    req_stream = requests.post(
        a1,
        json=request.get_json(),
        headers=h1,
        stream=True
    )

    if req_stream.ok:
        p1 += 1

    def g():
        for chunk in req_stream.iter_content(chunk_size=4096):
            yield chunk

    return Response(g(), content_type=req_stream.headers['Content-Type'], status=req_stream.status_code)

mm = lambda x: {"object": "list", "data": [{"id": m, "object": "model", "created": 0, "owned_by": "oai"} for m in x]}
m = mm(i)

@app.route(r2, methods=['GET'])
def a2_f():
    return m

@app.route(r3, methods=['POST'])
def a3_f():
    global p2
    js = request.get_json()
    sr = js.get("stream", False)
    req_stream = requests.post(
        a2,
        json=js,
        headers=h1,
        stream=True
    )

    if req_stream.ok:
        p2 += 1

    def g():
        if sr:
            last_pos = 0
            for line in req_stream.iter_lines():
                if line.startswith(b'data: ') and not line.startswith(b'data: [DONE]'):
                    data = json.loads(line.removeprefix(b'data: ').decode('utf-8'))
                    pos, last_pos = last_pos, len(data['completion'])
                    data['completion'] = data['completion'][pos:]
                    yield f'data: {json.dumps(data, indent=None, separators=(",", ":"))}\r\n\r\n'
        else:
            for chunk in req_stream.iter_content(chunk_size=4096):
                yield chunk

    return Response(g(), content_type=req_stream.headers['Content-Type'], status=req_stream.status_code)

n = mm(j)

@app.route(r4, methods=["GET"])
def a4_f():
    return n

@app.route(r5, methods=['POST'])
def a5_f():
    global p3
    request_json = request.get_json()
    if request_json.get("stream", False) or request_json.get("echo", False):
        return Response("cannot use streaming or echo", status=400)
    seed = None if request_json.get("seed") == -1 else request_json.get("seed")
    real_json = {
        "inputs": request_json["prompt"],
        "parameters": {
            "best_of": 1,
            "decoder_input_details": True,
            "details": False,
            "do_sample": True,
            "max_new_tokens": request_json["max_new_tokens"],
            "repetition_penalty": request_json["repetition_penalty"],
            "return_full_text": False,
            "seed": seed,
            "stop": request_json["stopping_strings"],
            "stream": False,
            "temperature": request_json["temperature"],
            "top_k": request_json["top_k"],
            "top_p": request_json["top_p"],
            "truncate": None,
            "typical_p": request_json["typical_p"],
            "watermark": False,
        },
    }

    global mist_prompts
    req_stream = requests.post(
        a3,
        json=real_json,
        headers=(h1 | h2),
    )

    if req_stream.ok:
        p3 += 1
    else:
        return Response(req_stream.text, status=500)

    data = req_stream.json()
    finish_reason = "length" if data["output"]["usage"]["completion_tokens"] >= request_json["max_new_tokens"] else "stop"
    response = {
        "id": "cmpl-xyz",
        "object": "text_completion",
        "created": int(time.time()),
        "model": j[0],
        "choices": [{
            "index": 0,
            "finish_reason": finish_reason,
            "text": data["output"]["choices"][0]["text"],
            "logprobs": None,
        }],
        "usage": data["output"]["usage"],
    }

    return response

@app.route('/', methods=['GET'])
def a6_f():
    u = int(time.time()) - st
    s = f"""
<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><meta name="robots" content="noindex"><title>mochi</title></head>
<body style="font-family: sans-serif; background-color: #f0f0f0; padding: 1em;">
<h2>mochi</h2>
{u}<br>
{p1}<br>
{p2}<br>
{p3}<br><br>
2m timeout<br>
for r3: use ooba, turn off streaming
</body></html>
    """.strip()
    return Response(s, mimetype="text/html")

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080)
Edit
Pub: 11 Jan 2024 01:02 UTC
Edit: 13 Jan 2024 03:08 UTC
Views: 7818