You can also use a function and use the “post to url function”, built-in in LiveCode, like this without any need for curl:
function ProcessOllamaText pText put pText into tArr["prompt"] put “You are a grumpy wizard, that doesn’t want to be disturbed as you rather want to create new spells" into tArr["system"] put "gemma2:27b" into tArr["model"] put false into tArr["stream"] put arrayToJSON(tArr) into tJSON post tJSON to "http://localhost:11434/api/generate" put it into tJSON put jsonToArray(tJSON) into tRespArr put tRespArr["response"] into tResult replace "\n" with return in tResult return tResult end ProcessOllamaText The tArr[“system”] is the system prompt and tArr[“model”] is the model you run. The system prompt is not needed, but are fun to tweak and test with. If you don’t set stream to false you will get a lot of responses back (usually one response / word). They start to arrive a lot quicker but then you need to handle that in another way, and would also need an asynchronous way of reading the data. You need to have Ollama running as of steps 1-3 in jbv’s description (and of course if you run Ollama run llama3:2:1b then that should be your “model” above. But then you can call it like this put ProcessOllamaText( “Is there a way to create a spell that transforms people into frogs?”) :-Håkan > On 3 Feb 2025, at 10:11, jbv via use-livecode <use-livecode@lists.runrev.com> > wrote: > > Hi list, > > Someone asked me privately, so I thought that maybe others > would be interested in a simple way to interact between LC > and AI models locally on their machine. > > The method uses Ollama, which is available for Mac, Win and > Linux : https://ollama.com > > 1- Download and install Ollama (plenty of tutorials on youtube) > > 2- run Ollama via Terminal (on Mac) : > ollama serve > > 3- load a model via Terminal (from HuggingFace for instance) : > ollama run llama3.2:1b > > 4- in a livecode stack, create a field with the following content : > curl -X POST http://localhost:11434/api/generate \ > -H "Content-Type: application/json" \ > -d '{ > "model": "llama3.2:1b", > "prompt": "What is the capital of France ?", > "stream": false > }' > > 5- create a button with the following script : > on mouseup > put field 1 into tcurl > put shell(tcurl) > end mouseup > > 6- the answer from the model displays in the message box in json format. > > This works great on machines with a GPU and at least 16 Gb of RAM. > The more RAM, the bigger the models that can be used. > > Enjoy, > jbv > > _______________________________________________ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode