(self)
| 106 | pass |
| 107 | |
| 108 | def do_POST(self): |
| 109 | try: |
| 110 | if self.path.startswith("/v1/") and not self._authorized(): |
| 111 | self.send_json({"error": {"message": "invalid api key"}}, 401) |
| 112 | return |
| 113 | length = int(self.headers.get("Content-Length", 0)) |
| 114 | body = self.rfile.read(length) if length else b"" |
| 115 | if self.path == "/v1/chat/completions": |
| 116 | self._handle_chat(body) |
| 117 | elif self.path == "/v1/responses": |
| 118 | self._handle_responses(body) |
| 119 | elif ":generateContent" in self.path: |
| 120 | self._handle_google_generate(body, stream=False) |
| 121 | elif ":streamGenerateContent" in self.path: |
| 122 | self._handle_google_generate(body, stream=True) |
| 123 | else: |
| 124 | self.send_json({"error": "not found"}, 404) |
| 125 | except (BrokenPipeError, ConnectionResetError): |
| 126 | pass |
| 127 | except Exception as e: |
| 128 | log(f"POST error: {e}") |
| 129 | try: |
| 130 | self.send_json({"error": {"message": str(e)}}, 500) |
| 131 | except: |
| 132 | pass |
| 133 | |
| 134 | # ─── /v1/chat/completions ───────────────────────────────────────────────── |
| 135 |
nothing calls this directly
no test coverage detected