Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Options

Using AI for FS generation.. and failing

fnxffnxf Member, User Group Leader Posts: 137 PRO
edited February 2023 in FeatureScript
So yes, I'm no coder, but have been prompting ChatGPT to see if it can write me some code. I find the conversational style very engaging.
Here's my current non-working result:

https://cad.onshape.com/documents/ae1931dd79abf7662aea410a/w/7528de4b57e62d87e25e4f0c/e/aa2e0934fc6a93830a0bf384
FeatureScript 1963;
import(path : "onshape/std/geometry.fs", version : "1963.0");
import(path : "onshape/std/common.fs", version : "1963.0");

annotation { "Feature Type Name" : "Zugdreieck" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Base Curve", "Filter" : EntityType.EDGE_OR_SKETCH_CURVE }
        definition.baseCurve is Query;

        annotation { "Name" : "Extrude Height" }
        definition.extrudeHeight is value with unitType(distance);
    }
    {
        // Get the curve from the query
        const curve = definition.baseCurve;
        var curveGeometry;
        if (isEdge(curve))
        {
            curveGeometry = evEdgeGeometry(context, {"edge" : curve});
        }
        else if (isSketchCurve(curve))
        {
            curveGeometry = evSketchCurveGeometry(context, {"sketchCurve" : curve});
        }
        else
        {
            throw regenError("The selected entity is not a valid curve");
        }

        // Get the length of the curve
        const b = length(curveGeometry);

        // Define the variables needed for the formula
        const h = definition.extrudeHeight.getValue() / 2.0;
        const l = sqrt(b * b / 2.0);

        // Create a sketch on the plane of the curve
        const sketch1 = newSketchOnPlane(context, id + "sketch1", {
            "sketchPlane" : evPlane(context, {"curve" : curve})
        });

        // Draw the three lines using the formula
        const line1 = sketch1.lineTo(point(b, 0));
        const line2 = sketch1.lineTo(point(b / 2.0, l));
        const line3 = sketch1.lineTo(point(0, 0));

        // Close the sketch
        sketch1.closePath();

        // Extrude the sketch
        const extrude1 = newLinearExtrude(context, id + "extrude1", {
            "entities" : sketch1.id,
            "direction" : vector(0, 0, 1),
            "distance" : definition.extrudeHeight
        });

        // Return the extruded solid
        return extrude1;
    });
Apparently there's an issue on line 13.. And I got the AI stumped as well ;-) because it keeps presenting "solutions" which give more errors ..
This was fun, and I wanted to share that :)

Comments

  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,391
    It's not bad, but it's making up functions as it goes along...
    Senior Director, Technical Services, EMEAI
  • Options
    Urs_Egger_REACTUrs_Egger_REACT Member Posts: 54 PRO
    That's a great idea. Seems like I should dive into this AI coding stuff
  • Options
    billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    edited February 2023
    Could you ask it to finish your project while out eating lunch?  B)
  • Options
    S1monS1mon Member Posts: 2,365 PRO
    Yeah, I tried this earlier, but found that ChatGPT doesn't seem to know much about Featurescript. I would love to have some help from a tool which ingested all the public Featurescripts and documentation. I'm sure it would make some weird mistakes and blatantly make stuff up, but it continues to be amazing how it can be successful in some contexts.
  • Options
    billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    edited February 2023


    There's a node module for talking to chatgpt. It wouldn't be hard to stuff it full of feature scripts. 

    I guess someone should ask OS 1st & then how would you do it?

    Is it "hey you this is a feature script" and then list the script in the dialog?


  • Options
    fnxffnxf Member, User Group Leader Posts: 137 PRO
    billy2 said:
    Could you ask it to finish your project while out eating lunch?  B)
    I will try that next time! But see what kind of prompts I was using, and now imagine that instead of just making things up, as @NeilCooke noticed, it would actually know FS?







  • Options
    billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,014 PRO
    Ok, the api is now available. 




    chatgpt api

    Are there any other Node guys out there?


  • Options
    baumarbaumar OS Professional Posts: 76 PRO
    edited February 29
    I also did a short try with ChatGPT and it's indeed very disappointing. I guess that's because the model has not access to programs and sources, as for other programming languages like Java the support is great. I really hope this will improve because AI will be daily help for programming as Google is now. Is there a page to follow the progress of AI integration (if it exists at all)?
    PS If you want to see what AI support can do you may want to check intellij's AI support (https://www.jetbrains.com/help/idea/ai-assistant.html). It is not perfect and it does not code while you sleep, but it's boosting development amazingly. For questions I searched the web for hours it gives hints within a few seconds. I think that would be a good benchmark to reach...
  • Options
    Caden_Armstrong_Caden_Armstrong_ Member Posts: 22 PRO
    Chat GPT isn't going to give any useful features because it doesn't have any training data (documentation doesn't count),

    Creating an AI that can create a feature is more than just funneling featurescript into it. Doing that might produce code that doesn't have syntax errors, but going from a prompt to useable output requires labelled data. Someone needs to produce a dataset that has both featurescript and metadata describing that featurescript. Without labelled data, the prompt will just give a mish mash of random featurescript. Theres multiple layers of translation from text prompt to code to 3d model. AI isn't magic, behind a useful AI is an army of people creating training data to produce results. For languages like javascript, theres a mountain of user forums where someone asks "how do I do X in javascript", and the top answer is a single isolated line of code that does it. That doesn't exist for FeatureScript, someone would have to intentionally make that dataset. 

    Until then, if you want an easier way of producing a feature, hire a professional. You'll get better results, and I'm definitely faster than messing with chat gpt.
    www.smartbenchsoftware.com
    Custom FeatureScript and Onshape Integrated Applications
Sign In or Register to comment.