From 41c52c25d526fd8def6ec1e1cfb81bb7bd448dca Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 12 Aug 2026 17:58:34 +0000 Subject: [PATCH] Add Grok 4.6 to live bench runs --- lcb_runner/lm_styles.py | 8 ++++ lcb_runner/prompts/code_generation.py | 2 +- lcb_runner/runner/runner_utils.py | 4 ++ lcb_runner/runner/xai_runner.py | 69 +++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 lcb_runner/runner/xai_runner.py diff --git a/lcb_runner/lm_styles.py b/lcb_runner/lm_styles.py index 66988366..6bf76605 100644 --- a/lcb_runner/lm_styles.py +++ b/lcb_runner/lm_styles.py @@ -12,6 +12,7 @@ class LMStyle(Enum): CohereCommand = "CohereCommand" DataBricks = "DataBricks" DeepSeekAPI = "DeepSeekAPI" + XAIAPI = "XAIAPI" GenericBase = "GenericBase" @@ -614,6 +615,13 @@ def __hash__(self) -> int: datetime(2023, 1, 1), link="https://huggingface.co/abacusai/Dracarys-72B-Instruct", ), + LanguageModel( + "grok-4.6", + "Grok-4.6", + LMStyle.XAIAPI, + datetime(2026, 8, 12), + link="https://docs.x.ai/developers/grok-4-6", + ), ] LanguageModelStore: dict[str, LanguageModel] = { diff --git a/lcb_runner/prompts/code_generation.py b/lcb_runner/prompts/code_generation.py index 020d4617..814373ff 100644 --- a/lcb_runner/prompts/code_generation.py +++ b/lcb_runner/prompts/code_generation.py @@ -206,7 +206,7 @@ def get_example_prompt(example): def format_prompt_generation( question: CodeGenerationProblem, LanguageModelStyle: LMStyle ) -> str: - if LanguageModelStyle in [LMStyle.OpenAIChat, LMStyle.DeepSeekAPI]: + if LanguageModelStyle in [LMStyle.OpenAIChat, LMStyle.DeepSeekAPI, LMStyle.XAIAPI]: chat_messages = [ { "role": "system", diff --git a/lcb_runner/runner/runner_utils.py b/lcb_runner/runner/runner_utils.py index a6aa6ee2..4f88c97c 100644 --- a/lcb_runner/runner/runner_utils.py +++ b/lcb_runner/runner/runner_utils.py @@ -30,6 +30,10 @@ def build_runner(args, model: LanguageModel): from lcb_runner.runner.deepseek_runner import DeepSeekRunner return DeepSeekRunner(args, model) + if model.model_style == LMStyle.XAIAPI: + from lcb_runner.runner.xai_runner import XAIRunner + + return XAIRunner(args, model) elif model.model_style in []: raise NotImplementedError( f"Runner for language model style {model.model_style} not implemented yet" diff --git a/lcb_runner/runner/xai_runner.py b/lcb_runner/runner/xai_runner.py new file mode 100644 index 00000000..39b69e00 --- /dev/null +++ b/lcb_runner/runner/xai_runner.py @@ -0,0 +1,69 @@ +import os +from time import sleep + +try: + import openai + from openai import OpenAI +except ImportError as e: + pass + +from lcb_runner.runner.base_runner import BaseRunner + + +class XAIRunner(BaseRunner): + client = OpenAI( + api_key=os.getenv("XAI_API"), base_url="https://api.x.ai/v1" + ) + + def __init__(self, args, model): + super().__init__(args, model) + self.client_kwargs: dict[str | str] = { + "model": args.model, + "temperature": args.temperature, + "max_tokens": args.max_tokens, + "top_p": args.top_p, + "frequency_penalty": 0, + "presence_penalty": 0, + "n": 1, + "timeout": args.openai_timeout, + # "stop": args.stop, --> stop is only used for base models currently + } + + def _run_single(self, prompt: list[dict[str, str]]) -> list[str]: + assert isinstance(prompt, list) + + def __run_single(counter): + try: + response = self.client.chat.completions.create( + messages=prompt, + **self.client_kwargs, + ) + content = response.choices[0].message.content + return content + except ( + openai.APIError, + openai.RateLimitError, + openai.InternalServerError, + openai.OpenAIError, + openai.APIStatusError, + openai.APITimeoutError, + openai.InternalServerError, + openai.APIConnectionError, + ) as e: + print("Exception: ", repr(e)) + print("Sleeping for 30 seconds...") + print("Consider reducing the number of parallel processes.") + sleep(30) + return XAIRunner._run_single(prompt) + except Exception as e: + print(f"Failed to run the model for {prompt}!") + print("Exception: ", repr(e)) + raise e + + outputs = [] + try: + for _ in range(self.args.n): + outputs.append(__run_single(10)) + except Exception as e: + raise e + return outputs