### Install Miniconda for Environment Setup Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/base/benchmarks/ExecRepoBench/README.md Steps to download and install Miniconda3, a minimal installer for Conda, which is used to manage Python environments for the project. ```sh wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh ``` -------------------------------- ### Install and Configure Aider-Chat for AI Models Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/_includes/get-started.md This snippet provides instructions to install `aider-chat` and configure it to work with either Anthropic's Claude 3.5 Sonnet or OpenAI's GPT-4o. It covers installation via pip, navigating to a Git repository, and setting API keys for different AI providers before launching `aider`. ```Shell python -m pip install aider-chat # Change directory into a git repo cd /to/your/git/repo # Work with Claude 3.5 Sonnet on your repo export ANTHROPIC_API_KEY=your-key-goes-here aider # Work with GPT-4o on your repo export OPENAI_API_KEY=your-key-goes-here aider ``` -------------------------------- ### Running Aider Locally from Source Code Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/faq.md This guide provides step-by-step instructions for developers who wish to run 'aider' directly from its source code. It covers cloning the repository, navigating to the project directory, setting up a virtual environment, installing 'aider' in editable/development mode, and executing the local version. ```bash # Clone the repository git clone git@github.com:paul-gauthier/aider.git # Navigate to the project directory cd aider # It's recommended to make a virtual environment # Install aider in editable/development mode, # so it runs from the latest copy of these source files python -m pip install -e . # Run the local version of aider python -m aider ``` -------------------------------- ### Install Python Dependencies for DPO Training Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/finetuning/dpo/README.md After activating the Conda environment, this command installs all necessary Python packages listed in the 'requirements.txt' file. This ensures that all prerequisites for running the DPO training scripts are met. ```bash pip install -r requirements.txt ``` -------------------------------- ### General Setup for Aider with Local Ollama Models Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/llms/ollama.md Provides a comprehensive guide to setting up Aider to connect with any local Ollama model. This includes steps for pulling a model, starting the Ollama server, installing Aider, configuring the OLLAMA_API_BASE environment variable for both Mac/Linux and Windows, and finally, running Aider with the specified Ollama model. ```Shell # Pull the model ollama pull # Start your ollama server ollama serve # In another terminal window... python -m pip install aider-chat export OLLAMA_API_BASE=http://127.0.0.1:11434 # Mac/Linux setx OLLAMA_API_BASE http://127.0.0.1:11434 # Windows, restart shell after setx aider --model ollama/ ``` -------------------------------- ### Install Python Dependencies for SFT Training Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/finetuning/sft/README.md After activating the Conda environment, this command installs all necessary Python packages listed in the 'requirements.txt' file. These dependencies are crucial for running the supervised fine-tuning process. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install DevQualityEval CLI Tool Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/eval-dev-quality/README.md This snippet provides the necessary commands to clone the DevQualityEval repository, navigate into its directory, and install the `eval-dev-quality` command-line tool using Go. ```bash git clone https://github.com/symflower/eval-dev-quality.git cd eval-dev-quality go install -v github.com/symflower/eval-dev-quality/cmd/eval-dev-quality ``` -------------------------------- ### Execute Supervised Fine-Tuning (SFT) Script Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/finetuning/sft/README.md This bash command initiates the supervised fine-tuning process for the Qwen2.5-Coder model. It requires paths to the processed SFT data, the pretrained model, and the directory where training checkpoints will be saved. ```bash DATA_PATH="/path/to/processed/sft.jsonl" PRETRAINED_MODEL="/path/to/pretrained_models/Qwen/Qwen2___5-Coder-1___5B/" OUTPUT_DIR="/path/to/checkpoints/sft_model/" bash ./scripts/sft_qwencoder.sh ${DATA_PATH} ${PRETRAINED_MODEL} ${OUTPUT_DIR} ``` -------------------------------- ### Example of Aider's /help Mode Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/usage/modes.md Demonstrates how to use the `/help` command to get assistance with Aider usage, configuration, and troubleshooting, including external resource references. ```Shell /help How do I use ollama? Run `aider --model ollama/`. See these docs for more info: https://aider.chat/docs/llms/ollama.html ``` -------------------------------- ### Specific Setup for Llama3:70b with Aider and Ollama Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/llms/ollama.md Illustrates the specific steps to configure Aider for use with the `llama3:70b` model via Ollama. This snippet covers pulling the `llama3:70b` model, starting the Ollama server, setting the OLLAMA_API_BASE environment variable, and launching Aider to interact with this particular model. ```Shell ollama pull llama3:70b ollama serve # In another terminal window... export OLLAMA_API_BASE=http://127.0.0.1:11434 # Mac/Linux setx OLLAMA_API_BASE http://127.0.0.1:11434 # Windows, restart shell after setx aider --model ollama/llama3:70b ``` -------------------------------- ### Install EvalPlus and Dependencies for QwenCoder-2.5 Evaluation Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/eval_plus/readme.md This snippet provides the necessary commands to set up the environment for evaluating QwenCoder-2.5 models. It installs the EvalPlus benchmark tool and other project-specific dependencies listed in `requirements.txt`. ```bash pip install evalplus --upgrade pip install -r requirements.txt ``` -------------------------------- ### Install Aider and Interact with OpenAI Models Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/llms/openai.md This snippet provides instructions for installing the Aider chat tool, configuring the OpenAI API key, and using various command-line options to interact with different OpenAI GPT models, including specific versions like GPT-4o, GPT-4 Turbo, and GPT-3.5 Turbo. It also shows how to list available models and how to specify any other OpenAI model using the `--model` flag, for example, `aider --model gpt-4-0125-preview`. ```python python -m pip install aider-chat ``` ```bash export OPENAI_API_KEY= # Mac/Linux setx OPENAI_API_KEY # Windows, restart shell after setx # Aider uses gpt-4o by default (or use --4o) aider # GPT-4 Turbo (1106) aider --4-turbo # GPT-3.5 Turbo aider --35-turbo # List models available from OpenAI aider --list-models openai/ ``` -------------------------------- ### Install LiveCodeBench Dependencies Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/livecode_bench/README.md This snippet provides instructions for installing the required Python packages for LiveCodeBench. It emphasizes the necessity of CUDA version greater than 12.0 and includes the installation of `flash-attn` without build isolation. ```bash # Make sure the CUDA version > 12.0. pip install -r requirements.txt pip install flash-attn --no-build-isolation ``` -------------------------------- ### Execute DPO Training Script with Path Configurations Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/finetuning/dpo/README.md This snippet shows how to run the DPO training script after configuring the paths for preference data, the SFT model, and the output directory. It executes a bash script that initiates the training process using the specified resources. ```bash DATA_PATH="/path/to/preference/data" SFT_MODEL="/path/to/sft/model" OUTPUT_DIR="/path/to/output" bash ./scripts/dpo_qwencoder.sh ``` -------------------------------- ### Setup Aider Benchmarking Environment Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/benchmark/README.md Prepare your system for running Aider benchmarks by cloning necessary repositories, creating a scratch directory for results, copying practice exercises, and building the Docker container. These steps are performed once to establish the benchmarking infrastructure. ```shell # Clone the aider repo git clone git@github.com:paul-gauthier/aider.git # Create the scratch dir to hold benchmarking results inside the main aider dir: cd aider mkdir tmp.benchmarks # Clone the exercism repo git clone git@github.com:exercism/python.git # Copy the practice exercises into the benchmark scratch dir cp -rp python/exercises/practice tmp.benchmarks/exercism-python # Build the docker container ./benchmark/docker_build.sh ``` -------------------------------- ### Example JSONLINE Format for SFT Training Data Sample Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/finetuning/sft/README.md This JSON snippet illustrates the expected structure for a single sample within the raw JSONLINE SFT dataset. Each sample contains a 'messages' array, representing a conversation, and a 'format' field, typically 'chatml'. ```json { "messages":[ {"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."}, {"role": "user", "content": "Write a regex expression to match any letter of the alphabet"}, {"role": "assistant", "content": "The regex expression to match any letter of the alphabet (either in uppercase or lowercase) is: \n\n```regex\n[a-zA-Z]\n```"}, {"role": "user", "content": "How about if I only want to match uppercase letters? Can you modify the regex expression for that?"}, {"role": "assistant", "content": "Sure, the regex expression to match any uppercase letter of the alphabet is:\n\n```regex\n[A-Z]\n```"} ], "format": "chatml" } ``` -------------------------------- ### Install Aider and Configure API Keys on Windows Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/install/install.md This snippet provides the shell commands required to install the `aider-chat` package using pip on Windows systems. It also demonstrates how to invoke `aider` with specific large language models like GPT-4o (OpenAI) and Claude 3.5 Sonnet (Anthropic) by passing their respective API keys as command-line arguments. ```Shell # Install aider python -m pip install aider-chat # To work with GPT-4o: $ aider --4o --openai-api-key sk-xxx... # To work with Claude 3.5 Sonnet: $ aider --sonnet --anthropic-api-key sk-xxx... ``` -------------------------------- ### Create Flask App with Hello World Endpoint Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/examples/hello-world-flask.md Initializes a basic Flask application, defines a `/hello` endpoint that returns 'Hello, World!', and sets up the app to run when executed. Requires Flask to be installed. ```Python from flask import Flask app = Flask(__name__) @app.route('/hello') def hello(): return "Hello, World!" if __name__ == '__main__': app.run() ``` -------------------------------- ### Example Coding Conventions for AI Assistant Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/usage/conventions.md Defines preferred libraries (httpx over requests) and coding practices (use types) for Python projects, intended to guide an AI coding assistant like 'aider'. This content would typically be placed in a `CONVENTIONS.md` file. ```text - Prefer httpx over requests for making http requests. - Use types everywhere possible. ``` -------------------------------- ### Create and Activate Conda Environment for SFT Training Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/finetuning/sft/README.md This snippet creates a new Conda environment named 'sft_env' with Python 3.9 and then activates it. This environment is intended for supervised fine-tuning (SFT) of the Qwen2.5-Coder model. ```bash conda create -n sft_env python=3.9 conda activate sft_env ``` -------------------------------- ### Verify Evaluation Environments Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/base/benchmarks/ExecRepoBench/README.md Command to verify the correctness of all prepared repository environments. This ensures that the setup is ready for running evaluations. ```sh export PATH=./miniconda3/envs/vllm/bin/:$PATH python create_test_repo.py --action "verify_all_repo_correctness" ``` -------------------------------- ### Install Aider and Start a Pair Programming Session Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/index.md This snippet provides instructions for installing Aider using pip and then initiating an Aider session within a local Git repository. It demonstrates how to set API keys for both Anthropic (Claude 3.5 Sonnet) and OpenAI (GPT-4o) to specify the desired LLM for the pair programming session. ```Shell python -m pip install aider-chat # Change directory into a git repo cd /to/your/git/repo # Work with Claude 3.5 Sonnet on your repo export ANTHROPIC_API_KEY=your-key-goes-here aider # Work with GPT-4o on your repo export OPENAI_API_KEY=your-key-goes-here aider ``` -------------------------------- ### Merge LoRA Adapter with Base Model Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/finetuning/sft/README.md This script merges a trained LoRA adapter with its corresponding base model. It is used after supervised fine-tuning with LoRA to create a single, merged model. The script takes paths for the base model, the trained adapter, and the output directory for the merged model. ```bash BASE_MODEL_PATH=${1} TRAIN_ADAPTERS_PATH=${2} OUTPUT_PATH=${3} bash ./scripts/merge_adapter.sh ${BASE_MODEL_PATH} ${TRAIN_ADAPTERS_PATH} ${OUTPUT_PATH} ``` -------------------------------- ### Initial Instruction to GPT for Code Implementation Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/_posts/2023-07-02-benchmarks.md This instruction is sent by 'aider' to GPT at the beginning of each exercise. It provides the Exercism instructions, the initial implementation file content, and directives for modifying the file, keeping existing function/class stubs, and using only standard Python libraries without suggesting package installations. ```Plaintext Use the above instructions to modify the supplied files: Keep and implement the existing function or class stubs, they will be called from unit tests. Only use standard python libraries, don't suggest installing any packages. ``` -------------------------------- ### Install and Run Aider with pipx on Replit Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/install/pipx.md For Replit environments, first install `pipx` itself, then use `pipx run` to execute `aider-chat`. This approach bypasses potential issues like missing `libstdc++.so.6` library errors that can occur when running `aider` directly after a `pipx` installation on Replit. ```Shell pip install pipx pipx run aider-chat ...normal aider args... ``` -------------------------------- ### Install Aider and Launch Browser UI Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/usage/browser.md This snippet provides instructions to install the Aider CLI tool using pip, configure the OpenAI API key for authentication, and then launch Aider's experimental browser-based user interface. It includes commands for both Mac/Linux and Windows for setting the API key. ```Shell python -m pip install aider-chat export OPENAI_API_KEY= # Mac/Linux setx OPENAI_API_KEY # Windows, restart shell after setx aider --browser ``` -------------------------------- ### Example Aider Session for Factorial Program Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/usage.md Demonstrates an interactive `aider` session. The user initiates `aider` with `factorial.py` and then prompts the AI to create a program that asks for a number and prints its factorial. The snippet shows the initial `aider` output, including version, models, and git repository information. ```bash $ aider factorial.py Aider v0.37.1-dev Models: gpt-4o with diff edit format, weak model gpt-3.5-turbo Git repo: .git with 258 files Repo-map: using 1024 tokens Use /help to see in-chat commands, run with --help to see cmd line args ─────────────────────────────────────────────────────────────────────── > Make a program that asks for a number and prints its factorial ... ``` -------------------------------- ### Connecting to Groq Llama 3 70B with Aider Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/llms/groq.md This snippet provides instructions for installing `aider-chat`, setting the `GROQ_API_KEY` environment variable on different operating systems, and initiating a chat session with the `groq/llama3-70b-8192` model using `aider`. It also shows how to list available Groq models. ```shell python -m pip install aider-chat export GROQ_API_KEY= # Mac/Linux setx GROQ_API_KEY # Windows, restart shell after setx aider --model groq/llama3-70b-8192 # List models available from Groq aider --list-models groq/ ``` -------------------------------- ### Install Aider's Latest Development Version from GitHub Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/install/optional.md To access the most recent features and bug fixes, users can install the bleeding-edge development version of Aider directly from its GitHub repository using pip. This ensures you have the very latest updates. ```Python python -m pip install --upgrade git+https://github.com/paul-gauthier/aider.git ``` -------------------------------- ### Install PortAudio for Aider Voice Coding Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/install/optional.md Aider supports voice coding via the /voice command, which relies on the PortAudio library for audio capture. Installation is optional and varies by operating system. Windows users do not need to install PortAudio separately. ```Shell brew install portaudio ``` ```Shell sudo apt-get install libportaudio2 ``` -------------------------------- ### Initialize Qwen2.5-Coder Model for Repository-Level Tasks Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/README.md This code demonstrates the initial setup for performing repository-level code completion. It shows how to load the `AutoTokenizer` and `AutoModelForCausalLM` from the `transformers` library, preparing the Qwen2.5-Coder model for inference on multi-file inputs. ```python from transformers import AutoTokenizer, AutoModelForCausalLM device = "cuda" # the device to load the model onto # Now you do not need to add "trust_remote_code=True" TOKENIZER = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-Coder-32B") MODEL = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-Coder-32B", device_map="auto").eval() ``` -------------------------------- ### Install Aider and Configure API Keys on Mac/Linux Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/install/install.md This snippet provides the shell commands required to install the `aider-chat` package using pip on Mac or Linux systems. It also demonstrates how to invoke `aider` with specific large language models like GPT-4o (OpenAI) and Claude 3.5 Sonnet (Anthropic) by passing their respective API keys as command-line arguments. ```Shell # Install aider python -m pip install aider-chat # To work with GPT-4o: $ aider --4o --openai-api-key sk-xxx... # To work with Claude 3.5 Sonnet: $ aider --sonnet --anthropic-api-key sk-xxx... ``` -------------------------------- ### Install Aider and Configure DeepSeek API Key Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/llms/deepseek.md This snippet provides instructions for installing the `aider-chat` package, setting the `DEEPSEEK_API_KEY` environment variable for both Mac/Linux and Windows, and initiating Aider with the DeepSeek Coder V2 model. ```shell python -m pip install aider-chat export DEEPSEEK_API_KEY= # Mac/Linux setx DEEPSEEK_API_KEY # Windows, restart shell after setx # Use DeepSeek Coder V2 aider --deepseek ``` -------------------------------- ### Install and Launch Aider with Browser UI Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/_posts/2024-05-02-browser.md This snippet provides instructions for installing the `aider-chat` package using pip, setting the OpenAI API key for different operating systems (Mac/Linux and Windows), and then launching the Aider application with its experimental browser-based user interface. Ensure your API key is correctly configured before running. ```shell python -m pip install aider-chat export OPENAI_API_KEY= # Mac/Linux setx OPENAI_API_KEY # Windows, restart shell after setx aider --browser ``` -------------------------------- ### Run Aider with Specific Files Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/usage.md Explains how to start `aider` by specifying source code files to be edited. These files are then added to the chat session, allowing `aider` to view and modify their contents. Files can be existing or new ones that `aider` will create. ```bash aider ... ``` -------------------------------- ### Initiating Voice-to-Code with Aider Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/usage/voice.md Demonstrates how to start a voice recording session within the aider chat interface using the `/voice` command and how to end it by pressing ENTER. This command transcribes spoken instructions into text for code modifications. ```CLI /voice Recording, press ENTER when done... 3.5sec “ add a factorial endpoint that uses math factorial ” ``` -------------------------------- ### Install Required Project Dependencies Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/README.md After activating the Conda environment, this command installs all necessary Python packages listed in the `requirements.txt` file. This ensures all project dependencies are met for subsequent operations, such as running evaluation scripts. ```bash pip install -r requirements.txt ``` -------------------------------- ### Set Up Conda Environment for Qwen2.5-Coder SFT Training Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/README.md This snippet provides commands to create and activate a new Conda environment specifically for SFT training. It includes steps to define a benchmark, create the environment with Python 3.9, activate it, navigate to the benchmark directory, and install initial Python dependencies using `pip`. ```bash benchmark="eval_plus" conda create -n eval_${benchmark}_env python=3.9 conda activate eval_${benchmark}_env cd ${benchmark} pip install -r requirements.txt ``` -------------------------------- ### Using the Experimental Aider Repo Map Feature Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/_posts/2023-05-25-ctags.md Instructions to install and run `aider` with the experimental repository map feature. This involves installing `aider` and `ctags` as prerequisites, then executing the `aider` command within a repository to observe the repo-map token usage. ```Shell aider ``` -------------------------------- ### Generate Code Completions with Qwen2.5-Coder Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/README.md This snippet illustrates how to use the Qwen2.5-Coder model to generate code completions. It shows how to prepare a multi-file Python project as an input prompt, tokenize it, and then use the `MODEL.generate` function to obtain the generated code. The example demonstrates completing a `main.py` file for a library system. ```Python input_text = """<|repo_name|>library-system <|file_sep|>library.py class Book: def __init__(self, title, author, isbn, copies): self.title = title self.author = author self.isbn = isbn self.copies = copies def __str__(self): return f"Title: {self.title}, Author: {self.author}, ISBN: {self.isbn}, Copies: {self.copies}" class Library: def __init__(self): self.books = [] def add_book(self, title, author, isbn, copies): book = Book(title, author, isbn, copies) self.books.append(book) def find_book(self, isbn): for book in self.books: if book.isbn == isbn: return book return None def list_books(self): return self.books <|file_sep|>student.py class Student: def __init__(self, name, id): self.name = name self.id = id self.borrowed_books = [] def borrow_book(self, book, library): if book and book.copies > 0: self.borrowed_books.append(book) book.copies -= 1 return True return False def return_book(self, book, library): if book in self.borrowed_books: self.borrowed_books.remove(book) book.copies += 1 return True return False <|file_sep|>main.py from library import Library from student import Student def main(): # Set up the library with some books library = Library() library.add_book("The Great Gatsby", "F. Scott Fitzgerald", "1234567890", 3) library.add_book("To Kill a Mockingbird", "Harper Lee", "1234567891", 2) # Set up a student student = Student("Alice", "S1") # Student borrows a book """ model_inputs = TOKENIZER([input_text], return_tensors="pt").to(device) # Use `max_new_tokens` to control the maximum output length. generated_ids = MODEL.generate(model_inputs.input_ids, max_new_tokens=1024, do_sample=False)[0] # The generated_ids include prompt_ids, so we only need to decode the tokens after prompt_ids. output_text = TOKENIZER.decode(generated_ids[len(model_inputs.input_ids[0]):], skip_special_tokens=True) print(f"Prompt: \n{input_text}\n\nGenerated text: \n{output_text}") ``` ```Python book = library.find_book("1234567890") if student.borrow_book(book, library): print(f"{student.name} borrowed {book.title}") else: print(f"{student.name} could not borrow {book.title}") # Student returns a book if student.return_book(book, library): print(f"{student.name} returned {book.title}") else: print(f"{student.name} could not return {book.title}") # List all books in the library print("All books in the library:") for book in library.list_books(): print(book) if __name__ == "__main__": main() ``` -------------------------------- ### Complete Example of File-Level Code Completion with Qwen2.5-Coder Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/README.md This comprehensive Python example demonstrates how to perform file-level code completion using Qwen2.5-Coder. It covers loading the model and tokenizer, constructing an input with 'fill-in-the-middle' tokens, generating the missing code segment, and decoding the output. ```python from transformers import AutoTokenizer, AutoModelForCausalLM # load model device = "cuda" # the device to load the model onto TOKENIZER = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-Coder-32B") MODEL = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-Coder-32B", device_map="auto").eval() input_text = """<|fim_prefix|>def quicksort(arr): if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] <|fim_suffix|> middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return quicksort(left) + middle + quicksort(right)<|fim_middle|>""" model_inputs = TOKENIZER([input_text], return_tensors="pt").to(device) # Use `max_new_tokens` to control the maximum output length. generated_ids = MODEL.generate(model_inputs.input_ids, max_new_tokens=512, do_sample=False)[0] # The generated_ids include prompt_ids, we only need to decode the tokens after prompt_ids. output_text = TOKENIZER.decode(generated_ids[len(model_inputs.input_ids[0]):], skip_special_tokens=True) print(f"Prompt: {input_text}\n\nGenerated text: {output_text}") ``` -------------------------------- ### Installing and Using Aider with Various LLMs Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/_posts/2024-07-25-new-models.md This snippet provides instructions for installing the `aider-chat` Python package and demonstrates how to use it to interact with different large language models such as DeepSeek Coder, Mistral Large 2, and various Llama 3.1 models. It shows how to set necessary API keys as environment variables and specify the desired model when running `aider`. ```bash $ python -m pip install aider-chat # Change directory into a git repo to work on $ cd /to/your/git/repo $ export DEEPSEEK_API_KEY=your-key-goes-here $ aider --model deepseek/deepseek-coder $ export MISTRAL_API_KEY=your-key-goes-here $ aider --model mistral/mistral-large-2407 $ export OPENROUTER_API_KEY=your-key-goes-here $ aider --model openrouter/meta-llama/llama-3.1-405b-instruct $ aider --model openrouter/meta-llama/llama-3.1-70b-instruct $ aider --model openrouter/meta-llama/llama-3.1-8b-instruct ``` -------------------------------- ### Configuring Aider for OpenAI Compatible APIs Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/llms/openai-compat.md This snippet provides instructions for setting up Aider to use OpenAI-compatible APIs. It covers installing the `aider-chat` package, configuring the `OPENAI_API_BASE` and `OPENAI_API_KEY` environment variables for both Mac/Linux and Windows operating systems, and finally, demonstrating how to launch Aider with a specified OpenAI-compatible model. ```python python -m pip install aider-chat ``` ```bash export OPENAI_API_BASE= export OPENAI_API_KEY= ``` ```cmd setx OPENAI_API_BASE setx OPENAI_API_KEY # ... restart shell after setx commands ``` ```shell aider --model openai/ ``` -------------------------------- ### Chat with Qwen2.5-Coder-32B-Instruct using Transformers Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/README.md This example demonstrates how to load and interact with the Qwen2.5-Coder-32B-Instruct model for conversational purposes. It shows the process of initializing the model and tokenizer, applying a chat template to format messages, and generating responses. ```python from transformers import AutoModelForCausalLM, AutoTokenizer model_name = "Qwen/Qwen2.5-Coder-32B-Instruct" model = AutoModelForCausalLM.from_pretrained( model_name, torch_dtype="auto", device_map="auto" ) tokenizer = AutoTokenizer.from_pretrained(model_name) prompt = "write a quick sort algorithm." messages = [ {"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."}, {"role": "user", "content": prompt} ] text = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True ) model_inputs = tokenizer([text], return_tensors="pt").to(model.device) generated_ids = model.generate( **model_inputs, max_new_tokens=512 ) generated_ids = [ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids) ] response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0] ``` -------------------------------- ### Example of Aider's /ask Mode Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/usage/modes.md Illustrates how to use the `/ask` command to query Aider about the codebase without making any modifications, receiving an informational response. ```Shell /ask What is this repo? This is the source code to the popular django package. ``` -------------------------------- ### Initial Prompt for GPT to Implement Python Code Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/benchmarks.md This prompt is sent to GPT at the beginning of each exercise. It instructs the model to modify a specified implementation file, preserve existing function or class stubs, and only use standard Python libraries, without suggesting new package installations. ```Text Use the above instructions to modify the supplied files: Keep and implement the existing function or class stubs, they will be called from unit tests. Only use standard python libraries, don't suggest installing any packages. ``` -------------------------------- ### Introduce Aider Package Extras for Optional Features Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/HISTORY.md Aider now offers three new package extras (`[help]`, `[browser]`, `[playwright]`) that can be installed on demand. These extras provide extended functionality, allowing users to customize their Aider installation based on specific needs. ```Shell aider-chat[help] aider-chat[browser] aider-chat[playwright] ``` -------------------------------- ### Basic Aider Scripting with Python Coder Object Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/scripting.md This Python example demonstrates how to programmatically interact with `aider` using the `Coder` class. It shows how to initialize a coder with a model and target files, then execute multiple natural language instructions and even in-chat commands like `/tokens`. ```python from aider.coders import Coder from aider.models import Model # This is a list of files to add to the chat fnames = ["greeting.py"] model = Model("gpt-4-turbo") # Create a coder object coder = Coder.create(main_model=model, fnames=fnames) # This will execute one instruction on those files and then return coder.run("make a script that prints hello world") # Send another instruction coder.run("make it say goodbye") # You can run in-chat "/" commands too coder.run("/tokens") ``` -------------------------------- ### Configure OpenRouter API Key and Use General Models with Aider Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/llms/openrouter.md This snippet demonstrates how to install the `aider-chat` package, set the `OPENROUTER_API_KEY` environment variable on different operating systems, and use the `aider` command to connect to any OpenRouter model. It also shows how to list available OpenRouter models. ```Shell python -m pip install aider-chat export OPENROUTER_API_KEY= # Mac/Linux setx OPENROUTER_API_KEY # Windows, restart shell after setx # Or any other open router model aider --model openrouter// # List models available from OpenRouter aider --list-models openrouter/ ``` -------------------------------- ### Perform Startup Activities and Exit (Debug) Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/config/options.md Executes all initial startup procedures for Aider but exits before accepting any user input. Useful for testing the startup phase without entering interactive mode. ```APIDOC --exit Default: False Environment variable: AIDER_EXIT ``` -------------------------------- ### Install and Run Aider with Claude 3.5 Sonnet Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/_posts/2024-07-01-sonnet-not-lazy.md This snippet provides instructions for installing the `aider-chat` Python package and configuring the `ANTHROPIC_API_KEY` environment variable on both Mac/Linux and Windows. After setup, it shows how to launch Aider, which will then use Claude 3.5 Sonnet by default. ```Shell $ python -m pip install aider-chat $ export ANTHROPIC_API_KEY= # Mac/Linux $ setx ANTHROPIC_API_KEY # Windows, restart shell after setx $ aider ``` -------------------------------- ### Aider Startup Configuration Output Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/_includes/help.md This snippet displays the typical output generated by Aider when it starts up. It includes essential details such as the Aider version, the large language models (LLMs) being utilized, the status of the Git repository, and the token usage for the repository map. This information is highly valuable for debugging and providing context when reporting issues. ```Shell Aider v0.37.1-dev Models: gpt-4o with diff edit format, weak model gpt-3.5-turbo Git repo: .git with 243 files Repo-map: using 1024 tokens ``` -------------------------------- ### Configure and Use Cohere Command-R+ with Aider Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/llms/cohere.md This snippet provides instructions for installing Aider, setting the Cohere API key as an environment variable on both Mac/Linux and Windows, and then running Aider with the Command-R+ model. It also shows how to list available Cohere models from Cohere's API. ```Shell python -m pip install aider-chat export COHERE_API_KEY= # Mac/Linux setx COHERE_API_KEY # Windows, restart shell after setx aider --model command-r-plus # List models available from Cohere aider --list-models cohere_chat/ ``` -------------------------------- ### Aider /help: Using Local LLMs Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/troubleshooting/support.md Illustrates how to use the `/help` command to get information on configuring Aider to work with local LLMs, covering options like Ollama and OpenAI-compatible APIs, and noting performance considerations. ```APIDOC #### /help can i use local LLMs? Yes, you can use local LLMs with Aider. Here's a summary of the options: 1. Ollama: Aider supports using local models through Ollama. 2. OpenAI-compatible API: Aider can access local models that provide an OpenAI-compatible API. 3. Other local models: Aider uses the LiteLLM package to connect to various LLM providers, which may include options for running models locally. However, it's important to note that Aider works best with more capable models. Less capable models may have difficulty properly returning "code edits," which could result in Aider not being able to edit your files and commit changes effectively. For more detailed information on using local LLMs and connecting to various models, you might want to check out these relevant documentation pages: - https://aider.chat/docs/llms.html - https://aider.chat/docs/llms/ollama.html - https://aider.chat/docs/llms/openai-compat.html Keep in mind that the performance and capabilities of local LLMs may vary depending on the specific model and your hardware resources. ``` -------------------------------- ### Create Evaluation Environments Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/base/benchmarks/ExecRepoBench/README.md Command to prepare the necessary test repository environments for evaluation. This involves setting the PATH and running a Python script to set up the environments. ```sh export PATH=./miniconda3/envs/vllm/bin/:$PATH python create_test_repo.py --action "prepare_environments" ``` -------------------------------- ### Use Curly Braces for Multi-line Input Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/_includes/multi-line.md Explains how to use '{' and '}' as delimiters to start and end a multi-line message in the chat, allowing for structured multi-line entry. ```User Guide Enter '{' alone on the first line to start a multiline message and '}' alone on the last line to end it. ``` -------------------------------- ### Replace /dev/null with prompt_toolkit Input Mocking in main(['--yes', 'foo.txt']) Test Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/examples/complex-change.md Applies the `prompt_toolkit` input and output mocking pattern to a test case involving `main(['--yes', 'foo.txt'])`, replacing the `/dev/null` approach for consistent test setup and automated confirmation scenarios. ```python pipe_input = create_pipe_input() save_stdin = sys.stdin sys.stdin = pipe_input main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput()) sys.stdin = save_stdin pipe_input.close() self.assertTrue(os.path.exists("foo.txt")) ``` -------------------------------- ### Set up and Use Gemini 1.5 Pro with Aider Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/llms/gemini.md This snippet provides commands to install the Aider chat tool, configure your Gemini API key for both Mac/Linux and Windows environments, and then use Aider with the Gemini 1.5 Pro model, including listing available Gemini models. ```Shell python -m pip install aider-chat export GEMINI_API_KEY= # Mac/Linux setx GEMINI_API_KEY # Windows, restart shell after setx aider --model gemini/gemini-1.5-pro-latest # List models available from Gemini aider --list-models gemini/ ``` -------------------------------- ### Prepare Multi-File Input for Code Generation Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/examples/Qwen2.5-Coder.md Illustrates the structured input format for the Qwen2.5-Coder model when generating code for a multi-file project. This example provides a partial Python implementation of a library system across `library.py`, `student.py`, and `main.py`, expecting the model to complete the `main.py` logic. ```Python library-system <|file_sep|>library.py class Book: def __init__(self, title, author, isbn, copies): self.title = title self.author = author self.isbn = isbn self.copies = copies def __str__(self): return f"Title: {self.title}, Author: {self.author}, ISBN: {self.isbn}, Copies: {self.copies}" class Library: def __init__(self): self.books = [] def add_book(self, title, author, isbn, copies): book = Book(title, author, isbn, copies) self.books.append(book) def find_book(self, isbn): for book in self.books: if book.isbn == isbn: return book return None def list_books(self): return self.books <|file_sep|>student.py class Student: def __init__(self, name, id): self.name = name self.id = id self.borrowed_books = [] def borrow_book(self, book, library): if book and book.copies > 0: self.borrowed_books.append(book) book.copies -= 1 return True return False def return_book(self, book, library): if book in self.borrowed_books: self.borrowed_books.remove(book) book.copies += 1 return True return False <|file_sep|>main.py from library import Library from student import Student def main(): # Set up the library with some books library = Library() library.add_book("The Great Gatsby", "F. Scott Fitzgerald", "1234567890", 3) library.add_book("To Kill a Mockingbird", "Harper Lee", "1234567891", 2) # Set up a student student = Student("Alice", "S1") # Student borrows a book ``` -------------------------------- ### Overall JSONLINE Format for SFT Datasets Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/finetuning/sft/README.md This snippet shows the line-by-line structure of the raw JSONLINE file for SFT datasets. Each line represents a complete sample, formatted as a JSON object containing 'messages' and 'format' fields. ```json {"messages": [sample1...], "format": "chatml"} {"messages": [sample2...], "format": "chatml"} {"messages": [sample3...], "format": "chatml"} ``` -------------------------------- ### Initiate aider session for documentation update Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/examples/update-docs.md This command starts an 'aider' interactive session, adding the README.md documentation file and the aider/main.py source code file to the chat context. This setup allows 'aider' to analyze the code and suggest documentation updates. ```shell $ aider ./README.md aider/main.py ``` -------------------------------- ### Perform Startup Activities and Exit (Debug) Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/config/dotenv.md Executes all initial startup activities of AIDER but then exits before accepting any user input. This is a debug feature to test the application's initialization process. ```Configuration #AIDER_EXIT=false ``` -------------------------------- ### Create and Activate Conda Environment for DPO Training Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/finetuning/dpo/README.md This command creates a new Conda environment named 'dpo_env' with Python 3.10 and then activates it. This isolated environment is crucial for managing project dependencies without conflicts with other Python projects. ```bash conda create -n dpo_env python=3.10 conda activate dpo_env ``` -------------------------------- ### GPT Diff Code Editing Format Example Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/_posts/2023-07-02-benchmarks.md Illustrates the `diff` format used by GPT models for returning code edits. This format specifies the filename and provides original and updated code blocks, allowing for clear visualization of changes. ```python demo.py <<<<<<< ORIGINAL print("hello") ======= print("goodbye") >>>>>>> UPDATED ``` -------------------------------- ### Example Aider Repo Map for Python Files Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/_posts/2023-10-22-repomap.md This snippet illustrates a partial repo map generated by Aider, showing the structure for `aider/coders/base_coder.py` and `aider/commands.py`. It includes key class and method definitions with their signatures, demonstrating how Aider provides concise, relevant context to the LLM by omitting less critical code (indicated by `⋮...`). ```Python aider/coders/base_coder.py: ⋮... │class Coder: │ abs_fnames = None ⋮... │ @classmethod │ def create( │ self, │ main_model, │ edit_format, │ io, │ skip_model_availabily_check=False, │ **kwargs, ⋮... │ def abs_root_path(self, path): ⋮... │ def run(self, with_message=None): ⋮... aider/commands.py: ⋮... │class Commands: │ voice = None │ ⋮... │ def get_commands(self): ⋮... │ def get_command_completions(self, cmd_name, partial): ⋮... │ def run(self, inp): ⋮... ``` -------------------------------- ### Example Python Source Code for Diff Comparison Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/unified-diffs.md Illustrates a simple Python script with a 'main' function and a comment, used as a baseline to demonstrate common issues with GPT-generated diffs, specifically missing context lines. ```python import sys def main(args): # show a greeting print("Hello!") return main(sys.argv[1:]) ``` -------------------------------- ### Binarize Raw SFT Data using Script Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/finetuning/sft/README.md This bash script command binarizes the raw JSONLINE SFT data into a processed format. It requires specifying the input path of the raw data, the desired output path for the processed data, and the path to the Qwen2.5-Coder tokenizer. ```bash INPUT_PATH="/path/to/raw/sft.jsonl" OUTPUT_PATH="/path/to/processed/sft.jsonl" TOKENIZER_PATH="/path/to/pretrained_models/Qwen/Qwen2___5-Coder-1___5B/" bash ./scripts/binarize_data.sh ${INPUT_PATH} ${OUTPUT_PATH} ${TOKENIZER_PATH} ``` -------------------------------- ### Example of Unified Diff Format for Code Editing Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/unified-diffs.md This snippet demonstrates the standard unified diff format, commonly used by `git diff`, showing how a line of code is changed from 'Hello!' to 'Goodbye!' in a Python file. This format is highlighted as being particularly effective for guiding GPT-4 Turbo's code editing. ```Diff --- a/greeting.py +++ b/greeting.py @@ -1,5 +1,5 @@ def main(args): # show a greeting - print("Hello!") + print("Goodbye!") return ``` -------------------------------- ### CSS for Responsive Video Player Styling Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/install.md This CSS snippet provides styles for a responsive video container, ensuring the embedded video maintains its aspect ratio and scales correctly within the page layout. It uses relative positioning, padding-bottom for aspect ratio, and absolute positioning for the video element. ```CSS .video-container { position: relative; padding-bottom: 76.2711864407%; height: 0; overflow: hidden; } .video-container video { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } ``` -------------------------------- ### Initialize Pygame Window and Game Loop Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/examples/pong.md This snippet sets up the basic Pygame environment. It initializes Pygame, creates a display window with specified dimensions, sets the window caption, and establishes a fundamental game loop to handle events and update the display. ```Python import pygame import sys # Initialize Pygame pygame.init() # Set up the game window screen_width = 640 screen_height = 480 screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption("Pong") # Game loop running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # Update game objects # Draw game objects # Update the display pygame.display.flip() # Quit Pygame pygame.quit() sys.exit() ``` -------------------------------- ### Define JSONL Data Format for DPO Training Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/finetuning/dpo/README.md This JSON structure illustrates the required format for preference data used in DPO training. Each line in the JSONL file should be a single JSON object containing 'prompt', 'chosen', and 'rejected' fields, representing a preference triplet. ```json { "prompt": "Prompt", "chosen": "The chosen response", "rejected": "The rejected response" } ``` -------------------------------- ### Install Aider Globally with pipx Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/docs/install/pipx.md Install `aider-chat` globally using `pipx` to ensure it runs in an isolated Python environment. This prevents dependency conflicts with other Python projects that might require different versions of packages, resolving common `pip install` errors related to incompatible package versions. ```Shell pipx install aider-chat ``` -------------------------------- ### Initialize 2048 Game Repository with Aider Source: https://github.com/qwenlm/qwen2.5-coder/blob/main/qwencoder-eval/instruct/aider/aider/website/examples/2048-game.md This snippet outlines the initial steps to set up the 2048 game repository for modification using `aider`. It involves cloning the GitHub repository, navigating into its directory, and then launching the `aider` tool to begin interactive code assistance. ```bash $ git clone https://github.com/gabrielecirulli/2048 $ cd 2048 $ aider ```