TDeepSeek

Fuente: source/classes/tdeepseek.prg

TDeepSeek is FiveWin's client for the DeepSeek API. DeepSeek is known for its strong coding and reasoning capabilities, making it an excellent choice for code generation, analysis, and logic tasks. The class provides a simple chat completion interface using Harbour's hb_curl library. It supports the deepseek-chat and deepseek-reasoner models.

Architecture

flowchart LR subgraph "FiveWin Application" A[TDeepSeek] end subgraph "libcurl" B[hb_curl
HTTPS] end subgraph "DeepSeek API" C["api.deepseek.com/chat/completions"] end A --> B B --> C

Key DATA Members

DATATypeDefaultDescription
cKeyCharacter""DeepSeek API key. Reads DEEPSEEK_API_KEY env var if empty.
cModelCharacter"deepseek-chat"Model: "deepseek-chat" or "deepseek-reasoner"
cResponseCharacterRaw JSON response from the API
cUrlCharacterAPI endpoint URL (auto-set to DeepSeek endpoint)
hCurlHandlelibcurl easy handle
nErrorNumeric0curl error code (HB_CURLE_OK = 0 = success)
nHttpCodeNumeric0HTTP response status code

Methods

MethodDescription
New( cKey, cModel )Create a TDeepSeek instance. If cKey is empty, reads DEEPSEEK_API_KEY from the environment. Sets the API endpoint and initializes a libcurl handle.
Send( cPrompt )Send a text prompt to the DeepSeek API. Stores the raw JSON response in cResponse.
GetValue()Extract the text response from the JSON in cResponse. Navigates choices[1].message.content on success, or returns the error message on failure.
End()Clean up the libcurl handle.

Example: Chat Completions

#include "FiveWin.ch"

function Main()

   local oAI := TDeepSeek():New( "sk-deepseek-key" )
   local cAnswer

   // Send a prompt
   oAI:Send( "Write a Harbour function to calculate the Fibonacci sequence" )

   if oAI:nError == 0 .and. oAI:nHttpCode == 200
      cAnswer := oAI:GetValue()
      MsgInfo( cAnswer )
   else
      MsgStop( "Error: " + oAI:cResponse )
   endif

   oAI:End()

return nil

Example: Using the Reasoner Model

#include "FiveWin.ch"

function Main()

   local oAI := TDeepSeek():New( "sk-deepseek-key", "deepseek-reasoner" )

   oAI:Send( "Solve this logic puzzle: A man pushes his car to a hotel " + ;
             "and tells the owner he is bankrupt. What happened?" )

   if oAI:nError == 0
      MsgInfo( oAI:GetValue() )
   endif

   oAI:End()

return nil

Notes

Ver También