Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lcb_runner/lm_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class LMStyle(Enum):
CohereCommand = "CohereCommand"
DataBricks = "DataBricks"
DeepSeekAPI = "DeepSeekAPI"
QwenAPI = "QwenAPI"

GenericBase = "GenericBase"

Expand Down Expand Up @@ -544,6 +545,13 @@ def __hash__(self) -> int:
datetime(2024, 3, 31),
link="https://huggingface.co/qwen/Qwen1.5-72B-Chat/",
),
LanguageModel(
"qwen3.8-max",
"Qwen3.8-Max",
LMStyle.QwenAPI,
datetime(2026, 8, 2),
link="https://qwen.ai/blog?id=qwen3.8",
),
LanguageModel(
"abacusai/Smaug-2-72B",
"Smaug-2-72B ",
Expand Down
2 changes: 1 addition & 1 deletion lcb_runner/prompts/code_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.QwenAPI]:
chat_messages = [
{
"role": "system",
Expand Down
70 changes: 70 additions & 0 deletions lcb_runner/runner/qwen_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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 QwenRunner(BaseRunner):
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API"),
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/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 QwenRunner._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
4 changes: 4 additions & 0 deletions lcb_runner/runner/runner_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.QwenAPI:
from lcb_runner.runner.qwen_runner import QwenRunner

return QwenRunner(args, model)
elif model.model_style in []:
raise NotImplementedError(
f"Runner for language model style {model.model_style} not implemented yet"
Expand Down