mirror of
https://github.com/OpenBMB/ChatDev.git
synced 2026-04-25 11:18:06 +00:00
704 B
704 B
Python Scratchpad Examples
Example: sum a list of numbers
numbers = [14, 27, 31, 8]
print(sum(numbers))
Expected structured result with execute_code:
{
"ok": true,
"exit_code": 0,
"stdout": "80\n",
"stderr": ""
}
Example: convert JSON to a sorted compact structure
import json
payload = {"b": 2, "a": 1, "nested": {"z": 3, "x": 2}}
print(json.dumps(payload, sort_keys=True))
Example: count words in text
text = "agent skills can trigger targeted workflows"
print(len(text.split()))
Example: test a regex
import re
text = "Order IDs: ORD-100, BAD-7, ORD-215"
matches = re.findall(r"ORD-\d+", text)
print(matches)