FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour new Class TDeepSeek in next FWH 24.12
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
new Class TDeepSeek in next FWH 24.12
Posted: Sun Jan 12, 2025 06:28 AM
Next FWH 24.12 includes Class TDeepSeek

DeepSeek is much cheaper than OpenAI and it offers the same AI quality.
You have to register in DeepSeek site and get your API key. Then from a cmd window do:
set DEEPSEEK_API_KEY=sk-...

sample of use:
#include "FiveWin.ch"

function Main()

   local oChat := TDeepSeek():New()
   
   oChat:Send( "Using MySQL how to list all tables ? write just the simplest SQL sentence, no explanations" )

   ? oChat:GetValue()

   oChat:End()

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Sun Jan 12, 2025 07:55 PM
// Based on https://api-docs.deepseek.com
// Remember to register in https://deepseek.com/ and get your API key

#include "FiveWin.ch"
#include "c:\harbour\contrib\hbcurl\hbcurl.ch"

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

CLASS TDeepSeek
    
    DATA   cKey   INIT ""
    DATA   cModel INIT "deepseek-chat"
    DATA   cResponse
    DATA   cUrl
    DATA   hCurl
    DATA   nError INIT 0
    DATA   nHttpCode INIT 0

    METHOD New( cKey, cModel )
    METHOD Send( cPrompt )    
    METHOD End()    
    METHOD GetValue( cHKey )    

ENDCLASS        

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

METHOD New( cKey, cModel ) CLASS TDeepSeek

    if Empty( cKey )
       ::cKey = GetEnv( "DEEPSEEK_API_KEY" )
    else
       ::cKey = cKey   
    endif

    if ! Empty( cModel )
       ::cModel = cModel
    endif
    
    ::cUrl = "https://api.deepseek.com/chat/completions"
    ::hCurl = curl_easy_init()
    
return Self    

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

METHOD End() CLASS TDeepSeek

    curl_easy_cleanup( ::hCurl )
    ::hCurl = nil

return nil    

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

METHOD GetValue( cHKey ) CLASS TDeepSeek

    local aKeys := hb_AParams(), cKey
    local uValue := hb_jsonDecode( ::cResponse )

    hb_default( @cHKey, "content" )

    if cHKey == "content"
       TRY 
          uValue = uValue[ "choices" ][ 1 ][ "message" ][ "content" ]
       CATCH
          uValue = uValue[ "error" ][ "message" ]
       END   
    endif

    TRY
       for each cKey in aKeys
          if ValType( uValue[ cKey ] ) == "A"
             uValue = uValue[ cKey ][ 1 ][ "choices" ][ 1 ][ "message" ][ "content" ]
          else
             uValue = uValue[ cKey ]
          endif
       next
    CATCH
       XBrowser( uValue )
    END

return uValue

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

METHOD Send( cPrompt ) CLASS TDeepSeek 

   local aHeaders, cJson, hRequest := { => }, hMessage1 := { => }, hMessage2 := { => }

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

   aHeaders := { "Content-Type: application/json", ;
                 "Authorization: Bearer " + ::cKey }

   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
   hMessage1[ "role" ] = "system"
   hMessage1[ "content" ] = "You are a helpfull assistant."
   hMessage2[ "role" ] = "user"
   hMessage2[ "content" ] = cPrompt
   hRequest[ "messages" ] = { hMessage1, hMessage2 }
   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

//----------------------------------------------------------------------------//
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 253
Joined: Fri Feb 03, 2006 04:21 PM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Thu Jan 16, 2025 05:16 PM
Antonio,

Gracias por compartir TDeepSeek.

Me gustar铆a obtener una Light para comunicarme con la API REST con certificado y CURL. seg煤n el c贸digo a continuaci贸n. 驴Tienes alguna experiencia sobre c贸mo hacerlo?
#include "fivewin.ch"
#include "hbcurl.ch"

* ========================================================================
Function Teste()
* ========================================================================
  local cURL := "https://cfqasvir.it-cpi019-rt.cfapps.us10-002.hana.ondemand.com/http/PurchaseOrder/v1?CodeERP=4510160192"
  local cCurl
  local nError
  local cResponse

  cCurl := curl_easy_init()
  curl_easy_setopt( cCurl, HB_CURLOPT_PROTOCOLS, HB_CURLPROTO_HTTPS)
  curl_easy_setopt( cCurl, HB_CURLOPT_URL                   , cURL       )
  curl_easy_setopt( cCurl, HB_CURLOPT_DL_BUFF_SETUP                )  
  curl_easy_setopt( cCurl, HB_CURLOPT_HTTPHEADER      , {"Content-Type: application/json"})                                                         
  curl_easy_setopt( cCurl, HB_CURLOPT_CUSTOMREQUEST   ,'GET'       )
  curl_easy_setopt( cCurl, HB_CURLOPT_SSLCERTPASSWD   , "Key_fornec_Int_69133353"                    )
  curl_easy_setopt( cCurl, HB_CURLOPT_SSLCERT         , "C:\sis\fsql901\Key_fornec_Int_69133353.pem" )
  curl_easy_setopt( cCurl, HB_CURLOPT_SSLKEY          , "C:\sis\fsql901\Key_fornec_Int_69133353.key" )
   
  nError := curl_easy_perform( cCurl )
    
  if nError == HB_CURLE_OK
     cResponse := curl_easy_dl_buff_get( cCurl )
  else
     cResponse := "Error code: " + curl_easy_strerror(nError)
  endif
    
  Msg( cResponse )
  
  curl_easy_cleanup(cCurl)

return nil

resposta : Status 401 n茫o autorized
Thanks,
Ari

FWH 2501 - Harbour 3.2.0 - Embarcadero 7.43 - MySQL
S茫o Paulo - SP - Brasil
www.sisrev.com.br
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Thu Jan 16, 2025 06:13 PM

Has probado a preguntarle a chatgpt ?

En estos casos preguntar a varias IAs: chatgpt, claude, copilot, deepseek, es la mejor opci贸n

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 253
Joined: Fri Feb 03, 2006 04:21 PM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Thu Jan 16, 2025 06:39 PM

Agradecido,

驴Preguntar茅?

Thanks,
Ari

FWH 2501 - Harbour 3.2.0 - Embarcadero 7.43 - MySQL
S茫o Paulo - SP - Brasil
www.sisrev.com.br
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Tue Jan 21, 2025 08:19 PM
Yesterday 2025-01-20 DeekSeek published a new model much more powerfull: DeepSeek R1

To use it from FWH Class TDeepSeek we have to specify model="deepseek-reasoner"

By default we are using

DATA cModel INIT "deepseek-chat"

so in order to use it we have to change this:

DATA cModel INIT "deepseek-reasoner"

Prices: (the cheapest of all and the best AI)
💰 $0.14 / million input tokens (cache hit)
💰 $0.55 / million input tokens (cache miss)
💰 $2.19 / million output tokens
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Wed Jan 22, 2025 05:40 PM
https://platform.deepseek.com/ to pay five USD using PayPal
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Mon Jan 27, 2025 01:22 PM
hi,
Antonio Linares wrote: https://platform.deepseek.com/ to pay five USD using PayPal
NOT FOUND 404
use this instead
https://www.deepseek.com/
greeting,

Jimmy
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Mon Jan 27, 2025 03:35 PM

The URL I provided works fine here

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Mon Jan 27, 2025 10:11 PM
hi,
Antonio Linares wrote: The URL I provided works fine here
i have read that DeepSeek Website was hacked so that might be the Reason why i can麓t connect to the Website.
greeting,

Jimmy
Posts: 9
Joined: Tue Nov 12, 2024 01:30 PM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Tue Jan 28, 2025 03:04 AM
I just tested DeepSeek's operations, and it is currently functioning normally.
Additionally, I asked it about the cause of this incident (after enabling web search), and here is the response it provided:

-----------------
Yes, according to reports from multiple media outlets, DeepSeek has recently suffered a large-scale cyber attack. Below is a summary of the relevant information:

1.Overview of the Attack
DeepSeek announced on its official service status page that its online services were subjected to a massive malicious attack, which temporarily restricted registration functionality. However, registered users can still log in normally. To mitigate the attack, DeepSeek has temporarily restricted registration methods for non-Chinese mainland phone numbers (+86).

2.Background of the Attack
The attack occurred after DeepSeek released its new AI models, Janus-Pro and JanusFlow, which demonstrated exceptional performance in multimodal understanding and generation tasks, even surpassing OpenAI's DALL-E 3 and Stable Diffusion in certain benchmark tests. The low cost and high performance of DeepSeek's models have caused significant turbulence in global tech stocks, particularly leading to a sharp decline in the stock prices of U.S. tech giants. This may be one of the motivations behind the attack.

3.Impact of the Attack
The attack caused anomalies in DeepSeek's website and API, with some users reporting issues with logging in or registering. Despite this, DeepSeek stated that it has taken measures to ensure normal usage for existing users and expressed gratitude for their understanding and support.

4.History of Security Vulnerabilities
It is worth noting that DeepSeek has previously been found to have security vulnerabilities. For example, in December 2024, researchers discovered a prompt injection vulnerability in DeepSeek's chatbot, which could potentially lead to user account takeovers. However, this vulnerability has since been patched.

In summary, DeepSeek has indeed been targeted by a large-scale cyber attack recently, but the company has taken steps to address the issue and ensure the normal operation of core services. The attack may be related to DeepSeek's rapid rise in the AI field and its impact on the global tech market.


-----------------



I also found out that DeepSeek released "Janus Pro" the day before yesterday. https://huggingface.co/deepseek-ai
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Tue Jan 28, 2025 06:57 AM
We are going to enhance FWH Class TDeepSeek to be able to use "Janus Pro" :)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Tue Jan 28, 2025 04:39 PM

Dear friends,

The whole world is in great excitement. Some stocks lose 18% of their value overnight. But our forum remains calm.

AI news cannot shake us.

Best regards,

Otto

Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Tue Jan 28, 2025 11:54 PM

Otto,

We remain calm because we use tools, and the stock market will not be of concern to us. The company can continue to function well even if investors are afraid they will not get their payouts. We care about the developers not the guys sitting on computers all day playing games with stocks.

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 1276
Joined: Tue Dec 28, 2010 01:29 PM
Re: new Class TDeepSeek in next FWH 24.12
Posted: Wed Jan 29, 2025 04:18 PM
Antonio Linares wrote: We are going to enhance FWH Class TDeepSeek to be able to use "Janus Pro" :)
Hello Master,

What is "Janus Pro" ?

FWH 25.12

Harbour/Hbmk2

Microsoft Visual C++

MySql 8.0

Antigravity