Is it magic?

Daestrum

Expert
Licensed User
Longtime User
I gave a local LLM (Phi-3.5) the following code. (its cut-off data date was well before Erel invented PyBridge)

prompt: Explain this code
B4X:
    ...
    Root = Root1
    Root.LoadLayout("MainPage")
    Py.Initialize(Me, "Py")
    Dim opt As PyOptions = Py.CreateOptions(File.Combine("D:/python.3.12.8","python.exe"))
    Dim scripts As String
    scripts = File.geturi(File.DirAssets,"__init__.py").Replace("file:/","").Replace("\","/").Replace("__init__.py","").Replace("%20"," ")
    opt.EnvironmentVars.Put("script_dir" , scripts)
    opt.EnvironmentVars.Put("HF_HOME" , "D:/.cache")
    opt.PyCacheFolder= "d:/.cache"
    Py.Start(opt)
    Wait For Py_Connected (Success As Boolean)
    If Success = False Then
        LogError("Failed to start Python process.")
        Return
    End If
    TextArea1.As(TextArea).WrapText=True
    TextArea2.As(TextArea).WrapText=True
    TextArea1.TextSize = 20
    TextArea2.TextSize = 20
    ...


This was its reply

The only error I see is it referred to BeeJ on the last line instead of B4J.
 

Daestrum

Expert
Licensed User
Longtime User
And if like me, you are lazy with comments, giving it the same code with the following prompt

prompt: Add comments to this code to explain what it is doing. Comments are in the form ' comment

you get:
Again almost perfect except it added "_" instead of " " in the replace line.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…