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

Implemented a AI function to enhance the time and space efficiency of… #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Himanshutomar31
Copy link

@Himanshutomar31 Himanshutomar31 commented Apr 26, 2023

Hello Torantulino, I have made some code changes that add a function capable of optimizing the time and space complexity of an existing function using GPT models. Can you please review the changes and merge them if you find them acceptable?

"In this example, I have provided two implementations to calculate the square of a number. The first implementation is an unoptimized code that uses a while loop to repeatedly add the number to itself. The second implementation is the result generated by the GPT model, which simply returns the square of the input using the power operator."
def calculate_square(x):
"""
This function returns the square of its input.
"""
n = x
res = 0
while n > 0:
res += x
n -= 1
return res

to

def calculate_square(x):
return x**2

@Himanshutomar31
Copy link
Author

Hi @Torantulino, Can you please review the changes and merge them if you find them acceptable? Thanks

Copy link
Owner

@Torantulino Torantulino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this is an interesting one!

It's a cool idea but a little different from the initial idea of AI Functions, and it executes completley unknown and unseen code without allowing the user to review it - which is pretty risky.

@Torantulino
Copy link
Owner

Also, could you not just use AI Functions as they currently exist for this?:

args = ["""n = x
res = 0
while n > 0:
res += x
n -= 1
return res"""]
description_string = """Returns a refactored version of the given code, optimised in time and space complexity."""

result = ai_functions.ai_function(function_string, args, description_string, model)

I would expect this to output return x**2, but I've not tested it yet.

@Himanshutomar31
Copy link
Author

Hmm this is an interesting one!

It's a cool idea but a little different from the initial idea of AI Functions, and it executes completely unknown and unseen code without allowing the user to review it - which is pretty risky.

Thank you very much for the review. Although it carries some risk, in our situation, it proves beneficial because if you were to provide these functions as a pip package in the future, it would enable developers to promptly verify optimized code. While it may not produce the exact output a developer anticipates, it certainly offers some insight into areas for improvement.

@Himanshutomar31
Copy link
Author

Himanshutomar31 commented May 23, 2023

not just use AI Functions as they currently exist for this?:

args = ["""n = x
res = 0
while n > 0:
res += x
n -= 1
return res"""], 
description_string = """Returns a refactored version of the given code, optimised in time and space complexity."""

result = ai_functions.ai_function(function_string, args, description_string, model)

I would expect this to output return x**2, but I've not tested it yet.

Yes, you are correct; I could have directly used the AI function. However, I assumed that you would be creating additional functions like this. Yes, the output is return x**2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants