MCPcopy Create free account
hub / github.com/Luce-Org/lucebox-hub / chat

Function chat

server/scripts/test_server_prefix_cache.py:89–106  ·  view source on GitHub ↗
(user_msg, max_tokens=8)

Source from the content-addressed store, hash-verified

87 system = "You are a precise coding assistant. " * 200
88
89 def chat(user_msg, max_tokens=8):
90 payload = {
91 "model": "luce-dflash",
92 "messages": [
93 {"role": "system", "content": system},
94 {"role": "user", "content": user_msg},
95 ],
96 "max_tokens": max_tokens, "stream": False,
97 }
98 body = json.dumps(payload).encode()
99 req = urllib.request.Request(
100 f"{base_url}/v1/chat/completions",
101 data=body, headers={"Content-Type": "application/json"})
102 t0 = time.time()
103 resp = urllib.request.urlopen(req, timeout=600)
104 data = json.loads(resp.read())
105 dt = time.time() - t0
106 return dt, data["choices"][0]["message"]["content"]
107
108 # Turn 1: cold (cache miss → snapshot taken at end)
109 print("\n=== Turn 1 (cold) ===", flush=True)

Callers 1

mainFunction · 0.70

Calls 1

encodeMethod · 0.45

Tested by

no test coverage detected