Communicate with AI via tsNetGetSync (Solved)

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Communicate with AI via tsNetGetSync (Solved)

Post by mrcoollion » Mon Mar 18, 2024 4:53 pm

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
Last edited by mrcoollion on Mon Mar 25, 2024 9:23 am, edited 1 time in total.

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Communicate with AI via tsNetGetSync

Post by mrcoollion » Wed Mar 20, 2024 2:41 pm

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":""}}

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Communicate with AI via tsNetGetSync

Post by mrcoollion » Mon Mar 25, 2024 9:21 am

Took me almost 3 days to figure it out but I got it working.

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Communicate with AI via tsNetGetSync (Solved)

Post by mrcoollion » 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.

Let me know?!

Regards,

MrCoolLIon
(Paul)

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Communicate with AI via tsNetGetSync (Solved)

Post by bn » Mon Mar 25, 2024 9:34 am

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

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 261
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Communicate with AI via tsNetGetSync (Solved)

Post by SWEdeAndy » Mon Mar 25, 2024 9:37 am

Definitely very interesting! Please do! :)
Andreas Bergendal
Independent app and system developer
WhenInSpace: https://wheninspace.se

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Communicate with AI via tsNetGetSync (Solved)

Post by mrcoollion » Mon Mar 25, 2024 10:27 am

Pfff.
How can i attach a livecode script in this forum?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Communicate with AI via tsNetGetSync (Solved)

Post by bn » Mon Mar 25, 2024 10:31 am

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

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Communicate with AI via tsNetGetSync (Solved)

Post by mrcoollion » Mon Mar 25, 2024 10:33 am

Thanks.. I will zipp it.

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Communicate with AI via tsNetGetSync (Solved)

Post by mrcoollion » Mon Mar 25, 2024 10:43 am

*&^%@$@@ 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.
Last edited by mrcoollion on Mon Mar 25, 2024 10:47 am, edited 1 time in total.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Communicate with AI via tsNetGetSync (Solved)

Post by bn » Mon Mar 25, 2024 10:46 am

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

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Communicate with AI via tsNetGetSync (Solved)

Post by mrcoollion » Mon Mar 25, 2024 10:52 am

Can you test it for me Bernd.
Just made a new topic for it (Learn AI and Contribute Topic).

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Communicate with AI via tsNetGetSync (Solved)

Post by bn » Mon Mar 25, 2024 11:29 am

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

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Communicate with AI via tsNetGetSync (Solved)

Post by mrcoollion » Mon Mar 25, 2024 12:08 pm

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.

Post Reply

Return to “Talking LiveCode”