MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / call_anthropic_messages

Function call_anthropic_messages

e2e/python/test_inference_routing.py:279–313  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

277 spec = datamodel_pb2.SandboxSpec(policy=_baseline_policy())
278
279 def call_anthropic_messages() -> str:
280 import json
281 import ssl
282 import urllib.error
283 import urllib.request
284
285 body = json.dumps(
286 {
287 "model": "claude-test",
288 "max_tokens": 64,
289 "messages": [{"role": "user", "content": "hello"}],
290 }
291 ).encode()
292
293 req = urllib.request.Request(
294 "https://inference.local/v1/messages",
295 data=body,
296 headers={
297 "Content-Type": "application/json",
298 "x-api-key": "dummy-key",
299 "anthropic-version": "2023-06-01",
300 },
301 method="POST",
302 )
303 ctx = ssl.create_default_context()
304 ctx.check_hostname = False
305 ctx.verify_mode = ssl.CERT_NONE
306
307 try:
308 resp = urllib.request.urlopen(req, timeout=30, context=ctx)
309 return resp.read().decode()
310 except urllib.error.HTTPError as exc:
311 return (
312 f"http_error_{exc.code}:{exc.read().decode('utf-8', errors='replace')}"
313 )
314
315 with sandbox(spec=spec, delete_on_exit=True) as sb:
316 result = sb.exec_python(call_anthropic_messages, timeout_seconds=60)

Callers

nothing calls this directly

Calls 1

readMethod · 0.45

Tested by

no test coverage detected