Download tests/test_param_uyum.py from SevdanurGenc/Text-to-SQL: direct link, hf CLI and curl.
- Browser
- Download file 2.6 kB
-
https://huggingface.co/SevdanurGenc/Text-to-SQL/resolve/main/tests/test_param_uyum.py
- Command line
-
hf download hf://SevdanurGenc/Text-to-SQL/tests/test_param_uyum.py
-
curl -L -o test_param_uyum.py https://huggingface.co/SevdanurGenc/Text-to-SQL/resolve/main/tests/test_param_uyum.py
2.6 kB
| """Yeni modellerin reddettiği parametrelere (temperature, max_tokens) uyum.""" | |
| import json | |
| import threading | |
| from http.server import BaseHTTPRequestHandler, HTTPServer | |
| import pytest | |
| from t2s import llm | |
| SEEN = [] | |
| class H(BaseHTTPRequestHandler): | |
| def log_message(self, *a): | |
| pass | |
| def do_POST(self): | |
| body = json.loads(self.rfile.read(int(self.headers["Content-Length"]))) | |
| SEEN.append(body) | |
| if self.path.endswith("/v1/messages") and "temperature" in body: | |
| return self._send(400, {"type": "error", "error": {"type": "invalid_request_error", | |
| "message": "`temperature` is deprecated for this model."}}) | |
| if self.path.endswith("/chat/completions") and "max_tokens" in body: | |
| return self._send(400, {"error": {"message": "Unsupported parameter: 'max_tokens' is not supported with " | |
| "this model. Use 'max_completion_tokens' instead."}}) | |
| if self.path.endswith("/v1/messages"): | |
| return self._send(200, {"content": [{"type": "text", "text": "ok"}], "usage": {}}) | |
| return self._send(200, {"choices": [{"message": {"content": "ok"}}], "usage": {}}) | |
| def _send(self, code, obj): | |
| b = json.dumps(obj).encode() | |
| self.send_response(code) | |
| self.send_header("Content-Type", "application/json") | |
| self.send_header("Content-Length", str(len(b))) | |
| self.end_headers() | |
| self.wfile.write(b) | |
| def url(): | |
| srv = HTTPServer(("127.0.0.1", 0), H) | |
| threading.Thread(target=srv.serve_forever, daemon=True).start() | |
| yield f"http://127.0.0.1:{srv.server_port}" | |
| srv.shutdown() | |
| def test_claude_drops_temperature(url): | |
| SEEN.clear() | |
| be = llm.AnthropicBackend("claude-yeni-x", api_key="k", base_url=url) | |
| assert be.chat("s", [{"role": "user", "content": "hi"}]) == "ok" | |
| assert be.chat("s", [{"role": "user", "content": "hi"}]) == "ok" | |
| assert len(SEEN) == 3 and "temperature" not in SEEN[-1] # ikinci çağrıda tek istek | |
| def test_openai_switches_max_tokens(url): | |
| SEEN.clear() | |
| be = llm.OpenAICompatBackend("yeni-model", base_url=url + "/v1", api_key="k") | |
| assert be.chat("s", [{"role": "user", "content": "hi"}]) == "ok" | |
| assert "max_completion_tokens" in SEEN[-1] and "max_tokens" not in SEEN[-1] | |
| def test_openai_new_names_detected(): | |
| be = llm.OpenAICompatBackend("gpt-6-astra", api_key="k") | |
| p = be._payload("s", [], 50) | |
| assert "max_completion_tokens" in p and "temperature" not in p | |