Skip to content

Commit

Permalink
Fix error in Basic Code Generation
Browse files Browse the repository at this point in the history
  • Loading branch information
shilpakancharla committed Jun 11, 2024
1 parent dff2174 commit 2644cdd
Showing 1 changed file with 8 additions and 130 deletions.
138 changes: 8 additions & 130 deletions examples/prompting/Basic_Code_Generation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@
},
{
"cell_type": "code",
<<<<<<< HEAD
<<<<<<< HEAD
"execution_count": null,
=======
"execution_count": 1,
>>>>>>> 757cc02 (Update basic code generation)
=======
"execution_count": null,
>>>>>>> 7c65d32 (Update notebook with shorter prompt)
"metadata": {
"cellView": "form",
"id": "vQoUR__bUlfj"
Expand Down Expand Up @@ -74,15 +66,7 @@
},
{
"cell_type": "code",
<<<<<<< HEAD
<<<<<<< HEAD
"execution_count": 1,
=======
"execution_count": 2,
>>>>>>> 757cc02 (Update basic code generation)
=======
"execution_count": 1,
>>>>>>> 7c65d32 (Update notebook with shorter prompt)
"execution_count": null,
"metadata": {
"id": "Ne-3gnXqR0hI"
},
Expand All @@ -93,15 +77,7 @@
},
{
"cell_type": "code",
<<<<<<< HEAD
<<<<<<< HEAD
"execution_count": 2,
=======
"execution_count": 3,
>>>>>>> 757cc02 (Update basic code generation)
=======
"execution_count": 2,
>>>>>>> 7c65d32 (Update notebook with shorter prompt)
"execution_count": null,
"metadata": {
"id": "EconMHePQHGw"
},
Expand All @@ -125,15 +101,7 @@
},
{
"cell_type": "code",
<<<<<<< HEAD
<<<<<<< HEAD
"execution_count": 3,
=======
"execution_count": 4,
>>>>>>> 757cc02 (Update basic code generation)
=======
"execution_count": 3,
>>>>>>> 7c65d32 (Update notebook with shorter prompt)
"execution_count": null,
"metadata": {
"id": "v-JZzORUpVR2"
},
Expand Down Expand Up @@ -165,60 +133,11 @@
},
{
"cell_type": "code",
<<<<<<< HEAD
<<<<<<< HEAD
"execution_count": 4,
=======
"execution_count": 5,
>>>>>>> 757cc02 (Update basic code generation)
=======
"execution_count": 4,
>>>>>>> 7c65d32 (Update notebook with shorter prompt)
"execution_count": null,
"metadata": {
"id": "kVF8ZQ38Vs1P"
},
"outputs": [],
<<<<<<< HEAD
"source": [
"error_handling_system_prompt =f\"\"\"\n",
"Your task is to explain exactly why this error occurred and how to fix it.\n",
"\"\"\"\n",
"error_handling_model = genai.GenerativeModel(model_name='gemini-1.5-flash-latest', generation_config={\"temperature\": 0},\n",
" system_instruction=error_handling_system_prompt)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"id": "CHTdAVE0pIFf"
},
"outputs": [
{
"data": {
"text/markdown": "The error message \"IndexError: list index out of range\" means you're trying to access an element in a list using an index that doesn't exist.\n\n**Explanation:**\n\n* **List Indexing:** In Python, lists are zero-indexed. This means the first element has an index of 0, the second element has an index of 1, and so on.\n* **Your Code:** In your code, `my_list = [1, 2, 3]` has three elements. The valid indices for this list are 0, 1, and 2.\n* **The Error:** You're trying to access `my_list[3]`. Since the list only has three elements, there is no element at index 3. This causes the \"IndexError: list index out of range\" error.\n\n**How to Fix It:**\n\n1. **Check the Index:** Ensure the index you're using is within the valid range of the list. In this case, you should use an index between 0 and 2.\n2. **Adjust the Code:** To access the last element of the list, use `my_list[2]`.\n\n**Corrected Code:**\n\n```python\nmy_list = [1, 2, 3]\nprint(my_list[2]) # This will print 3\n```\n\n**Important Note:** Always be mindful of the size of your lists and the indices you use to avoid this common error. \n",
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"error_message = \"\"\"\n",
" 1 my_list = [1,2,3]\n",
"----> 2 print(my_list[3])\n",
"\n",
"IndexError: list index out of range\n",
"\"\"\"\n",
"\n",
"error_prompt = f\"\"\"\n",
"You've encountered the following error message:\n",
"Error Message: {error_message}\"\"\"\n",
"\n",
=======
"source": [
"error_handling_system_prompt =f\"\"\"\n",
"Your task is to explain exactly why this error occurred and how to fix it.\n",
Expand All @@ -229,7 +148,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"id": "CHTdAVE0pIFf"
},
Expand Down Expand Up @@ -258,7 +177,6 @@
"You've encountered the following error message:\n",
"Error Message: {error_message}\"\"\"\n",
"\n",
>>>>>>> 757cc02 (Update basic code generation)
"Markdown(error_handling_model.generate_content(error_prompt).text)"
]
},
Expand All @@ -273,15 +191,7 @@
},
{
"cell_type": "code",
<<<<<<< HEAD
<<<<<<< HEAD
"execution_count": 6,
=======
"execution_count": 7,
>>>>>>> 757cc02 (Update basic code generation)
=======
"execution_count": 6,
>>>>>>> 7c65d32 (Update notebook with shorter prompt)
"execution_count": null,
"metadata": {
"id": "1T1QSzjVVvE_"
},
Expand All @@ -300,15 +210,7 @@
},
{
"cell_type": "code",
<<<<<<< HEAD
<<<<<<< HEAD
"execution_count": 7,
=======
"execution_count": 8,
>>>>>>> 757cc02 (Update basic code generation)
=======
"execution_count": 7,
>>>>>>> 7c65d32 (Update notebook with shorter prompt)
"execution_count": null,
"metadata": {
"id": "8KVpzExDqRj2"
},
Expand All @@ -320,15 +222,7 @@
"<IPython.core.display.Markdown object>"
]
},
<<<<<<< HEAD
<<<<<<< HEAD
"execution_count": 7,
=======
"execution_count": 8,
>>>>>>> 757cc02 (Update basic code generation)
=======
"execution_count": 7,
>>>>>>> 7c65d32 (Update notebook with shorter prompt)
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -350,15 +244,7 @@
},
{
"cell_type": "code",
<<<<<<< HEAD
<<<<<<< HEAD
"execution_count": 8,
=======
"execution_count": 9,
>>>>>>> 757cc02 (Update basic code generation)
=======
"execution_count": 8,
>>>>>>> 7c65d32 (Update notebook with shorter prompt)
"execution_count": null,
"metadata": {
"id": "lOU_abTPSmZu"
},
Expand Down Expand Up @@ -400,15 +286,7 @@
],
"metadata": {
"colab": {
<<<<<<< HEAD
<<<<<<< HEAD
"name": "Basic_code_generation.ipynb",
=======
"name": "Basic_Code_Generation.ipynb",
>>>>>>> 757cc02 (Update basic code generation)
=======
"name": "Basic_code_generation.ipynb",
>>>>>>> 7c65d32 (Update notebook with shorter prompt)
"toc_visible": true
},
"kernelspec": {
Expand Down

0 comments on commit 2644cdd

Please sign in to comment.