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

/generate sometimes splits classes and functions across multiple cells #1111

Open
Nikhil-Fulzele opened this issue Nov 17, 2024 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Nikhil-Fulzele
Copy link

Description

Code produce by /generate command splits the class/methods into multiple cells.

Please find below few screenshots for the referrence
Screenshot 2567-11-17 at 12 30 35
Screenshot 2567-11-17 at 12 31 24
Screenshot 2567-11-17 at 12 31 04

Reproduce

  1. Select openai-chat:gpt-4o-mini model from settings (i tried gpt-3.5 turbo as well)
  2. Select chat interface and write /generate create calculator
  3. Open the generated Notebook

Expected behavior

Model should not split class and methods into multiple cells. This make the notebook error purne.

Context

  • Operating System and version: Linux Ubuntu 22.04
  • Browser and version: Chrome 92 130.0.6723.117
  • JupyterLab version: 4.1.3
  • JupyterAI version: 2.25.0
  • JupyterServer version: 2.15.0
  • LLM Model used: openai-chat:gpt-4o-mini
Troubleshoot Output
Paste the output from running `jupyter troubleshoot` from the command line here.
You may want to sanitize the paths in the output.
Command Line Output
usage: jupyter-lab [-h]
jupyter-lab: error: unrecognized arguments: create calculator
[I 2024-11-17 12:22:00.772 AiExtension] Switching chat language model from None to openai-chat:gpt-4o-mini.
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
INFO:httpx:HTTP Request: POST https://openai_endpoint/v1/chat/completions "HTTP/1.1 200 OK"
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
INFO:httpx:HTTP Request: POST https://openai_endpoint/v1/chat/completions "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST https://openai_endpoint/v1/chat/completions "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST https://openai_endpoint/v1/chat/completions "HTTP/1.1 200 OK"
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
Prompt after formatting:
You are an AI that creates a detailed content outline for a Jupyter notebook on a given topic.
The output should be formatted as a JSON instance that conforms to the JSON schema below.
As an example, for the schema {"properties": {"foo": {"title": "Foo", "description": "a list of strings", "type": "array", "items": {"type": "string"}}}, "required": ["foo"]}
the object {"foo": ["bar", "baz"]} is a well-formatted instance of the schema. The object {"properties": {"foo": ["bar", "baz"]}} is not well-formatted.
Here is the output schema:
```
{"properties": {"description": {"title": "Description", "type": "string"}, "sections": {"title": "Sections", "type": "array", "items": {"$ref": "#/definitions/OutlineSection"}}}, "required": ["sections"], "definitions": {"OutlineSection": {"title": "OutlineSection", "type": "object", "properties": {"title": {"title": "Title", "type": "string"}, "content": {"title": "Content", "type": "string"}}, "required": ["title", "content"]}}}
```
Here is a description of the notebook you will create an outline for: /generate create calculator
Don't include an introduction or conclusion section in the outline, focus only on description and sections that will need code.

Finished chain.
Prompt after formatting:
Create a short, few word, descriptive title for a Jupyter notebook with the following content.
Content:
{'description': 'A Jupyter notebook that demonstrates how to create a simple calculator application using Python. It will cover basic functionalities like addition, subtraction, multiplication, and division, along with error handling and user input.', 'sections': [{'title': 'Setup', 'content': 'Import necessary libraries and set up the environment for the calculator.'}, {'title': 'Basic Operations', 'content': 'Define functions for addition, subtraction, multiplication, and division.'}, {'title': 'User Input', 'content': 'Implement a function to take user input for the numbers and the operation they wish to perform.'}, {'title': 'Error Handling', 'content': 'Add error handling to manage invalid inputs and division by zero.'}, {'title': 'Calculator Loop', 'content': 'Create a loop that allows the user to perform multiple calculations until they choose to exit.'}, {'title': 'Testing the Calculator', 'content': 'Write test cases to validate the functionality of the calculator.'}], 'prompt': '/generate create calculator'}
Don't return anything other than the title.
Prompt after formatting:
Create a markdown summary for a Jupyter notebook with the following content. The summary should consist of a single paragraph.
Content:
{'description': 'A Jupyter notebook that demonstrates how to create a simple calculator application using Python. It will cover basic functionalities like addition, subtraction, multiplication, and division, along with error handling and user input.', 'sections': [{'title': 'Setup', 'content': 'Import necessary libraries and set up the environment for the calculator.'}, {'title': 'Basic Operations', 'content': 'Define functions for addition, subtraction, multiplication, and division.'}, {'title': 'User Input', 'content': 'Implement a function to take user input for the numbers and the operation they wish to perform.'}, {'title': 'Error Handling', 'content': 'Add error handling to manage invalid inputs and division by zero.'}, {'title': 'Calculator Loop', 'content': 'Create a loop that allows the user to perform multiple calculations until they choose to exit.'}, {'title': 'Testing the Calculator', 'content': 'Write test cases to validate the functionality of the calculator.'}], 'prompt': '/generate create calculator'}
Prompt after formatting:
You are an AI that writes code for a single section of a Jupyter notebook.
Overall topic of the notebook: A Jupyter notebook that demonstrates how to create a simple calculator application using Python. It will cover basic functionalities like addition, subtraction, multiplication, and division, along with error handling and user input.
Title of the notebook section: Setup
Description of the notebok section: Import necessary libraries and set up the environment for the calculator.
Given this information, write all the code for this section and this section only. Your output should be valid code with inline comments.

Prompt after formatting:
You are an AI that writes code for a single section of a Jupyter notebook.
Overall topic of the notebook: A Jupyter notebook that demonstrates how to create a simple calculator application using Python. It will cover basic functionalities like addition, subtraction, multiplication, and division, along with error handling and user input.
Title of the notebook section: Basic Operations
Description of the notebok section: Define functions for addition, subtraction, multiplication, and division.
Given this information, write all the code for this section and this section only. Your output should be valid code with inline comments.

Prompt after formatting:
You are an AI that writes code for a single section of a Jupyter notebook.
Overall topic of the notebook: A Jupyter notebook that demonstrates how to create a simple calculator application using Python. It will cover basic functionalities like addition, subtraction, multiplication, and division, along with error handling and user input.
Title of the notebook section: User Input
Description of the notebok section: Implement a function to take user input for the numbers and the operation they wish to perform.
Given this information, write all the code for this section and this section only. Your output should be valid code with inline comments.

Prompt after formatting:
You are an AI that writes code for a single section of a Jupyter notebook.
Overall topic of the notebook: A Jupyter notebook that demonstrates how to create a simple calculator application using Python. It will cover basic functionalities like addition, subtraction, multiplication, and division, along with error handling and user input.
Title of the notebook section: Error Handling
Description of the notebok section: Add error handling to manage invalid inputs and division by zero.
Given this information, write all the code for this section and this section only. Your output should be valid code with inline comments.

Prompt after formatting:
You are an AI that writes code for a single section of a Jupyter notebook.
Overall topic of the notebook: A Jupyter notebook that demonstrates how to create a simple calculator application using Python. It will cover basic functionalities like addition, subtraction, multiplication, and division, along with error handling and user input.
Title of the notebook section: Calculator Loop
Description of the notebok section: Create a loop that allows the user to perform multiple calculations until they choose to exit.
Given this information, write all the code for this section and this section only. Your output should be valid code with inline comments.

Prompt after formatting:
You are an AI that writes code for a single section of a Jupyter notebook.
Overall topic of the notebook: A Jupyter notebook that demonstrates how to create a simple calculator application using Python. It will cover basic functionalities like addition, subtraction, multiplication, and division, along with error handling and user input.
Title of the notebook section: Testing the Calculator
Description of the notebok section: Write test cases to validate the functionality of the calculator.
Given this information, write all the code for this section and this section only. Your output should be valid code with inline comments.

Finished chain.
Finished chain.
Finished chain.
INFO:httpx:HTTP Request: POST https://openai_endpoint/v1/chat/completions "HTTP/1.1 200 OK"
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
INFO:httpx:HTTP Request: POST https://openai_endpoint/v1/chat/completions "HTTP/1.1 200 OK"
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
INFO:httpx:HTTP Request: POST https://openai_endpoint/v1/chat/completions "HTTP/1.1 200 OK"
INFO:httpx:HTTP Request: POST https://openai_endpoint/v1/chat/completions "HTTP/1.1 200 OK"
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
INFO:httpx:HTTP Request: POST https://openai_endpoint/v1/chat/completions "HTTP/1.1 200 OK"
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
INFO:httpx:HTTP Request: POST https://openai_endpoint/v1/chat/completions "HTTP/1.1 200 OK"
WARNING:langchain_core.callbacks.manager:Error in StdOutCallbackHandler.on_chain_start callback: AttributeError("'NoneType' object has no attribute 'get'")
Prompt after formatting:
Improve the following code and make sure it is valid. Make sure to return the improved code only - don't give an explanation of the improvements.

# Setup Section: Import necessary libraries and set up the environment for the calculator
# Import the required libraries
import sys  # For system-specific parameters and functions
import traceback  # For error handling and debugging
# Function to clear the output (optional, for better user experience)
def clear_output():
"""Clears the output in Jupyter Notebook (not necessary but can improve readability)."""
from IPython.display import clear_output
clear_output(wait=True)
# Display a welcome message
print("Welcome to the Simple Calculator!")
print("This calculator can perform addition, subtraction, multiplication, and division.")
print("Type 'exit' to quit the application.")
# Initialize a flag for the main loop
continue_calculating = True

Finished chain.
Prompt after formatting:
Improve the following code and make sure it is valid. Make sure to return the improved code only - don't give an explanation of the improvements.

# Basic Operations
def add(x, y):
"""Return the sum of x and y."""
return x + y
def subtract(x, y):
"""Return the difference of x and y."""
return x - y
def multiply(x, y):
"""Return the product of x and y."""
return x * y
def divide(x, y):
"""Return the quotient of x and y. Raises an error if dividing by zero."""
if y == 0:
raise ValueError("Cannot divide by zero.")
return x / y
# Example usage (uncomment to test)
# print("Addition (5 + 3):", add(5, 3))
# print("Subtraction (5 - 3):", subtract(5, 3))
# print("Multiplication (5 * 3):", multiply(5, 3))
# print("Division (5 / 3):", divide(5, 3))
# print("Division (5 / 0):", divide(5, 0))  # This will raise an error

Finished chain.
Prompt after formatting:
Improve the following code and make sure it is valid. Make sure to return the improved code only - don't give an explanation of the improvements.

# Section: User Input
def get_user_input():
"""
This function prompts the user for two numbers and the operation they wish to perform.
It returns the numbers and the operation as a tuple.
"""
# Get the first number from the user
while True:
try:
num1 = float(input("Enter the first number: "))  # Convert input to float
break  # Break the loop if input is valid
except ValueError:  # Handle invalid input
print("Invalid input. Please enter a valid number.")
# Get the second number from the user
while True:
try:
num2 = float(input("Enter the second number: "))  # Convert input to float
break  # Break the loop if input is valid
except ValueError:  # Handle invalid input
print("Invalid input. Please enter a valid number.")
# Get the operation from the user
while True:
operation = input("Enter the operation (+, -, *, /): ")  # Prompt for operation
if operation in ['+', '-', '*', '/']:  # Check if it's a valid operation
break  # Break the loop if input is valid
else:
print("Invalid operation. Please enter one of +, -, *, /.")
return num1, num2, operation  # Return the numbers and operation as a tuple

Finished chain.
Finished chain.
Prompt after formatting:
Improve the following code and make sure it is valid. Make sure to return the improved code only - don't give an explanation of the improvements.

# Error Handling Section
def safe_divide(x, y):
"""Performs division and handles division by zero."""
try:
result = x / y
except ZeroDivisionError:
# Handle the division by zero case
return "Error: Division by zero is not allowed."
return result
def get_float_input(prompt):
"""Gets a float input from the user and handles invalid input."""
while True:
try:
value = float(input(prompt))
return value
except ValueError:
# Handle the case where input cannot be converted to float
print("Invalid input. Please enter a numeric value.")
# Example of using the functions with error handling
# Get user input for two numbers
print("Welcome to the Simple Calculator!")
num1 = get_float_input("Enter the first number: ")
num2 = get_float_input("Enter the second number: ")
# Perform calculations with error handling
addition_result = num1 + num2
subtraction_result = num1 - num2
multiplication_result = num1 * num2
division_result = safe_divide(num1, num2)
# Display the results
print(f"Addition: {num1} + {num2} = {addition_result}")
print(f"Subtraction: {num1} - {num2} = {subtraction_result}")
print(f"Multiplication: {num1} * {num2} = {multiplication_result}")
print(f"Division: {num1} / {num2} = {division_result}")

Finished chain.
Prompt after formatting:
Improve the following code and make sure it is valid. Make sure to return the improved code only - don't give an explanation of the improvements.

# Calculator Loop Section
def calculator():
while True:  # Start an infinite loop to allow multiple calculations
print("\nWelcome to the Simple Calculator!")
print("Select operation:")
print("1. Addition (+)")
print("2. Subtraction (-)")
print("3. Multiplication (*)")
print("4. Division (/)")
print("5. Exit")
choice = input("Enter choice (1/2/3/4/5): ")  # User input for operation choice
if choice in ['1', '2', '3', '4']:  # Check if the choice is one of the operations
try:
# Take input for two numbers to perform the calculation
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
except ValueError:
print("Invalid input! Please enter numeric values.")  # Error handling for non-numeric input
continue  # Restart the loop if input is invalid
# Perform the calculation based on user choice
if choice == '1':
result = num1 + num2
operation = "addition"
elif choice == '2':
result = num1 - num2
operation = "subtraction"
elif choice == '3':
result = num1 * num2
operation = "multiplication"
elif choice == '4':
if num2 == 0:
print("Error! Division by zero.")  # Error handling for division by zero
continue
result = num1 / num2
operation = "division"
# Display the result
print(f"The result of the {operation} is: {result}")
elif choice == '5':
print("Exiting the calculator. Goodbye!")  # Exit message
break  # Exit the loop if user chooses to exit
else:
print("Invalid choice! Please select a valid operation.")  # Error handling for invalid operation choice
# Call the calculator function to start the loop
calculator()

Finished chain.

Browser Output
Paste the output from your browser Javascript console here, if applicable.
@Nikhil-Fulzele Nikhil-Fulzele added the bug Something isn't working label Nov 17, 2024
@dlqqq
Copy link
Member

dlqqq commented Nov 18, 2024

@Nikhil-Fulzele Thank you for opening an issue to track this! I've also noticed this occasionally in my personal testing. The error seems less common when using the latest, most capable LLMs from each provider (e.g. gpt-4o instead of gpt-4o-mini).

/generate currently uses the LLMChain class from LangChain, which is now on a deprecation path. Most likely, we'll want to rewrite the implementation as an agentic workflow using the newer LangGraph library.

I'll add this to the v3.0.0 milestone. 👍

@dlqqq dlqqq changed the title Code produce by /generate command splits the class/methods into multiple cells /generate command sometimes splits classes and functions across multiple cells Nov 18, 2024
@dlqqq dlqqq changed the title /generate command sometimes splits classes and functions across multiple cells /generate sometimes splits classes and functions across multiple cells Nov 18, 2024
@dlqqq dlqqq added this to the v3.0.0 milestone Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants