FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour nuevos metodos para tollama
Posts: 337
Joined: Fri Oct 07, 2005 02:44 PM
nuevos metodos para tollama
Posted: Fri Oct 17, 2025 09:26 PM
Estimados

Por si alguien esta usando modelos para embedding con ollama, pueden agregar estos metodos a tollama
METHOD SendEmbedding( cPrompt ) CLASS TOLlama

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

  // arma el requerimiento
   hRequest[ "model" ]       = ::cModel
   hRequest["input"] := cPrompt
   cJson = hb_jsonEncode( hRequest )
   
   aHeaders := { "Content-Type: application/json" }

   curl_easy_setopt( ::hCurl, HB_CURLOPT_POST, .T. )
   // setea el endpoint a llamar , ojo es distinto a los otros 
   curl_easy_setopt( ::hCurl, HB_CURLOPT_URL, "http://localhost:11434/api/embed" )

   curl_easy_setopt( ::hCurl, HB_CURLOPT_HTTPHEADER, aHeaders )
   curl_easy_setopt( ::hCurl, HB_CURLOPT_DL_BUFF_SETUP )
 
   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 GetValueEmbedding() CLASS TOLlama

   local hResponse, uValue

   hb_jsonDecode( ::cResponse, @hResponse )

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

return uValue
Saludos
Lautaro
Hola,

Soy un Contador que por necesidad aprendio a programar y se quedo programando.

Continue the discussion