(port: int, payload: dict, timeout=600)
| 57 | |
| 58 | |
| 59 | def chat_post(port: int, payload: dict, timeout=600) -> str: |
| 60 | body = json.dumps(payload).encode() |
| 61 | req = urllib.request.Request( |
| 62 | f"http://127.0.0.1:{port}/v1/chat/completions", |
| 63 | data=body, headers={"Content-Type": "application/json"}) |
| 64 | resp = urllib.request.urlopen(req, timeout=timeout) |
| 65 | data = json.loads(resp.read()) |
| 66 | return data["choices"][0]["message"]["content"] |
| 67 | |
| 68 | |
| 69 | def wait_server_up(port: int, proc: subprocess.Popen, timeout=180) -> bool: |