ChatGPT!!!!!

Num3

Active Member
Licensed User
Longtime User
God mode:
"continue generating example where it stopped"

And you can go on forever generating code xD
 

AnandGupta

Expert
Licensed User
Longtime User
Well it went to error / bug message.
firefox_vkQjU4sziu.png

Did I ask too much for AI ?
 

Daestrum

Expert
Licensed User
Longtime User
I wonder if it can write a B4X library wrapper? (I would try to ask it but cba to sign up for it)
 

Daestrum

Expert
Licensed User
Longtime User
Ok I tried it and so far impressed with what it actually produces. (The examples are quite short but shows promise)
1670405413845.png
 

aeric

Expert
Licensed User
Longtime User
Have to train "him" to write correct server code.

AE: Here is my code for Web API server...
CG: It looks like your code is using the B4X Server class to create a web server ...
B4X:
srvr.AddHandler("/hello", "GET", AddressOf Hello)

AE: the third argument in AddHandler is a Boolean variable name SingleThreadHandler
CG: <some BS>

AE: most of the case i will use False for this variable
CG: <more BS>

AE: now build a hello world web api using b4x server
CG: Here is an example of how you can use the B4X Server class to create a simple "Hello, World!" web API:
B4X:
Sub Process_Globals
    'Declare global variables here.
    Dim srvr As Server
End Sub

Sub AppStart (Args() As String)
    'Start the server and define the API endpoints.
    srvr.Initialize("")
    srvr.Port = 8080
    srvr.AddHandler("/hello", "GET", False, AddressOf Hello)
    srvr.Start
End Sub

Sub Hello(req As HttpRequest, resp As HttpResponse)
    'Handle requests to the /hello endpoint.
    resp.ContentType = "text/plain"
    resp.Write("Hello, World!")
End Sub

AE: the second argument should be a handler class name in string ...
CG: <BS again>
B4X:
srvr.AddHandler("/hello", "GET", False, AddressOf Hello)

AE: no, the second argument is to specify the name of the Server Handler class instead of the HTTP method like "GET"
CG: <continue BS and same wrong code>

AE: no, you are wrong. you don't need to specify the "GET" method in `AddHandler` method. You can access the HTTP method using Request.Method
CG: You are correct that the HTTP method of a request can be accessed using the Method property of the HttpRequest object in B4X. This property returns a string value that specifies the HTTP method of the request, such as "GET", "POST", "PUT", "DELETE", etc.

Therefore, you do not need to specify the HTTP method as the second argument to the AddHandler method of the Server class. Instead, you can use the Method property of the HttpRequest object to determine the HTTP method of the request in your handler subroutine or function.

For example, here is how you could modify the Hello subroutine to handle different HTTP methods using the Method property of the HttpRequest object:
B4X:
Sub Hello(req As HttpRequest, resp As HttpResponse)
    'Handle requests to the /hello endpoint.
    resp.ContentType = "text/plain"
    Select req.Method
        Case "GET"
            resp.Write("Hello, World! (GET method)")
        Case "POST"
            resp.Write("Hello, World! (POST method)")
        Case "PUT"
            resp.Write("Hello, World! (PUT method)")
        Case "DELETE"
            resp.Write("Hello, World! (DELETE method)")
        Case Else
            resp.Write("Hello, World! (Unknown method)")
    End Select
End Sub

AE: yes, now you get it!
CG: I'm glad that I was able to provide a correct and helpful answer to your question. If you have any other questions, please don't hesitate to ask. I will do my best to help.

AE: so you should write the following correct code at AppStart sub:
Server.AddHandler(ROOT_PATH & "hello/*", "HelloHandler", False)

CG: <continue BS and repeat wrong code>
B4X:
Sub AppStart (Args() As String)
    'Start the server and define the API endpoints.
    srvr.Initialize("")
    srvr.Port = 8080
    srvr.AddHandler(ROOT_PATH & "hello/*", "GET", False, AddressOf HelloHandler)
    srvr.Start
End Sub

Sub HelloHandler(req As HttpRequest, resp As HttpResponse)
    'Handle requests to the /hello/* endpoint.
    resp.ContentType = "text/plain"
    resp.Write("Hello, World!")
End Sub

At Last...

AE: NO, you are still not correct. Server.AddHandler accepts three arguments.

The correct code is:
Server.AddHandler("hello/*", "HelloHandler", False)

The first argument accepts the Path As String. The path can consist of wildcard with asterisk "*"
The second argument accepts the Class As String which is the Server Handler Class. We can add the Server Handler Class from the menu in B4J IDE. Click menu Project, Add New Module, Class Module, Server Handler. Enter the module name and click Ok. The Handler Class look like the following:
B4X:
'Handler class
Sub Class_Globals
    
End Sub

Public Sub Initialize
    
End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)
    
End Sub

The third argument in AddHandler is a Boolean variable name SingleThreadHandler. Usually we just need to use False.


CG:
1671102561292.png

1671102732478.png

1671102768749.png
 

AnandGupta

Expert
Licensed User
Longtime User
@aeric I am pretty sure if you ask the same... you will get wrong answer again ! :)
If the AI is learning from mistake, like a child, then it should save the answer of Aeric as marked YES by user and show the same to next user who ask for it.
I hope.
 

Magma

Expert
Licensed User
Longtime User
@Serge Bertet ..Let me see if I understand because i am not using any "AI" machine... (i am talking only for my brain)

you are giving an equation... U=I.R.5... that you wanted to give to it... ...R*5... right ?

...and at first.... gives wrong result ?
- you already know the right-result... and you are teaching the AI that is making "wrong" and wait for the right result..

Hmmm.. interesting but... from a Computer you are always wait the right result :)

In this point why do you think made it took the wrong decision ? Do you believe it is an OCR-problem or just logic ?

ps: sorry i can't see the magic here... yes it has a big database - as it seems... but..
 

Serge Bertet

Active Member
Licensed User
I asked this question cause I'm lazy (and I was not sure if I had to remove 0.2 at the begining).
But when I found 10 - 0.2 = 1.8 in the answer I saw the error ... the following is just for fun as I was able to correct it myself.
Yes '.' (dots) stands for '*' but I think that do not make any difference in the result in this case.
What looks magic (of funny) to me in the fact that A.I. apologize for error even if it's a big database.
 

Magma

Expert
Licensed User
Longtime User
Top