### check_auth() Source: https://context7.com/qwenlm/codeelo/llms.txt Sends a GET request to /check_auth with the Authorization header to validate the configured token. Returns the full requests.Response object. ```APIDOC ## check_auth() ### Description Verifies the authentication token by sending a GET request to the `/check_auth` endpoint. ### Method GET ### Endpoint /check_auth ### Parameters None ### Request Example ```python from api import check_auth auth = check_auth() if auth.status_code != 200: print(f"Auth failed: {auth.text}") else: print("Authenticated successfully") ``` ### Response #### Success Response (200) - **response** (requests.Response) - The full response object from the server. #### Error Response (401/403) - **response** (requests.Response) - The full response object from the server indicating authentication failure. ``` -------------------------------- ### Verify Authentication Token Source: https://context7.com/qwenlm/codeelo/llms.txt Validates the configured authentication token by sending a GET request to the /check_auth endpoint. Inspect the status code and response text for authentication status. ```python from api import check_auth auth = check_auth() if auth.status_code != 200: print(f"Auth failed: {auth.text}") else: print("Authenticated successfully") ``` -------------------------------- ### Serve a Local LLM with vLLM Source: https://github.com/qwenlm/codeelo/blob/main/README.md Host a local LLM server using vLLM for testing. This command serves the specified model, making it accessible for the evaluation script. ```bash vllm serve Qwen/Qwen2.5-Coder-7B-Instruct ``` -------------------------------- ### Set Environment Variables for Token and Base URL Source: https://github.com/qwenlm/codeelo/blob/main/README.md Set your access TOKEN and BASE_URL as environment variables before running the evaluation. Replace 'your_actual_token' and 'your_base_url' with your obtained credentials. ```bash export TOKEN="your_actual_token" # replace with your actual token export BASE_URL="your_base_url" # replace with base url ``` -------------------------------- ### Run End-to-End Evaluation Pipeline Source: https://context7.com/qwenlm/codeelo/llms.txt Executes the full benchmark pipeline, including iterating through contests, prompting the LLM, submitting solutions, collecting verdicts, and reporting aggregate Elo rating and percentile. Requires setting environment variables for authentication. ```bash # Step 1: Set credentials (obtained by emailing the authors and signing the AGREEMENT) export TOKEN="your_actual_token" export BASE_URL="https://your-base-url" # Step 2: Start a local LLM server (skip if using a third-party API) vllm serve Qwen/Qwen2.5-Coder-7B-Instruct # Step 3: Run evaluation over contests 2000–2010 python main.py \ --model Qwen/Qwen2.5-Coder-7B-Instruct \ --bid 2000 \ --eid 2010 # Expected output (abbreviated): # Authenticated # Problems: {"problems": [...]} id: 2000, len(problems) = 6 # Processing 2000, 0, problem: {'prob': '2000A', ...} # AC at 2000A in 1th submission, total submissions: 8 # ... # status_dict: {'2000A': ['AC', 'WA', ...], '2000B': [...], ...} # ratings: {2000: 1812, 2001: 1654, ...} # Average rating: 1733.0, percentile: 61.2 ``` -------------------------------- ### hello() Source: https://context7.com/qwenlm/codeelo/llms.txt Performs a basic health check against the CodeElo submission backend. Returns the server's response text, or an error string after RETRY failed attempts with DELAY-second back-off. ```APIDOC ## hello() ### Description Performs a basic health check against the CodeElo submission backend. ### Method GET ### Endpoint / ### Parameters None ### Request Example ```python import os from api import hello os.environ["TOKEN"] = "your_token" os.environ["BASE_URL"] = "https://your-base-url" response = hello() print(response) ``` ### Response #### Success Response (200) - **response** (string) - Server's response text (e.g., "OK" or "Welcome to CodeElo API") ``` -------------------------------- ### get_response(prompt, model) Source: https://context7.com/qwenlm/codeelo/llms.txt Sends a prompt to an OpenAI-compatible LLM server and returns the model's text response. Stop tokens, sampling parameters, and a repetition penalty are pre-configured for competitive programming tasks. ```APIDOC ## get_response(prompt, model) ### Description Queries an OpenAI-compatible LLM for a code generation response based on a given prompt. ### Method POST ### Endpoint /v1/chat/completions (Assumed endpoint for OpenAI-compatible LLM) ### Parameters #### Request Body - **prompt** (string) - Required - The input prompt for the LLM. - **model** (string) - Required - The identifier of the LLM model to use. ### Request Example ```python from llm_client import get_response # Requires a running vLLM server: http://localhost:8000/v1 response = get_response( prompt="Write a Python function to calculate the factorial of a number.", model="local-model" ) print(response) ``` ### Response #### Success Response (200) - **response** (string) - The text response generated by the LLM. ``` -------------------------------- ### Query LLM for Code Solution Source: https://context7.com/qwenlm/codeelo/llms.txt Sends a prompt to an OpenAI-compatible LLM server to generate a code solution. This function is pre-configured with stop tokens and sampling parameters suitable for competitive programming. ```python from llm_client import get_response # Requires a running vLLM server: ``` -------------------------------- ### Run Model Evaluation Script Source: https://github.com/qwenlm/codeelo/blob/main/README.md Execute the main evaluation script to test a model's performance. Specify the model name and the range of contest IDs (bid to eid) to evaluate. ```bash python main.py --model Qwen/Qwen2.5-Coder-7B-Instruct \ --bid 2000 --eid 2030 ``` -------------------------------- ### Render Problem as HTML Source: https://context7.com/qwenlm/codeelo/llms.txt Converts structured problem data into an HTML string for prompt inclusion. The first section is an H1, subsequent sections are H2 headings. Requires `get_problem` to fetch data and `json.loads` for parsing. ```python import json from api import get_problem from main import make_html_problem problem_raw = get_problem("2024A") problem_data = json.loads(problem_raw["json_str"]) html = make_html_problem(problem_data) print(html[:200]) #

Sasha and the Beautiful Array

...

Input

...
``` -------------------------------- ### Fetch All Problems for a Contest Source: https://context7.com/qwenlm/codeelo/llms.txt Retrieves all problems for a specified CodeForces contest ID. Use `update=True` to bypass the cache and fetch fresh data from CodeForces. ```python from api import get_all_problems # Fetch problems for contest 2024 result = get_all_problems(2024) # result = {"problems": [{"prob": "2024A", "json_str": "{...}"}, ...]}; problems = result["problems"] for p in problems: print(p["prob"]) # e.g., "2024A", "2024B", ... # Force update from CodeForces result_fresh = get_all_problems(2024, update=True) ``` -------------------------------- ### Fetch Details for a Single Problem Source: https://context7.com/qwenlm/codeelo/llms.txt Retrieves the complete problem statement and metadata for a given problem identifier (e.g., "2024A"). The raw JSON string is parsed to access problem details. ```python from api import get_problem import json problem_raw = get_problem("2024A") problem_data = json.loads(problem_raw["json_str"]) title = problem_data["meta"]["title"] sections = problem_data["statement"]["content"]["sections"] print(f"Problem: {title}") for section in sections: print(section["title"]) # Output: # Problem: Sasha and the Beautiful Array # (empty — first section is the problem body) # Input # Output # Examples ``` -------------------------------- ### Submit Code Solution to CodeForces Source: https://context7.com/qwenlm/codeelo/llms.txt Submits a code solution for a specific problem and programming language to CodeForces. The `lang` parameter must correspond to a valid language ID. A `tag` can be optionally provided. ```python from api import submit_code code = "" #include using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; cout << n << "\n"; } } " result = submit_code( prob="2024A", lang=91, # GNU G++23 14.2 (64 bit) code=code, tag="Qwen/Qwen2.5-Coder-7B-Instruct" ) print(result) # {"submission_id": "298471023"} submission_id = result["submission_id"] ``` -------------------------------- ### get_all_problems(cid, update=False) Source: https://context7.com/qwenlm/codeelo/llms.txt Retrieves the full list of problems for a given CodeForces contest ID. Set update=True to force a refresh from CodeForces rather than using a cached result. ```APIDOC ## get_all_problems(cid, update=False) ### Description Fetches all problems for a specified CodeForces contest ID. Optionally forces an update from CodeForces. ### Method GET ### Endpoint /problems/{cid} ### Parameters #### Path Parameters - **cid** (integer) - Required - The CodeForces contest ID. #### Query Parameters - **update** (boolean) - Optional - Defaults to `False`. If `True`, forces a refresh from CodeForces. ### Request Example ```python from api import get_all_problems # Fetch problems for contest 2024 result = get_all_problems(2024) problems = result["problems"] for p in problems: print(p["prob"]) # Force update from CodeForces result_fresh = get_all_problems(2024, update=True) ``` ### Response #### Success Response (200) - **problems** (array) - A list of problems, where each problem is an object with `prob` (string) and `json_str` (string) fields. - **prob** (string) - The problem identifier (e.g., "2024A"). - **json_str** (string) - A JSON string containing detailed problem information. ``` -------------------------------- ### get_problem(prob) Source: https://context7.com/qwenlm/codeelo/llms.txt Retrieves the full problem statement and metadata for a single problem identifier (e.g., "2024A"). ```APIDOC ## get_problem(prob) ### Description Retrieves the detailed statement and metadata for a specific problem. ### Method GET ### Endpoint /problem/{prob} ### Parameters #### Path Parameters - **prob** (string) - Required - The problem identifier (e.g., "2024A"). ### Request Example ```python from api import get_problem import json problem_raw = get_problem("2024A") problem_data = json.loads(problem_raw["json_str"]) title = problem_data["meta"]["title"] sections = problem_data["statement"]["content"]["sections"] print(f"Problem: {title}") for section in sections: print(section["title"]) ``` ### Response #### Success Response (200) - **json_str** (string) - A JSON string containing the full problem statement and metadata. ``` -------------------------------- ### Check CodeElo Server Connectivity Source: https://context7.com/qwenlm/codeelo/llms.txt Use this function to perform a basic health check against the CodeElo submission backend. Ensure your TOKEN and BASE_URL environment variables are set. ```python import os from api import hello os.environ["TOKEN"] = "your_token" os.environ["BASE_URL"] = "https://your-base-url" # Check if the server is reachable response = hello() print(response) # e.g., "OK" or "Welcome to CodeElo API" ``` -------------------------------- ### submit_code(prob, lang, code, tag='') Source: https://context7.com/qwenlm/codeelo/llms.txt POSTs a code submission to the backend. `lang` must be one of the integer IDs from `lang_map` in `main.py`. Returns a dict containing the `submission_id`. ```APIDOC ## submit_code(prob, lang, code, tag='') ### Description Submits a code solution for a specific problem to the CodeForces backend. ### Method POST ### Endpoint /submit ### Parameters #### Request Body - **prob** (string) - Required - The problem identifier (e.g., "2024A"). - **lang** (integer) - Required - The language ID for the submission (e.g., 91 for GNU G++23). - **code** (string) - Required - The source code of the solution. - **tag** (string) - Optional - Defaults to "". A tag for the submission, potentially identifying the model used. ### Request Example ```python from api import submit_code code = "#include \nusing namespace std;\nint main() {\n int t; cin >> t;\n while (t--) {\n int n; cin >> n;\n cout << n << \"\\n\";\n }\n}\n" result = submit_code( prob="2024A", lang=91, # GNU G++23 14.2 (64 bit) code=code, tag="Qwen/Qwen2.5-Coder-7B-Instruct" ) print(result) ``` ### Response #### Success Response (200) - **submission_id** (string) - The unique identifier for the submitted code. ``` -------------------------------- ### Extract Code Blocks from LLM Response Source: https://context7.com/qwenlm/codeelo/llms.txt Parses LLM output to extract fenced code blocks. It returns a list of (language, code) tuples. Ensure the LLM response is correctly formatted with triple backticks. ```python from main import extract_code_blocks llm_output = """ Here is the solution: ```cpp #include using namespace std; int main(){ cout << 42; } ``` """ blocks = extract_code_blocks(llm_output) print(blocks) # [('cpp', '#include\nusing namespace std;\nint main(){ cout << 42; }')] lang, code = blocks[0] print(lang) # "cpp" print(code[:30]) # "#include..." ``` -------------------------------- ### Compute Elo Rating Source: https://context7.com/qwenlm/codeelo/llms.txt Calculates an estimated Elo rating by fetching contest standings and simulating model rank. It uses a binary-search approach for Elo computation. The `problem_status` dictionary maps problem IDs to verdict lists. ```python from calc_rating import calc_elo_rating # Simulate: solved 2024A on 2nd try, solved 2024B on 1st try problem_status = { "2024A": ["WA", "AC"], # 1 wrong attempt, then accepted "2024B": ["AC"], # accepted on first try "2024C": ["WA", "WA"], # never accepted } rating = calc_elo_rating(contest_id=2024, problem_status=problem_status) print(f"Estimated Elo rating: {rating}") # Output: Estimated Elo rating: 1743 ``` -------------------------------- ### Convert Elo Rating to Percentile Source: https://context7.com/qwenlm/codeelo/llms.txt Converts an Elo rating to a human percentile (0-100) by comparing against a reference distribution of CodeForces users. Returns a float rounded to one decimal place. Uses `sorted_ratings.json` for reference. ```python from calc_rating import get_percentile rating = 1743 percentile = get_percentile(rating) print(f"Percentile: {percentile}%") # Output: Percentile: 63.4% # Common reference points: print(get_percentile(1200)) # ~20th percentile (Pupil) print(get_percentile(1900)) # ~80th percentile (Candidate Master) print(get_percentile(2400)) # ~97+ percentile (International Master) ``` -------------------------------- ### check_status(submission_id) Source: https://context7.com/qwenlm/codeelo/llms.txt Polls the backend for the current judge verdict of a submission. Returns a dict containing `status_canonical` (e.g., "AC", "WA", "TLE", "RE"). ```APIDOC ## check_status(submission_id) ### Description Polls the submission backend to retrieve the current verdict of a submitted solution. ### Method GET ### Endpoint /status/{submission_id} ### Parameters #### Path Parameters - **submission_id** (string) - Required - The unique identifier of the submission. ### Request Example ```python from api import check_status import time submission_id = "298471023" # Poll until a terminal verdict is returned while True: status = check_status(submission_id) verdict = status.get("status_canonical") print(f"Verdict: {verdict}") if verdict in ("AC", "WA", "TLE", "RE", "MLE", "CE"): break time.sleep(5) ``` ### Response #### Success Response (200) - **status_canonical** (string) - The canonical verdict of the submission (e.g., "AC", "WA", "TLE", "RE", "MLE", "CE"). ``` -------------------------------- ### Poll Submission Status for Verdict Source: https://context7.com/qwenlm/codeelo/llms.txt Periodically queries the submission backend for the judge verdict of a given submission ID. The loop continues until a terminal verdict (AC, WA, TLE, RE, MLE, CE) is received. ```python from api import check_status import time submission_id = "298471023" # Poll until a terminal verdict is returned while True: status = check_status(submission_id) verdict = status.get("status_canonical") print(f"Verdict: {verdict}") if verdict in ("AC", "WA", "TLE", "RE", "MLE", "CE"): break time.sleep(5) # Output: # Verdict: AC ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.