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
HTTPS] end subgraph "DeepSeek API" C["api.deepseek.com/chat/completions"] end A --> B B --> C
Key DATA Members
| DATA | Type | Default | Description |
|---|---|---|---|
cKey | Character | "" | DeepSeek API key. Reads DEEPSEEK_API_KEY env var if empty. |
cModel | Character | "deepseek-chat" | Model: "deepseek-chat" or "deepseek-reasoner" |
cResponse | Character | Raw JSON response from the API | |
cUrl | Character | API endpoint URL (auto-set to DeepSeek endpoint) | |
hCurl | Handle | libcurl easy handle | |
nError | Numeric | 0 | curl error code (HB_CURLE_OK = 0 = success) |
nHttpCode | Numeric | 0 | HTTP response status code |
Methods
| Method | Description |
|---|---|
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
- TDeepSeek requires the
hb_curllibrary. Include#include "hbcurl.ch"for curl constants. - The API key can be read from the
DEEPSEEK_API_KEYenvironment variable by passing an empty key toNew(). - SSL verification is disabled by default (
HB_CURLOPT_SSL_VERIFYPEER = .F.) for broad compatibility. - The
deepseek-reasonermodel provides chain-of-thought reasoning before answering, making it suitable for complex logic and analysis tasks. GetValue()navigates the JSON pathchoices[1].message.contentand returns the text. If the API returns an error, it navigateserror.messageinstead.- The class is stateless for prompts — each
Send()call is independent. For multi-turn conversations, maintain your own message history and send the full context.