Page 1 of 1

Communicate with AI via tsNetGetSync (Solved)

Posted: Mon Mar 18, 2024 4:53 pm
by mrcoollion
Hello LC specialists :-),

It has been a while for me to post a question but here is my latest headscratcher when using tsNetGetSync.
I hope that someone has an answer for me .

I have locally set up an opensource AI named LocalAI in Docker which works.
I now try to cummunicate with it using tsNetGetSync.
For getting the installed models according to LocalAI documentation i need to use the following curl command.

Code: Select all

curl http://localhost:8080/v1/models
I translated this to the following tsNetGetSync setup for getting the installed AI models and it works fine

Code: Select all

   put "" into tHeaders
   put "http://localhost:8080/v1/models" into tBaseURL
   put tsNetGetSync(tBaseURL, tHeaders, tRecvHeaders, tResult, tBytes) into tData
  
It gives me the requested information in tData which i reformatted to readable text with 'put JSONtoArray(tData) into tArray'.
However the next step where I ask the AI 'How are you?' i cannot get to work.
Below is the original curl request example from the site .

Code: Select all

curl http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
     "model": "luna-ai-llama2",
     "messages": [{"role": "user", "content": "How are you?"}],
     "temperature": 0.9
   }'
Here is the Site URL with the information: https://localai.io/docs/getting-started/manual/
------.
I do know that putting the header variable in alphabetical order is important for tsNetGetSync.
I tried multiple setups for the tRequest string but no luck. (Keep getting error 404).

Regards,

MrCoolLion (Paul)

Code: Select all

   put "http://localhost:8080" into tBaseURL
   put "" into tHeaders
   //put "/v1/chat/completions&Content-Type: application/json & model: ggml-gpt4all-j & messages: [&role: user&content: How are you?&] & temperature: 0.9" into tHeaders
   //put "/v1/chat/completions&content:How are you?&Content-Type:application/json&model:ggml-gpt4all-j&role:user&temperature:0.9" into tHeaders
   put "/v1/chat/completions&Content-Type: application/json & model: ggml-gpt4all-j & messages: [&role: user&content: How are you?&] & temperature: 0.9" into tHeaders
   put tBaseURL&tHeaders into tRequestString
   put "" into tHeaders
   put tsNetGetSync(tRequestString, tHeaders, tRecvHeaders, tResult, tBytes) into tData

Re: Communicate with AI via tsNetGetSync

Posted: Wed Mar 20, 2024 2:41 pm
by mrcoollion
Some Additional information.
Ik am now using tsNetPostSync which I should have used from the beginning for this type of request (chat).

Code: Select all

  put tsNetPostSync(tRequestString, tHeaders, tPostData, tRecvHeaders, tResult, tBytes) into tData
Here is the information i have send and the reply i get from the server.

Code: Select all

RequestString: http://localhost:8080/v1/chat/completions
Headers: "Content-Type: application/json"
PostData: '{"model": "ggml-gpt4all-j","messages": [{"role": "user","content": "How are you?"}],"temperature": 0.9}'
reply from the server is:

Code: Select all

Could not retrieve data. Error code : 500
RecvHeaders: HTTP/1.1 500 Internal Server Error
Date: Wed, 20 Mar 2024 13:33:58 GMT
Content-Type: application/json
Content-Length: 109
Data: {"error":{"code":500,"message":"runtime error: invalid memory address or nil pointer dereference","type":""}}

Re: Communicate with AI via tsNetGetSync

Posted: Mon Mar 25, 2024 9:21 am
by mrcoollion
Took me almost 3 days to figure it out but I got it working.

Re: Communicate with AI via tsNetGetSync (Solved)

Posted: Mon Mar 25, 2024 9:27 am
by mrcoollion
If Anyone is interested having a AI running local on your Laptop/PC for learning and testing purposes but also for actual reallife goals, then I will make a different topic of it and to support the community I will post my LiveCode Application and a short instruction on how to get things running.

Let me know?!

Regards,

MrCoolLIon
(Paul)

Re: Communicate with AI via tsNetGetSync (Solved)

Posted: Mon Mar 25, 2024 9:34 am
by bn
mrcoollion wrote:
Mon Mar 25, 2024 9:27 am
If Anyone is interested having a AI running local on your Laptop/PC for learning and testing purposes but also for actual reallife goals, then I will make a different topic of it and to support the community I will post my LiveCode Application and a short instruction on how to get things running.
(Paul)
Hi Paul,

If you could do that you would be a true Cool Lion... :D

Kind regards
Bernd

Re: Communicate with AI via tsNetGetSync (Solved)

Posted: Mon Mar 25, 2024 9:37 am
by SWEdeAndy
Definitely very interesting! Please do! :)

Re: Communicate with AI via tsNetGetSync (Solved)

Posted: Mon Mar 25, 2024 10:27 am
by mrcoollion
Pfff.
How can i attach a livecode script in this forum?

Re: Communicate with AI via tsNetGetSync (Solved)

Posted: Mon Mar 25, 2024 10:31 am
by bn
mrcoollion wrote:
Mon Mar 25, 2024 10:27 am
Pfff.
How can i attach a livecode script in this forum?
Paul,

You could paste a script after first clicking the </> icon.
Or you could probably zip a text file and attach it via "Attachments"

Kind regards
Bernd

Re: Communicate with AI via tsNetGetSync (Solved)

Posted: Mon Mar 25, 2024 10:33 am
by mrcoollion
Thanks.. I will zipp it.

Re: Communicate with AI via tsNetGetSync (Solved)

Posted: Mon Mar 25, 2024 10:43 am
by mrcoollion
*&^%@$@@ file is to big (616 kB).
I could use dropbox. Any better suggestions?
-- Update --
DropBox needs e-mail adresses . Si i think this is no option in this case.

Re: Communicate with AI via tsNetGetSync (Solved)

Posted: Mon Mar 25, 2024 10:46 am
by bn
mrcoollion wrote:
Mon Mar 25, 2024 10:43 am
*&^%@$@@ file is to big (616 kB).
I could use dropbox. Any better suggestions?
Maybe you have a website and offer it for download from there?
Kind regards
Bernd

Re: Communicate with AI via tsNetGetSync (Solved)

Posted: Mon Mar 25, 2024 10:52 am
by mrcoollion
Can you test it for me Bernd.
Just made a new topic for it (Learn AI and Contribute Topic).

Re: Communicate with AI via tsNetGetSync (Solved)

Posted: Mon Mar 25, 2024 11:29 am
by bn
Paul,

I downloaded your stack from dropBox and downloaded the Ollama version for Mac.

Unfortunately I am currently involved in another project and can not test nor adapt your stack for Mac.

I will wait until maybe someone figures it out.

Kind regards
Bernd

Re: Communicate with AI via tsNetGetSync (Solved)

Posted: Mon Mar 25, 2024 12:08 pm
by mrcoollion
That fine Bernd.
I just needed to know if you can download the stack.

Thanks.

FYI: The thing that needs to be changed for other OS's are the shell commands.