new Class TDeepSeek in next FWH 24.12

Post Reply
User avatar
Antonio Linares
Site Admin
Posts: 42395
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 10 times
Been thanked: 41 times
Contact:

new Class TDeepSeek in next FWH 24.12

Post by Antonio Linares »

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:

Code: Select all | Expand

#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
User avatar
Antonio Linares
Site Admin
Posts: 42395
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 10 times
Been thanked: 41 times
Contact:

Re: new Class TDeepSeek in next FWH 24.12

Post by Antonio Linares »

Code: Select all | Expand

// 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
User avatar
Ari
Posts: 239
Joined: Fri Feb 03, 2006 4:21 pm
Location: São Paulo, SP - Brazil
Contact:

Re: new Class TDeepSeek in next FWH 24.12

Post by Ari »

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?

Code: Select all | Expand

#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 2212 - Harbour 3.2.0 - Embarcadero 7.43 - MySQL
São Paulo - SP - Brasil
www.sisrev.com.br
User avatar
Antonio Linares
Site Admin
Posts: 42395
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 10 times
Been thanked: 41 times
Contact:

Re: new Class TDeepSeek in next FWH 24.12

Post by Antonio Linares »

Has probado a preguntarle a chatgpt ?

En _ preguntar a varias IAs: chatgpt, claude, copilot, deepseek, es la mejor opción
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Ari
Posts: 239
Joined: Fri Feb 03, 2006 4:21 pm
Location: São Paulo, SP - Brazil
Contact:

Re: new Class TDeepSeek in next FWH 24.12

Post by Ari »

Agradecido,

¿Preguntaré?
Thanks,
Ari

FWH 2212 - Harbour 3.2.0 - Embarcadero 7.43 - MySQL
São Paulo - SP - Brasil
www.sisrev.com.br
User avatar
Antonio Linares
Site Admin
Posts: 42395
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 10 times
Been thanked: 41 times
Contact:

Re: new Class TDeepSeek in next FWH 24.12

Post by Antonio Linares »

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
User avatar
Antonio Linares
Site Admin
Posts: 42395
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 10 times
Been thanked: 41 times
Contact:

Re: new Class TDeepSeek in next FWH 24.12

Post by Antonio Linares »

https://platform.deepseek.com/ to pay five USD using PayPal
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Jimmy
Posts: 1737
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: new Class TDeepSeek in next FWH 24.12

Post by Jimmy »

hi,
Antonio Linares wrote: Wed Jan 22, 2025 5:40 pm https://platform.deepseek.com/ to pay five USD using PayPal
NOT FOUND 404
use this instead
https://www.deepseek.com/
greeting,
Jimmy
User avatar
Antonio Linares
Site Admin
Posts: 42395
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 10 times
Been thanked: 41 times
Contact:

Re: new Class TDeepSeek in next FWH 24.12

Post by Antonio Linares »

The URL I provided works fine here
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Jimmy
Posts: 1737
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: new Class TDeepSeek in next FWH 24.12

Post by Jimmy »

hi,
Antonio Linares wrote: Mon Jan 27, 2025 3:35 pm 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
TomH
Posts: 3
Joined: Tue Nov 12, 2024 1:30 pm

Re: new Class TDeepSeek in next FWH 24.12

Post by TomH »

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.


-----------------
Post Reply