AI Classes
Sources: source/classes/topenai.prg, source/classes/tdeepseek.prg, source/classes/tgemini.prg, source/classes/tollama.prg
FiveWin provides a unified set of AI/LLM classes that integrate with popular cloud AI
providers and local models. All classes follow the same basic pattern: instantiate with
an API key (or model name for local), send a prompt, and extract the response. They use
Harbour's hb_curl library for HTTPS communication with the respective API endpoints.
For the complete AI documentation including all class members and extended examples, see TOpenAI / TChatGPT — that page documents every AI class with full reference tables, code samples, and a comparison guide.
Common Pattern
All AI classes share this basic workflow:
// 1. Create instance with API key (or model name for local)
oAI := TSomeAI():New( cApiKey )
// 2. Send a prompt
oAI:Send( "Your question here" )
// 3. Extract the response text
cAnswer := oAI:GetValue()
// 4. Clean up
oAI:End()
Class Reference
TOpenAI
Fuente: source/classes/topenai.prg
OpenAI ChatGPT integration. Supports text, vision (image analysis), and streaming responses.
| DATA | Default | Description |
|---|---|---|
cKey | OPENAI_API_KEY env | OpenAI API key |
cModel | gpt-4o-mini | Model name (e.g. gpt-4o, gpt-4o-mini) |
nTemperature | 0.5 | Sampling temperature (0.0 to 2.0) |
cResponse | Raw JSON response from API |
| Method | Parameters | Description |
|---|---|---|
New() | cKey, cModel | Constructor. Reads env var if cKey empty. |
Send() | cPrompt | Send text prompt, return raw JSON |
SendStream() | cPrompt, bCallback | Streaming response via callback |
SendImage() | cImageFile, cPrompt | Vision: analyze a local image |
SendImageURL() | cImageUrl, cPrompt | Vision: analyze image from URL |
GetValue() | Extract text from JSON response |
TDeepSeek
Fuente: source/classes/tdeepseek.prg
DeepSeek AI integration. Known for strong coding and reasoning capabilities.
| DATA | Default | Description |
|---|---|---|
cKey | DEEPSEEK_API_KEY env | DeepSeek API key |
cModel | deepseek-chat | Model: deepseek-chat or deepseek-reasoner |
| Method | Parameters | Description |
|---|---|---|
New() | cKey, cModel | Constructor |
Send() | cPrompt | Send prompt, return raw JSON |
GetValue() | Extract text from JSON response |
local oAI := TDeepSeek():New( "sk-deepseek-key" )
oAI:Send( "Write a Harbour function for binary search" )
MsgInfo( oAI:GetValue() )
oAI:End()
TGemini
Fuente: source/classes/tgemini.prg
Google Gemini integration. Supports text, images, file uploads, and streaming.
| DATA | Default | Description |
|---|---|---|
cKey | GEMINI_API_KEY env | Google API key |
cModel | gemini-2.0-flash | Model name |
nTemperature | 0 | Response creativity (0-2) |
| Method | Parameters | Description |
|---|---|---|
New() | cKey, cModel | Constructor |
Send() | uContent, cPrompt, bCallback | Send text, image file, or array of files with prompt |
UploadFile() | cFileName, lDeleteAfter | Upload file to Gemini for analysis |
GetValue() | Extract text from JSON response |
local oAI := TGemini():New( "google-api-key" )
// Text prompt
oAI:Send( "Explain quantum computing in simple terms" )
MsgInfo( oAI:GetValue() )
// Image analysis
oAI:Send( "C:\photos\chart.png", "Describe this chart" )
MsgInfo( oAI:GetValue() )
oAI:End()
TOLlama (Local AI)
Fuente: source/classes/tollama.prg
Local LLM integration via Ollama. No API key needed — runs models on your own machine. Default model: deepseek-r1:14b.
| DATA | Default | Description |
|---|---|---|
cModel | deepseek-r1:14b | Ollama model name |
cUrl | http://localhost:11434/api/chat | Ollama server endpoint |
| Method | Parameters | Description |
|---|---|---|
New() | cModel | Constructor. Default model: deepseek-r1:14b. |
Send() | cPrompt | Send prompt, return raw JSON |
SendStream() | cPrompt, bCallback | Streaming response via callback |
SendImage() | cImageFile, cPrompt | Vision for multimodal models (e.g. llava) |
GetValue() | Extract message content from JSON |
// Local AI - no API key needed
local oAI := TOLlama():New( "llama3" )
oAI:Send( "What is FiveWin?" )
MsgInfo( oAI:GetValue() )
// Streaming response
oAI:SendStream( "Write a poem", {|c| QOut(c)} )
// Image analysis (vision model)
oAI:SendImage( "photo.jpg", "What do you see?" )
oAI:End()
API Key Configuration
Each cloud AI class reads its API key from a specific environment variable when no key is passed to New():
| Class | Environment Variable | Base URL |
|---|---|---|
| TOpenAI | OPENAI_API_KEY | https://api.openai.com/v1 |
| TDeepSeek | DEEPSEEK_API_KEY | https://api.deepseek.com |
| TGemini | GEMINI_API_KEY | https://generativelanguage.googleapis.com |
| TOLlama | Not needed (local) | http://localhost:11434 |
Tips
- All AI classes require the
hb_curllibrary. Link with#include "hbcurl.ch"for curl constants. - SSL verification is disabled by default (
HB_CURLOPT_SSL_VERIFYPEER = .F.) for broad compatibility. - Use
GetValue()to extract the text response from the raw JSON stored incResponse. - The
cResponseDATA member always contains the raw JSON. Access it directly for debugging or custom parsing. - For complete documentation including all methods, callback codeblocks, and advanced usage, see the TOpenAI / TChatGPT page.