FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour What are these .gguf files in the llama classes?
Posts: 103
Joined: Fri Aug 09, 2013 12:43 AM
What are these .gguf files in the llama classes?
Posted: Mon Sep 22, 2025 07:50 PM

Hi,

I don't understand how to use the Llama classes in Harbour.

In this folder,

c:\users\ID.ollama\models\manifests\registry.ollama.ai\library\

, I have

dolphin-llama3

llama3

llama3.1

llama3.2

qwen2.5-coder

, but I don't see how these models relate to the .gguf references in the models.ini sample.

e.g. model1=/mnt/diskd/Arhiv/ai/tinyllama-1.1b-1t-openorca.Q5_K_M.gguf

or

model2=C:\Users\SYSADMIN\jan\models\mistral-ins-7b-q4\mistral-7b-instruct-v0.2.Q4_K_M.gguf

I searched in the ollama models folder, and there aren't any .gguf files there.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: What are these .gguf files in the llama classes?
Posted: Mon Sep 22, 2025 08:44 PM

Use the Class TOllama

This class superseeds any previous llama.cpp implementations

look for samples\ollama...prg

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 103
Joined: Fri Aug 09, 2013 12:43 AM
Re: What are these .gguf files in the llama classes?
Posted: Mon Sep 22, 2025 10:01 PM
Thanks Antonio,

I searched the forum for this class, but couldn't locate it.

I can't find it here, either:

https://github.com/FiveTechSoft/llama/tree/master/source


Antonio Linares wrote: Use the Class TOllama

This class superseeds any previous llama.cpp implementations

look for samples\ollama...prg
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: What are these .gguf files in the llama classes?
Posted: Mon Sep 22, 2025 10:35 PM
Class TOllama
tollama.prg
// Developed by FiveTech Software, using parts by Charles OhChul

#include "FiveWin.ch"
#include "hbcurl.ch"

//----------------------------------------------------------------------------//

CLASS TOLlama
    
   DATA   cModel
   DATA   cPrompt
   DATA   cResponse
   DATA   cUrl
   DATA   hCurl
   DATA   nError INIT 0
   DATA   nHttpCode INIT 0
   DATA   aAgents

   METHOD New( cModel )
   METHOD Send( cPrompt )    
   METHOD SendStream( cPrompt, bWriteFunction )  
   METHOD SendImage( cImageFileName, cPrompt )   
   METHOD End()    
   METHOD GetValue()    

ENDCLASS        

//----------------------------------------------------------------------------//

METHOD New( cModel ) CLASS TOLlama

   DEFAULT cModel := "deepseek-r1:14b"

   ::cModel = cModel
   ::cUrl = "http://localhost:11434/api/chat"
   ::hCurl = curl_easy_init()
    
return Self    

//----------------------------------------------------------------------------//

METHOD End() CLASS TOLlama

    curl_easy_cleanup( ::hCurl )
    ::hCurl = nil

return nil    

//----------------------------------------------------------------------------//

METHOD GetValue() CLASS TOLlama

   local hResponse, uValue  
   
   hb_jsonDecode( ::cResponse, @hResponse )

   TRY 
      uValue = hResponse[ "message" ][ "content" ]
   CATCH
      uValue = hResponse[ "error" ][ "message" ]
   END   

return uValue

//----------------------------------------------------------------------------//

METHOD Send( cPrompt ) CLASS TOLlama 

   local aHeaders, cJson, hRequest := { => }, hMessage := { => }

   if ! Empty( cPrompt )
      ::cPrompt = cPrompt
   endif   

   curl_easy_setopt( ::hCurl, HB_CURLOPT_POST, .T. )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_URL, ::cUrl )

   aHeaders := { "Content-Type: application/json" }

   curl_easy_setopt( ::hCurl, HB_CURLOPT_HTTPHEADER, aHeaders )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_USERNAME, '' )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_DL_BUFF_SETUP )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )

   hRequest[ "model" ]       = ::cModel
   hMessage[ "role" ]        = "user"
   hMessage[ "content" ]     = cPrompt
   hRequest[ "messages" ]    = { hMessage }
   hRequest[ "stream" ]      = .F.
   hRequest[ "temperature" ] = 0.5

   cJson = hb_jsonEncode( hRequest )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_POSTFIELDS, cJson )
   ::nError = curl_easy_perform( ::hCurl )
   curl_easy_getinfo( ::hCurl, HB_CURLINFO_RESPONSE_CODE, @::nHttpCode )

   if ::nError == HB_CURLE_OK
      ::cResponse = curl_easy_dl_buff_get( ::hCurl )
   else
      ::cResponse := "Error code " + Str( ::nError )
   endif
    
return ::cResponse

//----------------------------------------------------------------------------//

METHOD SendStream( cPrompt, bWriteFunction ) CLASS TOLlama 

   local aHeaders, cJson, hRequest := { => }, hMessage := { => }

   curl_easy_setopt( ::hCurl, HB_CURLOPT_POST, .T. )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_URL, ::cUrl )

   aHeaders := { "Content-Type: application/json" }

   curl_easy_setopt( ::hCurl, HB_CURLOPT_HTTPHEADER, aHeaders )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_USERNAME, '' )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )

   // Habilitar modo streaming
   hRequest[ "model" ]       = ::cModel
   hMessage[ "role" ]        = "user"
   hMessage[ "content" ]     = cPrompt
   hRequest[ "messages" ]    = { hMessage }
   hRequest[ "stream" ]      = .T.  // ACTIVAR STREAMING
   hRequest[ "temperature" ] = 0.5

   cJson = hb_jsonEncode( hRequest )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_POSTFIELDS, cJson )

   // Configurar la funci├│n de callback para recibir tokens en tiempo real
   curl_easy_setopt( ::hCurl, HB_CURLOPT_WRITEFUNCTION, bWriteFunction )

   ::nError = curl_easy_perform( ::hCurl )
   curl_easy_getinfo( ::hCurl, HB_CURLINFO_RESPONSE_CODE, @::nHttpCode )

   if ::nError != HB_CURLE_OK
      ::cResponse := "Error code " + Str( ::nError )
   endif
    
return ::cResponse

//----------------------------------------------------------------------------//

METHOD SendImage( cImageFileName, cPrompt ) CLASS TOLlama

   local aHeaders, cJson, cBase64Image, hRequest := {=>}, hMessage := { => }

   if ! File( cImageFileName )
      MsgAlert( "Image " + cImageFileName + " not found" )
      return nil
   endif

   DEFAULT cPrompt := "What is in this image?"

   cBase64Image = hb_base64Encode( memoRead( cImageFileName ) )

   curl_easy_setopt( ::hCurl, HB_CURLOPT_POST, .T. )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_URL, ::cUrl )

   aHeaders := { "Content-Type: application/json" }

   curl_easy_setopt( ::hCurl, HB_CURLOPT_HTTPHEADER, aHeaders )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_USERNAME, "" )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_DL_BUFF_SETUP )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )

   hRequest[ "model" ]    = ::cModel
   hMessage[ "role" ]     = "user"
   hMessage[ "content" ]  = cPrompt
   hMessage[ "images" ]   = { cBase64Image }
   hRequest[ "messages" ] = { hMessage }
   hRequest[ "stream" ]   = .F.   

   cJson := hb_jsonEncode( hRequest )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_POSTFIELDS, cJson )

   ::nError = curl_easy_perform( ::hCurl )
   curl_easy_getinfo( ::hCurl, HB_CURLINFO_RESPONSE_CODE, @::nHttpCode )

   if ::nError == HB_CURLE_OK
      ::cResponse = curl_easy_dl_buff_get( ::hCurl )
   else
      ::cResponse = "Error code " + Str( ::nError )
   endif

return ::cResponse

//----------------------------------------------------------------------------//

CLASS TAgent 

   DATA cCategory
   DATA aTools 

   METHOD New( cCategory, aTools )

ENDCLASS      

//----------------------------------------------------------------------------//
ollama1.prg
#include "FiveWin.ch"

function Main()

    local oChat := TOLlama():New( "llama3.2-vision" ) // deepseek-r1:32b" 

    oChat:Send( "who are you ?" )
    ? oChat:GetValue()

    oChat:End()

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 103
Joined: Fri Aug 09, 2013 12:43 AM
Re: What are these .gguf files in the llama classes?
Posted: Tue Sep 23, 2025 12:30 AM

Perfect, thanks Antonio.

Continue the discussion