ChatGPT for Software Development

Has anyone had any luck with using ChatGPT to create RhinoCommon code?

ChatGPT is a language model trained to generate human-like text based on the input it receives. While it is designed to assist with natural language tasks such as conversation and text generation, it is not suitable for use in coding. This is because ChatGPT has not been trained on code and does not have the knowledge or understanding of programming languages and syntax required to produce correct and functional code. Using ChatGPT for coding could result in errors, bugs, and potentially even security vulnerabilities in the resulting code. It is important to use specialized tools and resources for coding tasks, rather than relying on a general-purpose language model like ChatGPT

(generated in ChatGPT) :wink:

4 Likes

Even natural language can be syntactically and grammatically correct, and still be complete fabrication :wink:

2 Likes

For software development it can be useful to comment our own code, or to organice files, or as a search engine, and probably as well, to generate code that must to be reviewed. But specific problems requires specific knowledge, so lets wait for the childrens of this open source NLP models. :rocket:

And now it starts to make sense to shift from the clicking user experience paradigm, to a voice commands UX paradigm, like some sort of chat with the app. No just using specific languages (as the Rhno API or the UI) but using generic interfaces as your own language. So this is awesome IMO in Rhino for new creators and less technical workflows. Quicker to do almost anything but harder to go technically deep. So more fun and less headache! NLP models can manage quite complex problem contexts, and 3d modelling processes can be represented using a language interface as well, because each operation has a meaning and a symbol, and relations between them. So now we are just one training set away from given a mouth and ears to Rhino! :stuck_out_tongue:

i tried to get a recursive search function to generate a sphere, that is tangent to 4 surfaces.

many time the interface broke, not completing the answerā€¦

copy paste from chatGPT:

// Import the necessary RhinoCommon libraries
using Rhino;
using Rhino.Geometry;
using Rhino.DocObjects;
using Rhino.Commands;
using Rhino.Input;
using Rhino.Input.Custom;

namespace MyRhinocommonScripts
{
    public class FindTangentSphere : Command
    {
        public override string EnglishName { get { return "FindTangentSphere"; } }

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Create a new Rhino.Input.Custom.GetObject object to get the four surfaces from the user
            var go = new GetObject();
            go.SetCommandPrompt("Select four nurbs surfaces to find tangent sphere");
            go.GeometryFilter = ObjectType.Surface;
            go.EnablePreSelect(false, true);
            go.GetMultiple(4, 4);
            if (go.CommandResult() != Result.Success)
                return go.CommandResult();

            // Get the four selected surfaces
            var surfaces = new NurbsSurface[4];
            for (int i = 0; i < 4; i++)
            {
                var objRef = go.Object(i);
                surfaces[i] = objRef.Surface();
            }

            // Create a new Rhino

chatgpt is quite astonishing regarding html, css, javascript.
even for vanilla c# to solve some some mathematical riddles i got code that could be compiled without any mistake.

and what is even more crazy - you can chat with the ai to optimize the code ā€¦ can you please use a separate functionā€¦ can you please ā€¦ it has some problems with casing in rhinoscriptsyntax. ;-D

stuff like this is spooky:

question:
can you show a sample rhino phyton code using rhinoscriptsyntax to insert a square of 200 units into the current rhino document. the lower left point should be at x=17, y=32.

result:

import rhinoscriptsyntax as rs

# Define the lower left point of the square
point = [17, 32, 0]

# Define the side length of the square
side = 200

# Create the square using the rs.AddPolyline() method
# and passing in the point, side length, and a boolean indicating
# whether the square should be closed or not
square = rs.AddPolyline([point, [point[0]+side, point[1], point[2]], [point[0]+side, point[1]+side, point[2]], [point[0], point[1]+side, point[2]], point], closed=True)

# Use the rs.ObjectColor() method to set the color of the square
rs.ObjectColor(square, (255, 0, 0))

ask to improve:
can you please calculate the 4 cornerpoints in separate lines of code

result 2

import rhinoscriptsyntax as rs

# Define the lower left point of the square
point = [17, 32, 0]

# Define the side length of the square
side = 200

# Calculate the coordinates of the other three corner points
# by adding the side length to the x or y coordinate of the
# lower left point
point1 = [point[0] + side, point[1], point[2]]
point2 = [point[0] + side, point[1] + side, point[2]]
point3 = [point[0], point[1] + side, point[2]]

# Print the coordinates of the four corner points
print(point)
print(point1)
print(point2)
print(point3)

ask to improve 2
but the points still should be used in the polyline function

result 3

import rhinoscriptsyntax as rs

# Define the lower left point of the square
point = [17, 32, 0]

# Define the side length of the square
side = 200

# Calculate the coordinates of the other three corner points
# by adding the side length to the x or y coordinate of the
# lower left point
point1 = [point[0] + side, point[1], point[2]]
point2 = [point[0] + side, point[1] + side, point[2]]
point3 = [point[0], point[1] + side, point[2]]

# Create the square using the rs.AddPolyline() method
# and passing in the four corner points, and a boolean indicating
# whether the square should be closed or not
square = rs.AddPolyline([point, point1, point2, point3, point], closed=True)

# Use the rs.ObjectColor() method to set the color of the square
rs.ObjectColor(square, (255, 0, 0))

i think its quite crazy

2 Likes

Well, itā€™s also capable of lying to you - or at least not telling you the whole truth. The code doesnā€™t run, because the closed argument doesnā€™t actually exist in rhinoscriptsyntax AddPolyline()ā€¦ (it does in GH though)

Message: AddPolyline() got an unexpected keyword argument 'closed'

Maybe you can tell it that it needs to add the last point at the end (so you have 5 points) and eliminate the closed argument, and it will learnā€¦ :stuck_out_tongue_winking_eye:

yep, but if you paste the error code, the AI will improve the code againā€¦(sorry already closed the chat)

Yeah, I think Iā€™m going to quit scripting now. Also Iā€™m going to quit making images, because Dall-e can do much better than I can already. What am I going to do with all my time?

One of these days Iā€™m gonna need to get me one of them robots that can communicate with AI and set them to restoring my vintage car in the garageā€¦ For the moment the only advantage I have over AI is that I can hold a wrench.

7 Likes

pasting the code again and ask for help:

1 Like

rs.AddPolylinePoint() ? Hey, thatā€™s a new one on me! Cool that it can invent rhinoscriptsyntax functions that donā€™t exist (yet).
:stuck_out_tongue_winking_eye:

Back in the last century a lot of work was put into developing programming systems that allowed code to be mathematically proved to be correct.

Unfortunately the humans who specified what the code was to do were not amenable to the same proof of correctness.

So for now gigo - garbage in, garbage out - still holds, but it looks like AI is starting to help polish the garbage.

language model trained to generate human-like text :face_with_symbols_over_mouth:

I got the exact same feelingā€¦This feels like such a game changer. Only hope is that a) the gains of this leap do not end up with a happy few and b) that we find a way to spend all that time purposefullyā€¦

I asked ChatGPT for some simple code for drawing a circle using RhinoCommon and already learned a new, elegant way to do it. Amazing that the algo even adds comments to explainā€¦

1 Like

If you are stuck and you are looking for a concept to coding/scripting problem, ChatGPT may give you some idea and point you to some direction. However it is your responsibility to understand, validate and make code fit your needs.

There is already a lot of garbage code over the web, which is used currently to train AI.

AI also will not solve complex structural problems of project code. Not yetā€¦ if ever.

1 Like

I would say that ChatGPT is not the answer to all our solutions but a big support. Here an example of how I translated the solution given from ChatGPT to RhinoCommon (ConvexHull algorithm).

2 Likes

I dabbled with this too recently. I asked it to write a function that generates a model of the One World Trade Center tower, and Iā€™m both impressed and disappointed.

:white_check_mark: It understands what the One World Trade Center looks like and manages to translate this into geometry.
:white_check_mark: It understands (ish) RhinoCommon, and how to use the C# API to achieve its goal.
:x: The final geometric output isnā€™t super impressive.

I wrote a bit more about this experiment on my blog in case anyoneā€™s interested: ChatGPT and RhinoCommon ā€“ emil poulsen

I hope McNeelā€™s programmers are not going to squander resourcesā€“trying to lay the very first bricks for their eventual replacement.

I personally find it a great tool, you just need to learn what it can do good and how to ask for help. If you think about the fact that this chatbot is based on machine learning, then itā€™s obvious that it requires an incredible amount of training data. The more (useful) training data it has on a specific problem, the better the answers. Of course, it can connect the dots, which is actually the more impressive ā€œfeatureā€. However, you should not expect that it does the work for you. It can really help to give you an entry point to a specific problem. Letā€™s say you are new to Rhinocommon or for some reason you donā€™t understand or find the official documentation on how to use it. By asking for such example, you already get a clue on how to script shapes with it. If you refine your questions with this in mind, you can really benefit from ChatGPT. For me itā€™s a great helper in Matlab scripting.

2 Likes

@TomTom Agreed! Have you made any experiments with ChatGPT + RhinoCommon?