Skip to content

Commit 16de2a1

Browse files
committed
fix: testing util and oai runner
1 parent 051d813 commit 16de2a1

3 files changed

Lines changed: 59 additions & 5 deletions

File tree

‎lcb_runner/evaluation/testing_util.py‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,39 @@ def __exit__(self, *args):
7070
sys.stdout = self._stdout
7171

7272

73+
# Custom mock for sys.stdin that supports buffer attribute
74+
class MockStdinWithBuffer:
75+
def __init__(self, inputs: str):
76+
self.inputs = inputs
77+
self._stringio = StringIO(inputs)
78+
self.buffer = MockBuffer(inputs)
79+
80+
def read(self, *args):
81+
return self.inputs
82+
83+
def readline(self, *args):
84+
return self._stringio.readline(*args)
85+
86+
def readlines(self, *args):
87+
return self.inputs.split("\n")
88+
89+
def __getattr__(self, name):
90+
# Delegate other attributes to StringIO
91+
return getattr(self._stringio, name)
92+
93+
94+
class MockBuffer:
95+
def __init__(self, inputs: str):
96+
self.inputs = inputs.encode("utf-8") # Convert to bytes
97+
98+
def read(self, *args):
99+
# Return as byte strings that can be split
100+
return self.inputs
101+
102+
def readline(self, *args):
103+
return self.inputs.split(b"\n")[0] + b"\n"
104+
105+
73106
def clean_if_name(code: str) -> str:
74107
try:
75108
astree = ast.parse(code)
@@ -125,11 +158,14 @@ def call_method(method, inputs):
125158

126159
inputs_line_iterator = iter(inputs.split("\n"))
127160

161+
# Create custom stdin mock with buffer support
162+
mock_stdin = MockStdinWithBuffer(inputs)
163+
128164
# sys.setrecursionlimit(10000)
129165

130166
# @patch('builtins.input', side_effect=inputs.split("\n"))
131167
@patch("builtins.open", mock_open(read_data=inputs))
132-
@patch("sys.stdin", StringIO(inputs))
168+
@patch("sys.stdin", mock_stdin) # Use our custom mock instead of StringIO
133169
@patch("sys.stdin.readline", lambda *args: next(inputs_line_iterator))
134170
@patch("sys.stdin.readlines", lambda *args: inputs.split("\n"))
135171
@patch("sys.stdin.read", lambda *args: inputs)

‎lcb_runner/lm_styles.py‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,19 @@ def to_dict(self) -> dict:
476476
# link="https://ai.google.dev/gemini-api/docs/models/experimental-models",
477477
# ),
478478
LanguageModel(
479-
"gemini-2.5-pro-exp-03-25",
480-
"Gemini-2.5-Pro",
479+
"gemini-2.5-pro-preview-05-06",
480+
"Gemini-2.5-Pro-05-06",
481481
LMStyle.GeminiThinking,
482482
datetime(2023, 4, 30),
483483
link="https://blog.google/technology/google-deepmind/gemini-model-thinking-updates-march-2025/#advanced-coding",
484484
),
485+
# LanguageModel(
486+
# "gemini-2.5-pro-exp-03-25",
487+
# "Gemini-2.5-Pro-03-25",
488+
# LMStyle.GeminiThinking,
489+
# datetime(2023, 4, 30),
490+
# link="https://blog.google/technology/google-deepmind/gemini-model-thinking-updates-march-2025/#advanced-coding",
491+
# ),
485492
LanguageModel(
486493
"gemini-2.5-flash-preview-04-17",
487494
"Gemini-2.5-Flash-Preview",
@@ -629,6 +636,13 @@ def to_dict(self) -> dict:
629636
datetime(2024, 6, 30),
630637
link="https://huggingface.co/Qwen/Qwen2.5-Coder-32B-Instruct",
631638
),
639+
LanguageModel(
640+
"Qwen/Qwen3-235B-A22B",
641+
"Qwen3-235B-A22B",
642+
LMStyle.CodeQwenInstruct,
643+
datetime(2024, 6, 30),
644+
link="https://huggingface.co/Qwen/Qwen3-235B-A22B",
645+
),
632646
LanguageModel(
633647
"azerogpt",
634648
"AzeroGPT-64b",

‎lcb_runner/runner/oai_runner.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ def __init__(self, args, model):
4545
# "stop": args.stop, --> stop is only used for base models currently
4646
}
4747

48-
def _run_single(self, prompt: list[dict[str, str]]) -> list[str]:
48+
def _run_single(self, prompt: list[dict[str, str]], n: int = 10) -> list[str]:
4949
assert isinstance(prompt, list)
5050

51+
if n == 0:
52+
print("Max retries reached. Returning empty response.")
53+
return []
54+
5155
try:
5256
response = OpenAIRunner.client.chat.completions.create(
5357
messages=prompt,
@@ -67,7 +71,7 @@ def _run_single(self, prompt: list[dict[str, str]]) -> list[str]:
6771
print("Sleeping for 30 seconds...")
6872
print("Consider reducing the number of parallel processes.")
6973
sleep(30)
70-
return self._run_single(prompt)
74+
return self._run_single(prompt, n=n - 1)
7175
except Exception as e:
7276
print(f"Failed to run the model for {prompt}!")
7377
print("Exception: ", repr(e))

0 commit comments

Comments
 (0)