File size: 1,787 Bytes
d1221ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from http.server import BaseHTTPRequestHandler, HTTPServer
import json


class Handler(BaseHTTPRequestHandler):
    def do_POST(self):
        length = int(self.headers.get("Content-Length", "0"))
        body = self.rfile.read(length)
        try:
            payload = json.loads(body or b"{}")
        except Exception:
            payload = {}

        messages = payload.get("messages", [])
        user_text = messages[-1].get("content", "") if messages else ""
        lower = user_text.lower()

        if "question:" in lower:
            if "what f1 score did the model with 16k token context achieve on scrolls" in lower:
                content = "43.2%"
            elif "by what percentage does sgc reduce memory consumption" in lower:
                content = "60%"
            elif "how many tokens was medllm trained on" in lower:
                content = "200 billion tokens"
            else:
                content = "42"
        else:
            content = "Concise summary preserving key facts and figures."

        response = {
            "id": "mock-chatcmpl",
            "object": "chat.completion",
            "choices": [
                {
                    "index": 0,
                    "message": {"role": "assistant", "content": content},
                    "finish_reason": "stop",
                }
            ],
        }
        encoded = json.dumps(response).encode("utf-8")
        self.send_response(200)
        self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(encoded)))
        self.end_headers()
        self.wfile.write(encoded)

    def log_message(self, format, *args):
        return


if __name__ == "__main__":
    HTTPServer(("127.0.0.1", 8001), Handler).serve_forever()