Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Episode 2 code generation and optimization #14

Merged
merged 16 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ po/*~

# Mac OS X Finder
.DS_Store

# Custom folders
exercises/
6 changes: 3 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ contact: '[email protected]' # FIXME

# Order of episodes in your lesson
episodes:
- Introduction-AI-coding.md
- introduction-ai-coding.md
- code-generation-optimization.md
- Enhancing-coding-efficiency.md
- Ethical-and-security-considerations.md
- enhancing-coding-efficiency.md
- ethical-and-security-considerations.md

# Information for Learners
learners:
Expand Down
349 changes: 322 additions & 27 deletions episodes/code-generation-optimization.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ exercises: 15

:::::::::::::::::::::::::::::::::::::: questions

- How can the autocomplete function in Codeium help improve your coding speed?
- How can the Autocomplete function in Codeium help improve your coding speed?
- What types of repetitive coding tasks can be automated?
- What are some key components of a clear and effective prompt when using the autocomplete function?
- What are some key components of a clear and effective prompt when using the Autocomplete function?
- In what ways can Codeium assist in generating and improving code documentation?

::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::: objectives

- Use an autocomplete function of Codeium to improve coding speed
- Automate repetitive coding tasks using the autocomplete function of Codeium
- Compose clear and effective prompts that capture and facilitate the expected outcomes using the autocomplete function
- Use an Autocomplete function of Codeium to improve coding speed
- Automate repetitive coding tasks using the Autocomplete function of Codeium
- Compose clear and effective prompts that capture and facilitate the expected outcomes using the Autocomplete function
- Generate and improve documentation using Codeium

::::::::::::::::::::::::::::::::::::::::::::::::

## Autocomplete Function

A key feature of Codeium is its autocomplete function: with every keystroke, Codeium actively attempts to predict and complete what you're typing. By analyzing the current file, previous edits, and contextual snippets from your codebase, it offers relevant suggestions as "ghost text".
A key feature of Codeium is its Autocomplete function: with every keystroke, Codeium actively attempts to predict and complete what you're typing. By analyzing the current file, previous edits, and contextual snippets from your codebase, it offers relevant suggestions as "ghost text".

![](episodes/fig/acceleration.gif){alt='Autocomplete Function'}

This feature can be particularly useful when you're writing boilerplate code (which refers to repetitive code that often serves as a standard template), as it can save you time and reduce the likelihood of errors. By leveraging Codeium's autocomplete function, you can speed up your coding process and focus on the more creative and challenging aspects of your work.
This feature can be particularly useful when you're writing boilerplate code (which refers to repetitive code that often serves as a standard template), as it can save you time and reduce the likelihood of errors. By leveraging Codeium's Autocomplete function, you can speed up your coding process and focus on the more creative and challenging aspects of your work.

### Boilerplate, Formatting, and More

Expand Down Expand Up @@ -60,7 +60,7 @@ Note that the non-FIM model suggests a generic docstring based on only the prece

### Inline Comments

You can guide the autocomplete feature by using comments within your code. Codeium interprets these comments and generates code suggestions to implement what the comment describes.
You can guide the Autocomplete feature by using comments within your code. Codeium interprets these comments and generates code suggestions to implement what the comment describes.

![](episodes/fig/minimize_boilerplate.gif){alt='Inline Comments'}

Expand All @@ -84,18 +84,18 @@ The following shortcuts can be used to speed up your workflow:

### Best Practices

- Avoid manually triggering autocomplete; instead, let it naturally enhance your workflow. Writing prompts as comments is not recommended, but decorating your code with quality comments and information variable/function names yields the best results.
- To achieve the best results with autocomplete, it's important to enhance your code with clear, *declarative* (not instructive) code, descriptive function names, and good comments with examples of the desired inputs and outputs. See the table below for examples:
- Avoid manually triggering Autocomplete; instead, let it naturally enhance your workflow. Writing prompts as comments is not recommended, but decorating your code with quality comments and information variable/function names yields the best results.
- To achieve the best results with Autocomplete, it's important to enhance your code with clear, *declarative* (not instructive) code, descriptive function names, and good comments with examples of the desired inputs and outputs. See the table below for examples:

![](episodes/fig/table_autocomplete.png){alt='Best Practices for Autocomplete'}

- If needed, you can temporarily snooze autocomplete. This feature is available in VS Code version 1.8.66. Simply click the Codeium button in the bottom right to access it.
- If needed, you can temporarily snooze Autocomplete. This feature is available in VS Code version 1.8.66. Simply click the Codeium button in the bottom right to access it.

::::::::::::::::::::::::::::::::::::: challenge

## Autocomplete Exploration (10 min)

Familiarize yourself with Codeium's autocomplete feature by practicing coding tasks. Create the function `analyze_co2_trends()` that processes the CO2 data in `weekly_in_situ_co2_mlo.csv` to calculate monthly average CO2 concentrations and visualizes the trend over time. The function should:
Familiarize yourself with Codeium's Autocomplete feature by practicing coding tasks. Create the function `analyze_co2_trends()` that processes the CO2 data in `weekly_in_situ_co2_mlo.csv` to calculate monthly average CO2 concentrations and visualizes the trend over time. The function should:

- Accept the dataframe as an argument.
- Convert the `date` column to a datetime format.
Expand All @@ -104,11 +104,11 @@ Familiarize yourself with Codeium's autocomplete feature by practicing coding ta
- Visualize the trends over time in a well-formatted plot.
- Return the monthly averages.

**Note**: While this task can be solved without using autocomplete, it’s important to use Codeium in this exercise to demonstrate how autocomplete can assist with coding. Although using Python is not mandatory, the solution will be provided in Python.
**Note**: While this task can be solved without using Autocomplete, it’s important to use Codeium in this exercise to demonstrate how Autocomplete can assist with coding. Although using Python is not mandatory, the solution will be provided in Python.

1. What are the benefits of using Codeium’s autocomplete feature in this function?
2. What are the potential drawbacks of relying on autocomplete?
3. How can you improve the accuracy of suggestions using autocomplete?
1. What are the benefits of using Codeium’s Autocomplete feature in this function?
2. What are the potential drawbacks of relying on Autocomplete?
3. How can you improve the accuracy of suggestions using Autocomplete?

::::::::::::::::::::::::::::::::::::::::::::::::

Expand Down Expand Up @@ -164,7 +164,7 @@ When you click on `Docstring`, Codeium will automatically generate a docstring a

## Autocomplete Feature for Docstrings

Note that Codeium's autocomplete feature may also suggest docstrings as you type, further assisting in creating well-documented functions without needing to manually write them. This can be particularly useful when you need to create specific wordings and have the freedom to customize documents interactively.
Note that Codeium's Autocomplete feature may also suggest docstrings as you type, further assisting in creating well-documented functions without needing to manually write them. This can be particularly useful when you need to create specific wordings and have the freedom to customize documents interactively.

::::::::::::::::::::::::::::::::::::::::::::::::

Expand Down Expand Up @@ -242,7 +242,7 @@ def analyze_co2_trends(df):

::::::::::::::::::::::::::::::::::::: keypoints

- Codeium's autocomplete boosts coding speed by predicting and completing code based on context, past edits, and current files.
- Codeium's Autocomplete boosts coding speed by predicting and completing code based on context, past edits, and current files.
- Automating repetitive tasks like boilerplate code, repetitive functions, and formatting reduces errors and saves time.
- Fill-in-the-Middle (FIM) improves suggestions by analyzing the code above and below the insertion point.
- Docstring generation via code lenses automates the creation of accurate docstrings in the correct location.
Expand Down
Binary file added episodes/fig/RAG.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/at_mentions.png
olgaminaeva marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/atmentions1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/best practices chat.png
olgaminaeva marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/chat_vscode_where_to_find.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/codeium chat best practices.png
olgaminaeva marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/codeium_command_vscode.mp4
Binary file not shown.
Binary file added episodes/fig/command.webp
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
::::::::::::::::::::::::::::::::::::::::::::::::

## Introduction ##

Artificial intelligence (AI) models for coding assistants, such as Codeium and GitHub Copilot, rely on machine learning (ML) techniques, particularly deep learning and natural language processing (NLP), to assist developers. These models are trained on vast amounts of publicly available code and documentation to understand patterns, syntax, and code logic across various programming languages.
Let’s break down the *key characteristics* of how these models work:

Expand All @@ -39,7 +40,7 @@

| | **GitHub Copilot** | **Codeium** | **Amazon CodeWhisperer / Amazon Q Developer** | **Tabnine** | **Hugging Chat** |
|------------|-----------|-----------------|-----------------|-------------------|------------------|
| | ![](episodes/fig/github copilot logo.png) | ![](episodes/fig/codeium_logo.png) | ![](episodes/fig/amazon Q developer logo.png) | ![](episodes/fig/Tabnine-AI logo.png) | ![](episodes/fig/hugging chat logo.webp) |

Check warning on line 43 in episodes/introduction-ai-coding.md

View workflow job for this annotation

GitHub Actions / Build markdown source files if valid

[image missing alt-text]: episodes/fig/codeium_logo.png
| **Brief Introduction** | AI coding assistant developed in collaboration with OpenAI, suggests code as you type within the IDE | AI coding assistant that provides code completions and refactoring suggestions | AI assistant from Amazon Web Services, offers real-time code recommendations and integrates into various development environments | AI code completion tool providing accurate, context-aware code suggestions across multiple languages | Leverages open-source models for flexible and customizable AI code assistance |
| **Key Features** | Integration with GitHub ecosystem<br><br> Multilingual support<br><br> Acts as a virtual pair programmer | Advanced code completions<br><br> Code refactoring capabilities<br><br> Supports multiple programming languages | Code recommendations<br><br> Security scans for vulnerabilities<br><br> Real-time documentation assistance<br><br> Multilingual support | Robust autocompletion<br><br> Learns from codebase to suggest relevant snippets and APIs<br><br> Extensive language support | Open-source model integration<br><br> High flexibility in deployment<br><br> Supports diverse coding environments |
| **Pricing** | Free for verified students (via GitHub Student Pack)<br><br> Monthly subscription fee, often with a free trial month | Free version with basic features<br><br> Paid version for full access to advanced features and higher usage limits | Free tier with basic features<br><br> Paid tiers with additional features, higher usage limits, and advanced support | Free version with limited features<br><br> Pro version subscription-based, available monthly or yearly<br><br> Discounts for team licenses | Free access to open-source models<br><br> Paid options for advanced support and additional features |
Expand All @@ -58,7 +59,7 @@

4. Install Codeium: Type Codeium in the marketplace search bar, open up the page and click the blue Install button.

![](episodes/fig/install_extension.png)

Check warning on line 62 in episodes/introduction-ai-coding.md

View workflow job for this annotation

GitHub Actions / Build markdown source files if valid

[image missing alt-text]: episodes/fig/install_extension.png

5. Authorize: After installation is complete, you should be prompted by Visual Studio Code with a pop-up on the bottom right to authorize Codeium.
*If not, you should see an option to sign in to your Codeium account in the bottom left Accounts tab of your Visual Studio Code window.*
Expand All @@ -72,8 +73,6 @@

8. All Done! You will be asked to confirm the authentication in Visual Studio Code (click Open in the resulting pop-up).



### Using Codeium as your Coding Assistant ###

In this lesson, we will learn about the three ways Codeium can assist with coding: *Autocomplete*, *Chat*, and *Command*.
Expand All @@ -84,8 +83,6 @@

**Command:** With Command, you can tell Codeium what changes you want to make to your code in plain language. Codeium will then suggest the changes, which you can choose to accept, reject, or adjust as needed.



::::::::::::::::::::::::::::::::::::: keypoints

- AI coding assistants work by combining ML, contextual code understanding, and NLP to help developers code faster and more efficiently.
Expand Down
Loading