What's new

Prompt Engineering

stepalibre

Alibre Super User
I made tools to debug and build with OpenAI APIs. GAI is a blackbox it's hard to understand what's going on.

1700527112746.png
1700527746941.png
 

stepalibre

Alibre Super User
In discussions about using Alibre API and GenAI, I explained how simplifying the input/prompt can help improve results. Now I’ll give more information for the record.

Using source code as input can be expensive and take longer as the chat/request data increase and the API can throttle. It can also confuse the GenAI with unnecessary information. Reducing complexity, token count and calls to the API is preferred to save time and money. As I learn more about GenAI I find that you must try everything, even ideas that might seem pointless. My approach is to think in terms of simple input and output.

This is a technique I use to understand how GenAI works to get the result I want. I create a custom file/data format or structure that represents my data (this can be anything), use GenAI to process it, and then do more work locally. The file can be converted to another format or type, such as C# code, in this example. You can use the file to generate code for AlibreX and Alibre Script. For example, Class-> a.b.c could translate to AlibreScript.API.Part to generate Python or C# code.

Custom format
Code:
Class->a.b.c
Property->p0
Property->p1
Property->p2
Method->m0(a t0)
Method->m1(b1 t1, b2 t1)
Method->m2(c1 t2, c2 t2, c3 t2)
Method->m3(d1 t3, d2 t2, d3 t2, d4 t2)
Method->m4(e1 t4, e2 t2, e3 t2, e4 t2, e5 t2)
Method->m5(String a0, Double a1, Int32 a2, Double a3, Double a4, Boolean a5, Double a6, Double a7, Int32 a8, a9 b0)

Generated C# from the custom format with dummy data
C#:
class Program
{
    static void Main(string[] args)
    {
        // Create an instance of the 'c' class
        c instance = new c();
        // Create dummy instances of the required types for method arguments
        t0 argT0 = new t0();
        t1 argT1 = new t1();
        t2 argT2 = new t2();
        t3 argT3 = new t3();
        t4 argT4 = new t4();
        b0 argB0 = new b0();
        // Call the methods of the 'c' class with the dummy instances
        instance.m0(argT0);
        instance.m1(argT1, argT1);
        instance.m2(argT2, argT2, argT2);
        instance.m3(argT3, argT2, argT2, argT2);
        instance.m4(argT4, argT2, argT2, argT2, argT2);
        // Call the method with a mix of types and literals
        instance.m5("example", 1.0, 2, 3.0, 4.0, true, 5.0, 6.0, 7, argB0);
        // Access and possibly modify the properties of the 'c' class
        t0 propertyT0 = instance.p0;
        t1 propertyT1 = instance.p1;
        t2 propertyT2 = instance.p2;
        // Modify the properties if needed
        instance.p0 = new t0();
        instance.p1 = new t1();
        instance.p2 = new t2();
        // Output to indicate the methods have been called
        Console.WriteLine("Methods of class 'c' have been called with dummy arguments.");
    }
}
namespace a.b
{
    // Dummy types as placeholders for t0, t1, t2, etc.
    public class t0 { /* Dummy class implementation */ }
    public class t1 { /* Dummy class implementation */ }
    public class t2 { /* Dummy class implementation */ }
    public class t3 { /* Dummy class implementation */ }
    public class t4 { /* Dummy class implementation */ }
    public class b0 { /* Dummy class implementation */ }

    public class c
    {
        // Properties
        public t0 p0 { get; set; }
        public t1 p1 { get; set; }
        public t2 p2 { get; set; }
        // Method implementations
        public void m0(t0 a) { /* Method implementation */ }
        public void m1(t1 b1, t1 b2) { /* Method implementation */ }
        public void m2(t2 c1, t2 c2, t2 c3) { /* Method implementation */ }
        public void m3(t3 d1, t2 d2, t2 d3, t2 d4) { /* Method implementation */ }
        public void m4(t4 e1, t2 e2, t2 e3, t2 e4, t2 e5) { /* Method implementation */ }
        public void m5(string a0, double a1, int a2, double a3, double a4, bool a5, double a6, double a7, int a8, b0 a9)
        {
            /* Method implementation */
        }
        // Constructor
        public c()
        {
            // Initialize properties with default values
            p0 = new t0();
            p1 = new t1();
            p2 = new t2();
        }
    }
}

Chatting with the custom format

1700571163255.png

Here is another example where I use a custom format for GenAI:

 

stepalibre

Alibre Super User
And finally, here are some examples showing how I use custom formats and API outlines to make stub/mock APIs and wrapper libraries. Prompting with a simple structure is much better and is easier to understand.
Code:
Type->AlibreScript.API.Edge
Property->_Edge
Property->Name
Property->Diameter
Property->Length
Property->Vertices
Method->GetPart()
Method->GetVertices()
Method->FilletableObject()
Method->ChamferableObject()
Method->AxisObject()
Method->PathObject()
Method->ConstraintObject()
Method->SelectableObject()
Method->GetSelectionAssembly()
Method->SetOccurrence(IADOccurrence Occurrence)
Method->GetOccurrence()
Method->SetParentAssembly(Assembly ParentAssembly)
Method->GetParentAssembly()
Field->_SelectionSession-Type->IADSession
Field->_Session-Type->IADSession
Python:
class Edge:
    def __init__(self):
        self._Edge = None
        self.Name = None
        self.Diameter = None
        self.Length = None
        self.Vertices = None
    def GetPart(self):
        pass
    def GetVertices(self):
        pass
    def FilletableObject(self):
        pass
    def ChamferableObject(self):
        pass
    def AxisObject(self):
        pass
    def PathObject(self):
        pass
    def ConstraintObject(self):
        pass
    def SelectableObject(self):
        pass
    def GetSelectionAssembly(self):
        pass
    def SetOccurrence(self, Occurrence):
        pass
    def GetOccurrence(self):
        pass
    def SetParentAssembly(self, ParentAssembly):
        pass
    def GetParentAssembly(self):
        pass
class SelectionSession:
    def __init__(self):
        self._SelectionSession = None
        self._Session = None
class Session:
    def __init__(self):
        self._Session = None
C#:
using System;
namespace AlibreScript.API
{
    public class Edge
    {
        public string _Edge { get; set; }
        public string Name { get; set; }
        public string Diameter { get; set; }
        public string Length { get; set; }
        public string Vertices { get; set; }
        public void GetPart()
        {
            // Implement GetPart method logic here
        }
        public void GetVertices()
        {
            // Implement GetVertices method logic here
        }
        public void FilletableObject()
        {
            // Implement FilletableObject method logic here
        }
        public void ChamferableObject()
        {
            // Implement ChamferableObject method logic here
        }
        public void AxisObject()
        {
            // Implement AxisObject method logic here
        }
        public void PathObject()
        {
            // Implement PathObject method logic here
        }
        public void ConstraintObject()
        {
            // Implement ConstraintObject method logic here
        }
        public void SelectableObject()
        {
            // Implement SelectableObject method logic here
        }
        public void GetSelectionAssembly()
        {
            // Implement GetSelectionAssembly method logic here
        }
        public void SetOccurrence(IADOccurrence Occurrence)
        {
            // Implement SetOccurrence method logic here
        }
        public IADOccurrence GetOccurrence()
        {
            // Implement GetOccurrence method logic here
            return null; // Replace with actual return value
        }
        public void SetParentAssembly(Assembly ParentAssembly)
        {
            // Implement SetParentAssembly method logic here
        }
        public Assembly GetParentAssembly()
        {
            // Implement GetParentAssembly method logic here
            return null; // Replace with actual return value
        }
    }
    public class SelectionSession
    {
        public IADSession _SelectionSession { get; set; }
        public IADSession _Session { get; set; }
    }
    public interface IADOccurrence
    {
        // Define the IADOccurrence interface members here
    }
    public interface IADSession
    {
        // Define the IADSession interface members here
    }
    public class Assembly
    {
        // Define the Assembly class members here
    }
}
Code:
Namespace AlibreScript.API
    Public Class Edge
        Public Property _Edge As String
        Public Property Name As String
        Public Property Diameter As String
        Public Property Length As String
        Public Property Vertices As String
        Public Sub GetPart()
            ' Implement GetPart method logic here
        End Sub
        Public Sub GetVertices()
            ' Implement GetVertices method logic here
        End Sub
        Public Sub FilletableObject()
            ' Implement FilletableObject method logic here
        End Sub
        Public Sub ChamferableObject()
            ' Implement ChamferableObject method logic here
        End Sub
        Public Sub AxisObject()
            ' Implement AxisObject method logic here
        End Sub
        Public Sub PathObject()
            ' Implement PathObject method logic here
        End Sub
        Public Sub ConstraintObject()
            ' Implement ConstraintObject method logic here
        End Sub
        Public Sub SelectableObject()
            ' Implement SelectableObject method logic here
        End Sub
        Public Sub GetSelectionAssembly()
            ' Implement GetSelectionAssembly method logic here
        End Sub
        Public Sub SetOccurrence(Occurrence As IADOccurrence)
            ' Implement SetOccurrence method logic here
        End Sub
        Public Function GetOccurrence() As IADOccurrence
            ' Implement GetOccurrence method logic here
            Return Nothing ' Replace with actual return value
        End Function

        Public Sub SetParentAssembly(ParentAssembly As Assembly)
            ' Implement SetParentAssembly method logic here
        End Sub
        Public Function GetParentAssembly() As Assembly
            ' Implement GetParentAssembly method logic here
            Return Nothing ' Replace with actual return value
        End Function
    End Class
    Public Class SelectionSession
        Public Property _SelectionSession As IADSession
        Public Property _Session As IADSession
    End Class
    Public Interface IADOccurrence
        ' Define the IADOccurrence interface members here
    End Interface
    Public Interface IADSession
        ' Define the IADSession interface members here
    End Interface
    Public Class Assembly
        ' Define the Assembly class members here
    End Class
End Namespace
Code:
namespace AlibreScript.API
type Edge() =
    let mutable _Edge = ""
    let mutable Name = ""
    let mutable Diameter = ""
    let mutable Length = ""
    let mutable Vertices = ""
    member this.GetPart() =
        // Implement GetPart method logic here
    member this.GetVertices() =
        // Implement GetVertices method logic here
    member this.FilletableObject() =
        // Implement FilletableObject method logic here
    member this.ChamferableObject() =
        // Implement ChamferableObject method logic here
    member this.AxisObject() =
        // Implement AxisObject method logic here
    member this.PathObject() =
        // Implement PathObject method logic here
    member this.ConstraintObject() =
        // Implement ConstraintObject method logic here
    member this.SelectableObject() =
        // Implement SelectableObject method logic here
    member this.GetSelectionAssembly() =
        // Implement GetSelectionAssembly method logic here
    member this.SetOccurrence(Occurrence : IADOccurrence) =
        // Implement SetOccurrence method logic here
    member this.GetOccurrence() : IADOccurrence =
        // Implement GetOccurrence method logic here
        null // Replace with actual return value
    member this.SetParentAssembly(ParentAssembly : Assembly) =
        // Implement SetParentAssembly method logic here
    member this.GetParentAssembly() : Assembly =
        // Implement GetParentAssembly method logic here
        null // Replace with actual return value
type SelectionSession() =
    let mutable _SelectionSession = null
    let mutable _Session = null
type IADOccurrence =
    // Define the IADOccurrence type members here
type IADSession =
    // Define the IADSession type members here
type Assembly =
    // Define the Assembly type members here
 
Top