From 947d9dfdf16ae37109898111a5caacae7377b96d Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 4 Jun 2025 11:49:37 +0800 Subject: update code and kk eval --- code_eval/OpenCodeEval/backend/base.py | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 code_eval/OpenCodeEval/backend/base.py (limited to 'code_eval/OpenCodeEval/backend/base.py') diff --git a/code_eval/OpenCodeEval/backend/base.py b/code_eval/OpenCodeEval/backend/base.py new file mode 100644 index 0000000..42091b9 --- /dev/null +++ b/code_eval/OpenCodeEval/backend/base.py @@ -0,0 +1,55 @@ +from typing import Callable +from abc import ABC, abstractmethod + +def make_chat_template( + prompt: str, + response_prefix: str = "", + is_chat: bool = True, + tokenizer: Callable = None + ) -> str: + + if is_chat: + prompt = tokenizer.apply_chat_template( + [ + {"role": "user", "content": prompt}, + ], + tokenize = False, + add_generation_prompt = True + ) + response_prefix + if tokenizer.bos_token and prompt.startswith(tokenizer.bos_token): + prompt = prompt[len(tokenizer.bos_token):] + return prompt + else: + return prompt + +class Generator(ABC): + + model_name: str = None + + def __init__(self, model_name: str) -> None: + """ + :param stop_words: list + list of stop words if the generation uses a stopping criteria during generation + :param requires_execution: bool + wheter the task requires code execution during evaluation or not + """ + self.model_name = model_name + + def fewshot_examples(self): + """Loads and returns the few-shot examples for the task if they exist.""" + pass + + @abstractmethod + def set_stop(self): + """ + Set the stop tokens for the model + """ + pass + + @abstractmethod + def generate(self): + """Builds the prompt for the LM to generate from. + :param doc: dict[str: str] + sample from the test dataset + """ + pass \ No newline at end of file -- cgit v1.2.3