File tree Expand file tree Collapse file tree
evalscope/benchmarks/scicode Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- from typing import cast
2-
31from evalscope .api .evaluator import TaskState
42
53
@@ -21,7 +19,7 @@ def extract_code(block: str) -> str:
2119 The extracted code with the code fences and surrounding whitespace removed.
2220
2321 """
24- return block .replace (' ```python' , '' ).replace (' ```' , '' ).strip ()
22+ return block .replace (" ```python" , "" ).replace (" ```" , "" ).strip ()
2523
2624
2725def get_generated_code (state : TaskState ) -> list [str ]:
@@ -43,10 +41,8 @@ def get_generated_code(state: TaskState) -> list[str]:
4341 If the number of assistant messages does not match the number of subproblems in the task metadata.
4442
4543 """
46- assistant_messages = [
47- extract_code (cast (str , message .content )) for message in state .messages if message .role == 'assistant'
48- ]
49- assert len (assistant_messages ) == len (state .metadata ['sub_steps' ])
44+ assistant_messages = [extract_code (message .text ) for message in state .messages if message .role == "assistant" ]
45+ assert len (assistant_messages ) == len (state .metadata ["sub_steps" ])
5046 return assistant_messages
5147
5248
@@ -73,4 +69,4 @@ def subproblem_str_to_int(num: str) -> int:
7369 1
7470
7571 """
76- return int (num .split ('.' )[1 ])
72+ return int (num .split ("." )[1 ])
Original file line number Diff line number Diff line change 1+ from evalscope .api .dataset import Sample
2+ from evalscope .api .evaluator import TaskState
3+ from evalscope .api .messages import ChatMessageAssistant , ContentText
4+ from evalscope .benchmarks .scicode .util import get_generated_code
5+
6+
7+ def test_get_generated_code_accepts_text_content_blocks ():
8+ state = TaskState (
9+ model = "test" ,
10+ sample = Sample (input = "77" , metadata = {"sub_steps" : [{}]}),
11+ messages = [
12+ ChatMessageAssistant (content = [
13+ ContentText (text = "```python\n def answer():\n return 1\n ```" ),
14+ ], ),
15+ ],
16+ )
17+
18+ assert get_generated_code (state ) == ["def answer():\n return 1" ]
You can’t perform that action at this time.
0 commit comments