main changes
This commit is contained in:
@@ -15,6 +15,23 @@ HEADERS = {
|
||||
}
|
||||
|
||||
|
||||
def send_request (headers, body):
|
||||
with httpx.Client(timeout=60.0) as client:
|
||||
try:
|
||||
response = client.post(ANTHROPIC_API_URL, headers=headers, json=body)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except httpx.HTTPStatusError as e:
|
||||
print(f"[ERROR] HTTP {e.response.status_code} - {e.response.reason_phrase}")
|
||||
try:
|
||||
print("[DETAIL] Response JSON:")
|
||||
print(json.dumps(e.response.json(), indent=2))
|
||||
except Exception:
|
||||
print("[DETAIL] Raw Response Text:")
|
||||
print(e.response.text)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def send_prompt(api_key, messages):
|
||||
headers = HEADERS.copy()
|
||||
headers["x-api-key"] = api_key
|
||||
@@ -46,20 +63,7 @@ def send_prompt(api_key, messages):
|
||||
}
|
||||
}
|
||||
|
||||
with httpx.Client(timeout=60.0) as client:
|
||||
try:
|
||||
response = client.post(ANTHROPIC_API_URL, headers=headers, json=body)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except httpx.HTTPStatusError as e:
|
||||
print(f"[ERROR] HTTP {e.response.status_code} - {e.response.reason_phrase}")
|
||||
try:
|
||||
print("[DETAIL] Response JSON:")
|
||||
print(json.dumps(e.response.json(), indent=2))
|
||||
except Exception:
|
||||
print("[DETAIL] Raw Response Text:")
|
||||
print(e.response.text)
|
||||
sys.exit(1)
|
||||
return send_request(headers, body)
|
||||
|
||||
|
||||
def extract_tool_use(response):
|
||||
@@ -138,20 +142,7 @@ def run():
|
||||
}
|
||||
}
|
||||
|
||||
with httpx.Client(timeout=60.0) as client:
|
||||
try:
|
||||
response = client.post(ANTHROPIC_API_URL, headers=headers, json=tool_result_msg)
|
||||
response.raise_for_status()
|
||||
final_response = response.json()
|
||||
except httpx.HTTPStatusError as e:
|
||||
print(f"[ERROR] HTTP {e.response.status_code} - {e.response.reason_phrase}")
|
||||
try:
|
||||
print("[DETAIL] Response JSON:")
|
||||
print(json.dumps(e.response.json(), indent=2))
|
||||
except Exception:
|
||||
print("[DETAIL] Raw Response Text:")
|
||||
print(e.response.text)
|
||||
sys.exit(1)
|
||||
final_response = send_request(headers, tool_result_msg)
|
||||
|
||||
print("Final Claude response:")
|
||||
for block in final_response.get("content", []):
|
||||
|
||||
Reference in New Issue
Block a user