UPDATE: Sample generator now includes a new key in each item.
This commit is contained in:
parent
35ca56118d
commit
b5167b71e3
|
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""
|
"""
|
||||||
Use:
|
Use:
|
||||||
python generate_mbpp_avap.py
|
python generate_mbap.py
|
||||||
python generate_mbpp_avap.py --lrm path/to/avap.md
|
python generate_mbap.py --lrm path/to/avap.md
|
||||||
python generate_mbpp_avap.py --lrm avap.md --output output/mbpp_avap.json --problems 300
|
python generate_mbap.py --lrm avap.md --output output/mbpp_avap.json --problems 300
|
||||||
|
|
||||||
Requirements:
|
Requirements:
|
||||||
pip install anthropic
|
pip install anthropic
|
||||||
|
|
@ -62,7 +62,7 @@ REGLAS ESTRICTAS para el código AVAP generado:
|
||||||
|
|
||||||
MODO DE EJECUCIÓN — MUY IMPORTANTE:
|
MODO DE EJECUCIÓN — MUY IMPORTANTE:
|
||||||
- El código se ejecuta DIRECTAMENTE, línea a línea, sin servidor ni registro de endpoints.
|
- El código se ejecuta DIRECTAMENTE, línea a línea, sin servidor ni registro de endpoints.
|
||||||
- NUNCA uses registerEndpoint(), NUNCA uses mainHandler(), NUNCA envuelvas el código en funciones solo para ejecutarlo salvo que queramos probar la funcionalidad de funciones.
|
- NUNCA uses registerEndpoint(), NUNCA uses mainHandler(), NUNCA envuelvas el código en funciones solo para ejecutarlo.
|
||||||
- El código correcto es simplemente las instrucciones en línea, por ejemplo:
|
- El código correcto es simplemente las instrucciones en línea, por ejemplo:
|
||||||
result = "Hello World"
|
result = "Hello World"
|
||||||
addResult(result)
|
addResult(result)
|
||||||
|
|
@ -82,9 +82,28 @@ Estructura exacta de cada elemento:
|
||||||
"task_id": <número entero>,
|
"task_id": <número entero>,
|
||||||
"text": "<enunciado del problema en español>",
|
"text": "<enunciado del problema en español>",
|
||||||
"code": "<código AVAP con saltos de línea como \\n>",
|
"code": "<código AVAP con saltos de línea como \\n>",
|
||||||
|
"test_inputs": { "<param1>": <valor1>, "<param2>": <valor2> },
|
||||||
"test_list": ["<expr_python_1>", "<expr_python_2>"]
|
"test_list": ["<expr_python_1>", "<expr_python_2>"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FORMATO DE test_inputs — MUY IMPORTANTE:
|
||||||
|
- Es un objeto JSON con un valor fijo para cada variable que el código recibe via addParam().
|
||||||
|
- Los nombres de las claves deben coincidir EXACTAMENTE con el nombre de variable usado en addParam().
|
||||||
|
- Los valores deben ser concretos y representativos del problema (no genéricos como "test" o 123).
|
||||||
|
- Si el código no tiene ningún addParam(), el campo test_inputs debe ser un objeto vacío: {}
|
||||||
|
- Estos valores son los que el evaluador inyectará en el stack antes de ejecutar el código,
|
||||||
|
de modo que las aserciones de test_list puedan validar las variables de salida resultantes.
|
||||||
|
|
||||||
|
Ejemplo con addParam:
|
||||||
|
código: addParam("password", password)\\nencodeSHA256(password, hashed)\\naddResult(hashed)
|
||||||
|
test_inputs: { "password": "secret123" }
|
||||||
|
test_list: ["re.match(r'^[a-f0-9]{64}$', hashed)"]
|
||||||
|
|
||||||
|
Ejemplo sin addParam:
|
||||||
|
código: randomString(16, token)\\naddResult(token)
|
||||||
|
test_inputs: {}
|
||||||
|
test_list: ["re.match(r'^[a-zA-Z0-9]{16}$', token)"]
|
||||||
|
|
||||||
FORMATO DE test_list — MUY IMPORTANTE:
|
FORMATO DE test_list — MUY IMPORTANTE:
|
||||||
Cada aserción debe ser una expresión Python con re.match() o re.search()
|
Cada aserción debe ser una expresión Python con re.match() o re.search()
|
||||||
evaluable directamente sobre las variables del stack AVAP (disponibles como
|
evaluable directamente sobre las variables del stack AVAP (disponibles como
|
||||||
|
|
@ -138,22 +157,26 @@ Responde ÚNICAMENTE con el array JSON. Sin texto antes ni después.
|
||||||
|
|
||||||
def parse_response(raw: str):
|
def parse_response(raw: str):
|
||||||
text = raw.strip()
|
text = raw.strip()
|
||||||
|
|
||||||
if text.startswith("```"):
|
if text.startswith("```"):
|
||||||
lines = text.splitlines()
|
lines = text.splitlines()
|
||||||
inner = lines[1:]
|
inner = lines[1:]
|
||||||
if inner and inner[-1].strip() == "```":
|
if inner and inner[-1].strip() == "```":
|
||||||
inner = inner[:-1]
|
inner = inner[:-1]
|
||||||
text = "\n".join(inner).strip()
|
text = "\n".join(inner).strip()
|
||||||
|
|
||||||
problems = json.loads(text)
|
problems = json.loads(text)
|
||||||
|
|
||||||
if not isinstance(problems, list):
|
if not isinstance(problems, list):
|
||||||
raise ValueError("answer is not a JSON.")
|
raise ValueError("response is not an JSON array")
|
||||||
|
|
||||||
for p in problems:
|
for p in problems:
|
||||||
for field in ("task_id", "text", "code", "test_list"):
|
for field in ("task_id", "text", "code", "test_list"):
|
||||||
if field not in p:
|
if field not in p:
|
||||||
raise ValueError(f"field '{field}' not found in a problem.")
|
raise ValueError(f"Field missing '{field}' in task_id={p.get('task_id','?')}.")
|
||||||
|
if "test_inputs" not in p:
|
||||||
|
p["test_inputs"] = {}
|
||||||
|
if not isinstance(p["test_inputs"], dict):
|
||||||
|
raise ValueError(f"'test_inputs' must by a JSON Object (task_id={p.get('task_id','?')}).")
|
||||||
|
|
||||||
return problems
|
return problems
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue