fixes
This commit is contained in:
@@ -21,7 +21,7 @@ def send_prompt(api_key, user_prompt):
|
|||||||
|
|
||||||
body = {
|
body = {
|
||||||
"model": MODEL,
|
"model": MODEL,
|
||||||
"max_tokens": 1024,
|
"max_tokens": 2048,
|
||||||
"tools": [
|
"tools": [
|
||||||
{
|
{
|
||||||
"type": f"computer_{TOOL_VERSION}",
|
"type": f"computer_{TOOL_VERSION}",
|
||||||
@@ -47,14 +47,24 @@ def send_prompt(api_key, user_prompt):
|
|||||||
],
|
],
|
||||||
"thinking": {
|
"thinking": {
|
||||||
"type": "enabled",
|
"type": "enabled",
|
||||||
"budget_tokens": 512
|
"budget_tokens": 1024
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
with httpx.Client(timeout=60.0) as client:
|
with httpx.Client(timeout=60.0) as client:
|
||||||
response = client.post(ANTHROPIC_API_URL, headers=headers, json=body)
|
try:
|
||||||
response.raise_for_status()
|
response = client.post(ANTHROPIC_API_URL, headers=headers, json=body)
|
||||||
return response.json()
|
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 extract_tool_use(response):
|
def extract_tool_use(response):
|
||||||
@@ -74,6 +84,7 @@ def run():
|
|||||||
|
|
||||||
print(f"Sending prompt: {prompt}")
|
print(f"Sending prompt: {prompt}")
|
||||||
first_response = send_prompt(api_key, prompt)
|
first_response = send_prompt(api_key, prompt)
|
||||||
|
print(first_response)
|
||||||
|
|
||||||
tool_use = extract_tool_use(first_response)
|
tool_use = extract_tool_use(first_response)
|
||||||
if not tool_use:
|
if not tool_use:
|
||||||
@@ -83,6 +94,7 @@ def run():
|
|||||||
|
|
||||||
print(f"Tool requested: {tool_use['name']}")
|
print(f"Tool requested: {tool_use['name']}")
|
||||||
print(f"Input: {tool_use['input']}")
|
print(f"Input: {tool_use['input']}")
|
||||||
|
print(tool_use)
|
||||||
|
|
||||||
fake_result = {"result": f"(Stub) Executed {tool_use['name']} successfully."}
|
fake_result = {"result": f"(Stub) Executed {tool_use['name']} successfully."}
|
||||||
|
|
||||||
@@ -91,26 +103,76 @@ def run():
|
|||||||
|
|
||||||
tool_result_msg = {
|
tool_result_msg = {
|
||||||
"model": MODEL,
|
"model": MODEL,
|
||||||
"max_tokens": 512,
|
"max_tokens": 2048,
|
||||||
"tools": [],
|
"tools": [],
|
||||||
"messages": [
|
"messages": [
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": prompt
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
'type': 'thinking',
|
||||||
|
'thinking': (
|
||||||
|
"The user is asking me to take a screenshot of their desktop. I can do this "
|
||||||
|
"using the \"computer\" function with the \"screenshot\" action.\n\n"
|
||||||
|
"I need to call the following:\n"
|
||||||
|
"- Function: computer\n"
|
||||||
|
"- Action: screenshot"
|
||||||
|
),
|
||||||
|
'signature': (
|
||||||
|
"ErUBCkYIBBgCIkDPXNmcKH0varjvxjdtV6bzHp8OfBbJ3Jg+rJZvBGpXIE1L4RrroreDvBLcoC4uO76tNHDikWlnwv7UAgUtHEFMEgy6tLHT/"
|
||||||
|
"oFQ4tczh00aDMND7yTs4mXU4utOjiIw08TVLfADRoZLfX5ookvmFuDfN0m2l7KPcgAfQ1Af7AH+T2YHqi+DRtnuGxt35vAeKh1sTRvojVlHU"
|
||||||
|
"4en+7+TxdQ+yEC3x70IkuQgF5DHQhgC"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'type': 'text',
|
||||||
|
'text': "I'll take a screenshot of your desktop right away."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'type': 'tool_use',
|
||||||
|
'id': tool_use["id"],
|
||||||
|
'name': 'computer',
|
||||||
|
'input': {
|
||||||
|
'action': 'screenshot'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": [
|
"content": [
|
||||||
{
|
{
|
||||||
"type": "tool_result",
|
"type": "tool_result",
|
||||||
"tool_use_id": tool_use["id"],
|
"tool_use_id": tool_use["id"],
|
||||||
"content": fake_result
|
"content": "(Stub) Executed tool successfully"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"thinking": {
|
||||||
|
"type": "enabled",
|
||||||
|
"budget_tokens": 1024
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
with httpx.Client(timeout=60.0) as client:
|
with httpx.Client(timeout=60.0) as client:
|
||||||
response = client.post(ANTHROPIC_API_URL, headers=headers, json=tool_result_msg)
|
try:
|
||||||
response.raise_for_status()
|
response = client.post(ANTHROPIC_API_URL, headers=headers, json=tool_result_msg)
|
||||||
final_response = response.json()
|
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)
|
||||||
|
|
||||||
print("Final Claude response:")
|
print("Final Claude response:")
|
||||||
for block in final_response.get("content", []):
|
for block in final_response.get("content", []):
|
||||||
|
|||||||
Reference in New Issue
Block a user